在Context文件中配置Tomcat 7 JDNI数据源的问题

时间:2012-11-30 22:10:07

标签: java spring datasource tomcat7 jndi

这是我得到的例外:

Error creating bean with name 'jndiDataSource' defined in class path resource [spring/database.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [connection_pool] is not bound in this Context. Unable to find [connection_pool]

这是我的数据源bean:

<bean id="jndiDataSource"
      class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="connection_pool" />
</bean>

这是我放入MyApp##1.0.2.xml的上下文文件tomcat7/conf/Catalina/localhost

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="path\to\war\my-app-1.0.2.war"
    antiResourceLocking="false" privileged="true" >

<Resource name="connection_pool" 
            url="jdbc:mysql://localhost:3306/db_name"
            driverClassName="com.mysql.jdbc.Driver"
            username="username" password="password" 
            auth="Container" type="javax.sql.DataSource"
            maxActive="100" maxIdle="30" maxWait="10000" />

</Context>

有没有人知道为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

试试这个,它应该提供正确的配置:

<jee:jndi-lookup id="myDataSource" jndi-name="java:connection_pool" />