zoukankan      html  css  js  c++  java
  • 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。

  • 相关阅读:
    2020软件工程作业01
    问题清单
    2020软件工程个人作业06——软件工程实践总结作业
    感谢随笔
    2020软件工程作业05
    2020软件工程作业04
    2020软件工程作业03
    2020软件工程作业02
    2020软件工程作业01
    2020软件工程个人作业06——软件工程实践总结作业
  • 原文地址:https://www.cnblogs.com/mokingone/p/9109028.html
Copyright © 2011-2022 走看看