2012-11-30 121 views
0

這是我得到的異常:問題的背景,文件配置Tomcat 7 JDNI數據源

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 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> 

有沒有人有任何想法,爲什麼這不工作?

+0

只是猜測這裏,但你有沒有嘗試過沒有名字的下劃線? – GreyBeardedGeek

+0

我只是這樣做,它仍然無法正常工作... – Gevorg

+0

看看這個問題的接受答案:http://stackoverflow.com/questions/9183321/how-to-use-jndi-datasource-provided-by -Tomcat式彈簧 – GreyBeardedGeek

回答

0

嘗試此相反,它應該提供正確的配置:

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