我想通过 JNDI 进入DataSource
。Spring
所有的配置都给出了。
谁能告诉我配置有什么问题。
我想在这里提到的一件事是 JNDI DS 托管在不托管Spring
应用程序的 JBoss 服务器上。
配置
数据源-ds.xml
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/wc-mysql</jndi-name>
<connection-url>jdbc:mysql://xx.xx.xx.xx:3306/club</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>club</user-name>
<password>club</password>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<use-java-context>false</use-java-context>
<metadata><type-mapping>mySQL</type-mapping></metadata>
</local-tx-datasource>
</datasources>
配置上下文.xml
<bean id="wcDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/wc-mysql" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">jnp://yy.yy.yy.yy:1099</prop>
<!--
<prop key="java.naming.factory.initial">
org.springframework.mock.jndi.SimpleNamingContextBuilder
</prop>
<prop key="java.naming.factory.url.pkgs">yourPackagePrefixesGoHere</prop> -->
<!-- other key=values here -->
</props>
</property>
<!-- other properties here-->
</bean>
例外
Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in 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)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)