如何在Tomcat7下的Axis2中配置JNDI上下文?(使用myBatis的JAX-WSWeb服务)
我实现了一个在Tomcat7下的Axis2(Jax WS)上运行的Java web服务。 为了从postgreSQL获取数据,此web服务使用mybatis框架。 如果我在mybatis-config.xml中手动设置连接参数,所有这些都可以正常工作,但是 我想使用JNDI数据源直接通过服务器上下文获取它们 在myBatis-config.xml中,我放置了以下标记(在环境标记中):如何在Tomcat7下的Axis2中配置JNDI上下文?(使用myBatis的JAX-WSWeb服务),tomcat,axis2,jndi,mybatis,Tomcat,Axis2,Jndi,Mybatis,我实现了一个在Tomcat7下的Axis2(Jax WS)上运行的Java web服务。 为了从postgreSQL获取数据,此web服务使用mybatis框架。 如果我在mybatis-config.xml中手动设置连接参数,所有这些都可以正常工作,但是 我想使用JNDI数据源直接通过服务器上下文获取它们 在myBatis-config.xml中,我放置了以下标记(在环境标记中): 在internet上搜索时,我还了解到我必须使用以下标记创建Tomcat(或Axis2?)上下文: <
在internet上搜索时,我还了解到我必须使用以下标记创建Tomcat(或Axis2?)上下文:
<Resource name="jdbc/myWebService" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/myDB" username="user" password="password" maxActive="20" maxIdle="10" maxWait="-1"/>
及
连接PostgreSQL
jdbc/myWebService
javax.sql.DataSource
容器
可分享
但是我不知道我必须把它们放在哪里(在哪个xml文件中)以及是否需要其他任何东西。可以在
[your webapp name]/META-INF/context.xml
文件中定义资源
定义,例如:
<?xml version='1.0' encoding='utf-8'?>
<Context path="/[your webapp context]" privileged="true">
<Resource name="jdbc/myWebService" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/myDB" username="user" password="password" maxActive="20" maxIdle="10" maxWait="-1"/>
</Context>
还有其他选项,例如在server.xml
或共享上下文中定义它。看
资源引用
进入您的[您的webapp名称]/WEB-INF/WEB.xml
<resource-ref>
<description>ConnectionToPostgreSQL</description>
<res-ref-name>jdbc/myWebService</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<?xml version='1.0' encoding='utf-8'?>
<Context path="/[your webapp context]" privileged="true">
<Resource name="jdbc/myWebService" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/myDB" username="user" password="password" maxActive="20" maxIdle="10" maxWait="-1"/>
</Context>