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。

  • 相关阅读:
    2018前端越来越流行的的技术
    程序员怎么写出一份漂亮的简历
    程序员怎么写出一份漂亮的简历
    程序员如何利用空闲时间挣零花钱
    扫雷(mine)
    一道数论好题(math)
    消失的数字(number)
    1380 没有上司的舞会 40分
    2596 售货员的难题 水深搜
    JavaEE Tutorials (17)
  • 原文地址:https://www.cnblogs.com/mokingone/p/9109028.html
Copyright © 2011-2022 走看看