写程序,做产品,过日子

成功其实很简单,就是强迫自己坚持下去

BlogJava 首页 新随笔 联系 聚合 管理
  69 Posts :: 1 Stories :: 92 Comments :: 0 Trackbacks

 

ejb-jar.xml in ejb/META-INF

 

<session >
... ...

<resource-ref>
<res-ref-name>XPCDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

</session>

 

jboss.xml in ejb/META-INF

 

<?xml version="1.0"?>
<!DOCTYPE jboss PUBLIC
"-//JBoss//DTD JBOSS 3.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">

<jboss>
<enterprise-beans>
<session>
<ejb-name>CacheDemo1</ejb-name>
<jndi-name>ejb/CacheDemo1</jndi-name>
<local-jndi-name>ejb/CacheDemo1Local</local-jndi-name>
<resource-ref>
<res-ref-name>XPCDataSource</res-ref-name>
<jndi-name>java:/XPCDataSource</jndi-name>
</resource-ref>
</session>
</enterprise-beans>
</jboss>

 

web.xml  in web/WEB-INF

<resource-ref>
<res-ref-name>XPCDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

 

jboss-web.xml in web/WEB-INF

<resource-ref>
<res-ref-name>XPCDataSource</res-ref-name>
<jndi-name>java:/XPCDataSource</jndi-name>
</resource-ref>

 

创建Data Source

Context c = new InitialContext();
Object obj = c.lookup("java:comp/env/XPCDataSource");
DataSource ds = (DataSource)narrow(obj, DataSource.class);
connection = ds.getConnection();

 

取得Transaction

//context is javax.ejb.SessionContext

//Transaction should be getten from EJB

UserTransaction tx = context.getUserTransaction();

 

Webspere deployer will change ejb-jar.xml. Never put struts to Webspere/lib/ext

posted on 2007-03-07 09:51 Welkin Hu 阅读(508) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: