1.下载ow2-jotm-dist-2.2.1
2.把jotm所有的jar放到Tomcat/lib下
3.创建文件carol.properties
# # JNDI (Protocol Invocation)
carol.protocols=jrmp
# Local RMI Invocation
carol.jvm.rmi.local.call=true
# do not use CAROL JNDI wrapper
carol.start.jndi=false
# do not start a name server
carol.start.ns=false
# Naming Factory
carol.jndi.java.nameing.factory.url.pkgs=org.apache.nameing
4.修改数据源配置文件
<?xml version='1.0' encoding='utf-8'?>
<Context path="/xflow" debug="0" reloadable="false" docBase="D:\workspace\xflow\WebRoot\">
<Resource name="jdbc/afunms"
auth="Container"
type="javax.sql.DataSource"
factory="org.objectweb.jotm.datasource.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
username="root"
password="root"
url="jdbc:mysql://localhost:3306/netflow?useUnicode=true&characterEncoding=utf-8" />
<Resource name="UserTransaction"
auth="Container"
type="javax.transaction.UserTransaction" />
<Transaction factory="org.objectweb.jotm.UserTransactionFactory"
jotm.timeout="60" />
</Context>
5.java代码这样写:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/afunms");
UserTransaction ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction");