我们的项目必须从下面的数据源配置切换到 JBoss AS 7.1.1 提供的 jndi 数据源。
应用程序上下文.xml:
...
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="xxxx" />
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml"/>
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform"
value="org.hibernate.dialect.SQLServerDialect" />
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
...
来自 applicationContext.xml 的“旧”数据源:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${database.driverClassName}" />
<property name="jdbcUrl" value="${database.url}" />
<property name="user" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="initialPoolSize" value="10" />
<property name="checkoutTimeout" value="0" />
<property name="maxStatements" value="50" />
<property name="maxIdleTime" value="300" />
</bean>
数据库属性:
database.driverClassName=net.sourceforge.jtds.jdbc.Driver
database.url=jdbc:jtds:sqlserver://xxx:xxx/
database.username=username
database.password=pwd
使用 jndi 的“新”数据源配置:
<jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/myDataSource"
expected-type="javax.sql.DataSource" resource-ref="false">
</jee:jndi-lookup>
服务器日志:
Caused by: javax.resource.ResourceException: Wrong driver class [class org.h2.Driver] for
this connection URL [jdbc:jtds:sqlserver://xxx:xxx]
at
org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(
LocalManagedConnectionFactory.java:251)
... 68 more
我必须在哪里添加驱动程序类?JNDI 调用正确吗?