Spring4.x Tomcat JNDI 配置问题

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null‘ 错误原因。


tomcat  配置

     conf/server.xml 下的配置

  在<GlobalNamingResources> 下添加

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxWait="5000" name="jdbc/DbPool"password="123456" type="javax.sql.DataSource" url="jdbc:mysql://127.0.0.1:3306/myhs?useUnicode=true&amp;characterEncoding=UTF-8"username="root"/>

conf/context.xml 下的配置

<Context> 下添加

<ResourceLink global="jdbc/DbPool" name="jdbc/DbPool" type="javax.sql.DataSource"/>  

Spring

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/DbPool</value>
</property>
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>

报以上错误就是应为红色底色标注的地方名问题,tomcat下一定要是这样的名字。否则Spring无法创建dataSource。

posted on 2015-06-15 09:42  未亦末  阅读(226)  评论(0编辑  收藏  举报