從Eclipse運行它時,我無法使我的DataSource與JNDI和Tomcat 6一起工作。我添加了一個context.xml中我的/ META-INF具有以下內容:帶有Tomcat 6和Eclipse的JNDI數據源
<Context>
<Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/database"
maxActive="15"
maxIdle="7"
validationQuery="Select 1" />
</Context>
並配置我的Spring bean如下:
<bean id="UserDatabase" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDB"></property>
<property name="lookupOnStartup" value="true"></property>
<property name="cache" value="true"></property>
<property name="proxyInterface" value="javax.sql.DataSource"></property>
</bean>
我還添加了這行我web.xml中:
<resource-ref>
<description>Connection Pool</description>
<res-ref-name>jdbc/myDB</res-ref-name>
<res-type>javax.sql.Datasource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
但由於某些原因,我仍然得到這個錯誤:
javax.naming.NameNotFoundException: The name jdbc is not associated to this context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
我不明白爲什麼這不起作用......任何想法?
謝謝丹尼,我想我更近了一步,現在我得到:javax.naming.NamingException:無法創建資源實例 – 2011-06-14 15:07:41