jboss数据源

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

你可能感兴趣的:(jboss数据源)