Joa*_*les 9 eclipse spring tomcat jndi
从Eclipse运行它时,我无法让我的DataSource使用JNDI和Tomcat 6.我已经使用以下内容向我的/ META-INF添加了一个context.xml:
<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>
Run Code Online (Sandbox Code Playgroud)
并配置我的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>
Run Code Online (Sandbox Code Playgroud)
我还将这些行添加到我的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>
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,我仍然得到这个错误:
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)
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这不起作用......有什么想法吗?
我更改了以下内容,现在它可以工作:
在我的context.xml中完成了Context标记:
<Context docBase="myApp" path="/myApp" reloadable="true" source="org.eclipse.jst.jee.server:app">
Run Code Online (Sandbox Code Playgroud)
并且在连接URL中,该字符&导致Cannot create resource错误,不知道为什么,所以我的URL现在就像:
jdbc:mysql://localhost/database?useUnicode=true&characterEncoding=utf-8
Run Code Online (Sandbox Code Playgroud)
请注意&URL中的URL ...