1
這是我的mysql-ds.xml文件:在Spring應用程序從JBOSS 4.2.3配置JNDI數據源
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/DefaultDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/usuarios</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>da</password>
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
,這是我在context.xml中
<beans>
<bean name="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>jdbc/DefaultDS</value>
</property>
</bean>
豆
這是正確的方法嗎?當我運行我的JUnit測試出現此錯誤
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [context.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
這是我的這個網站感謝第一個問題。
添加了resourceRef財產也應該解決這個問題。 這告訴bean在JEE容器中查找DS –