2014-01-09 44 views
2

我一直在寻找解决这个问题3天,阅读论坛...然后我决定寻求一些帮助。无情地说,你的帮助将不胜感激:-)HTTP 500 - 无法创建用于连接URL'''的类''的JDBC驱动程序'null'

我在Tomcat中创建了一个jndi资源在Tomcat中的context.xml实例在我的web应用程序工作正常,当我从eclipse启动服务器。当我从eclipse的“运行配置”启动web应用程序时,它不能正常工作:clean tomcat7:run。我的目标是将构建,部署,启动服务器委托给eclipse中的maven。

我已经把Tomcat_Home/lib中的mysql-connector-java-5.1.27.jar。

我不想将数据源配置放在应用程序中(没有META-INF ....),因为jndi的一个目标是将数据源信息放在应用程序之外。

感谢您阅读并花费时间查找解决方案。

技术规格

  • 蚀:JUNO release2
  • 春天工具套件:3.4
  • WTP
  • M2E:1.4
  • 行家:3.0.2
  • JDK:21年6月1日
  • tomcat:7.0.25

    MySQL的:5.6.14

堆栈跟踪

type Exception report 

message Request processing failed; nested exception is 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' 

description The server encountered an internal error that prevented it from fulfilling this request. 

exception 

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is 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' 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927) 
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 


root cause 

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' 
    org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) 
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:662) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702) 
    org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:178) 
    com.marc.springmvc3.dao.PersonDAO.getPersonById(PersonDAO.java:26) 
    com.marc.springmvc3.service.PersonService.getAllPersons(PersonService.java:18) 
    com.marc.springmvc3.mvc.PersonController.getListOfPerson(PersonController.java:33) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    java.lang.reflect.Method.invoke(Method.java:597) 
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) 
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
    org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123) 
    org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97) 
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:723) 
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687) 
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) 
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) 
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 


root cause 

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' 
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452) 
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371) 
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 
    org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) 
    org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) 
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:662) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702) 
    org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:178) 
    com.marc.springmvc3.dao.PersonDAO.getPersonById(PersonDAO.java:26) 
    com.marc.springmvc3.service.PersonService.getAllPersons(PersonService.java:18) 
    com.marc.springmvc3.mvc.PersonController.getListOfPerson(PersonController.java:33) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    java.lang.reflect.Method.invoke(Method.java:597) 
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) 
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
    org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123) 
    org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97) 
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:723) 
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687) 
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) 
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) 
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 


root cause 

java.lang.NullPointerException 
    sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507) 
    sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476) 
    sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307) 
    java.sql.DriverManager.getDriver(DriverManager.java:253) 
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437) 
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371) 
    org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 
    org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) 
    org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) 
    org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:662) 
    org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702) 
    org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:178) 
    com.marc.springmvc3.dao.PersonDAO.getPersonById(PersonDAO.java:26) 
    com.marc.springmvc3.service.PersonService.getAllPersons(PersonService.java:18) 
    com.marc.springmvc3.mvc.PersonController.getListOfPerson(PersonController.java:33) 
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    java.lang.reflect.Method.invoke(Method.java:597) 
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) 
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
    org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:123) 
    org.springframework.web.method.annotation.ModelFactory.initModel(ModelFactory.java:97) 
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:723) 
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687) 
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) 
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) 
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs. 

的pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
        http://maven.apache.org/maven-v4_0_0.xsd"> 

<modelVersion>4.0.0</modelVersion> 
<groupId>com.marc</groupId> 
<artifactId>spring-mvc-3</artifactId> 
<name>spring-mvc-3</name> 
<packaging>war</packaging> 
<version>1.0.0-BUILD-SNAPSHOT</version> 

<properties> 
    <java-version>1.6</java-version> 
    <org.springframework-version>3.2.0.RELEASE</org.springframework-version> 
    <org.aspectj-version>1.6.10</org.aspectj-version> 
    <org.slf4j-version>1.6.1</org.slf4j-version> 
</properties> 

<dependencies> 
    <!-- Spring --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${org.springframework-version}</version> 
     <exclusions> 
      <!-- Exclude Commons Logging in favor of SLF4j --> 
      <exclusion> 
       <groupId>commons-logging</groupId> 
       <artifactId>commons-logging</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 
    <!-- AspectJ --> 
    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjrt</artifactId> 
     <version>${org.aspectj-version}</version> 
    </dependency> 

    <!-- Logging --> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>${org.slf4j-version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>jcl-over-slf4j</artifactId> 
     <version>${org.slf4j-version}</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>${org.slf4j-version}</version> 
     <scope>runtime</scope> 
    </dependency> 

    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.16</version> 
     <scope>runtime</scope> 
    </dependency> 

    <!-- @Inject --> 
    <dependency> 
     <groupId>javax.inject</groupId> 
     <artifactId>javax.inject</artifactId> 
     <version>1</version> 
    </dependency> 

    <!-- JSR 303 with Hibernate Validator --> 
    <dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.0.0.GA</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>4.1.0.Final</version> 
    </dependency> 

    <!-- MYSQL driver--> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.27</version> 
    </dependency> 

    <!-- JDBC --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-jdbc</artifactId> 
     <version>${org.springframework-version}</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-dbcp</groupId> 
     <artifactId>commons-dbcp</artifactId> 
     <version>20030825.184428</version> 
    </dependency> 

    <!-- Test --> 
    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-core</artifactId> 
     <version>1.9.5</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 


    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
    </dependency> 
</dependencies> 

<build> 
    <finalName>spring-mvc-3</finalName> 
    <plugins> 
     <!-- Maven Tomcat Plugin --> 
     <plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat7-maven-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
       <url>http://127.0.0.1:8080/manager/text</url> 
       <server>TomcatServer</server> 
       <path>/${project.build.finalName}</path> 
       <port>8080</port> 
       <charset>UTF-8</charset> 
       <finalName>${project.build.finalName}</finalName> 
       <username>ssss</username> 
       <password>dddddddddd</password> 
      </configuration> 
      <dependencies> 
       <dependency> 
        <groupId>mysql</groupId> 
        <artifactId>mysql-connector-java</artifactId> 
        <version>5.1.27</version> 
       </dependency> 
      </dependencies> 
     </plugin> 

     <!-- Maven compiler plugin --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version>     
      <configuration> 
       <source>${java-version}</source> 
       <target>${java-version}</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

服务器/ Tomcat的配置/ Tomcat的users.xml中(在Eclipse)

<role rolename="admin"/> 
    <user username="ssss" password="dddddddddd" roles="admin"/> 

的web.xml

<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

    <display-name>Spring Web MVC Application</display-name> 

    <servlet> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>mvc-dispatcher</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <!-- database jndi reference --> 
    <description>MySQL Test App</description> 
    <resource-ref> 
     <description>DB Connection</description> 
     <res-ref-name>jdbc/TestDB</res-ref-name> 
     <res-type>javax.sql.DataSource</res-type> 
     <res-auth>Container</res-auth> 
    </resource-ref> 
</web-app> 

MVC-调度-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/jee 
     http://www.springframework.org/schema/jee/spring-jee-3.2.xsd"> 

    <jee:jndi-lookup id="dataSource" 
     jndi-name="jdbc/TestDB" 
     expected-type="javax.sql.DataSource" 
     resource-ref="true"/> 

    <bean id="personDao" class="com.marc.springmvc3.dao.PersonDAO"> 
     <property name="dataSource" ref="dataSource"/> 
     </bean> 

的Tomcat的context.xml(在Eclipse)

<?xml version="1.0" encoding="UTF-8"?> 
<Context> 

    <!-- Default set of monitored resources --> 
    <WatchedResource>WEB-INF/web.xml</WatchedResource> 

    <!-- Uncomment this to disable session persistence across Tomcat restarts --> 
    <!-- 
    <Manager pathname="" /> 
    --> 

    <!-- Uncomment this to enable Comet connection tacking (provides events 
     on session expiration as well as webapp lifecycle) --> 
    <!-- 
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> 
    --> 

<Resource name="jdbc/TestDB" 
      username="xxx" 
      password="xxxxxxxx" 
      driverClassName="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://localhost:3306/mytest" 
      auth="Container" 
      type="javax.sql.DataSource" 
      maxActive="100" 
      maxIdle="30" 
      maxWait="10000" 
      initialSize="1"/> 


<!--  <ResourceLink name="jdbc/TestDB" 
     global="jdbc/TestDB" 
     type="javax.sql.DataSource"/> --> 
</Context> 
+1

你还没有定义jdbc/TestDB是什么地方,因此你没有数据库驱动 –

+0

是的,'context.xml'是错误的,应该包含'jdbc/TestDB'的定义。在答案中添加了正确的'config.xml'。 – MariuszS

+0

我在我的文章中犯了一个错误。我刚更新了web.xml和tomcat context.xml(eclipse) – user3178994

回答

2

,我终于找到了解决办法,我会与谁遇到了同样的问题分享。

将src/main/webapp下的META-INF文件夹创建为WEB-INF sibling 将Tomcat-config/context.xml文件移至META-INF文件夹。你会在pom.xml中看到这个文件不会成为WAR文件的一部分。

META-INF/context.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<Context> 

    <!-- Default set of monitored resources --> 
    <WatchedResource>WEB-INF/web.xml</WatchedResource> 

<Resource name="jdbc/TestDB" 
      username="xxxx" 
      password="xxxxxxxxxx" 
      driverClassName="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://localhost:3306/TestDB" 
      auth="Container" 
      type="javax.sql.DataSource" 
      maxActive="100" 
      maxIdle="30" 
      maxWait="10000" 
      initialSize="1"/> 
</Context> 

适应pom.xml中

<plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat7-maven-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
       <url>http://127.0.0.1:8080/manager/text</url> 
       <server>TomcatServer</server> <!-- user + password defined in the Maven/conf/settings.xml--> 
       <path>/${project.build.finalName}</path> 
       <port>8080</port> 
       <charset>UTF-8</charset> 
       <finalName>${project.build.finalName}</finalName> 
       <contextFile>${project.basedir}/src/main/webapp/META-INF/context.xml</contextFile> <!--The path of the Tomcat context XML file. This is not used for war deployment mode.--> 
      </configuration> 
      <dependencies> 
       <dependency> 
        <groupId>mysql</groupId> 
        <artifactId>mysql-connector-java</artifactId> <!-- driver mysql --> 
        <version>5.1.27</version> 
       </dependency> 
      </dependencies> 
     </plugin> 

MAVEN_HOME/CONF/settings.xml中 的ID是在pom.xml引用。用户名和密码在tomcat-users.xml中

<server> 
    <id>TomcatServer</id> 
    <username>xxxxx</username> 
    <password>xxxxxxxxx</password> 
</server> 

的Eclipse /运行宣布 - 运行配置...

  • 创建新的启动配置
  • 基地direrctory $ {workspace_loc:/项目名称}
  • 目标干净tomcat7:运行

  • 应用

  • 运行

下一次,你可以在附近的运行方式......在工具栏按钮上的箭头单击并选择要运行的配置。 “停止”和“重新启动”按钮非常有用。

+0

我认为你可以简化这个配置,如果这不是你的要求,就不要使用JEE资源:) Spring对环境配置,配置文件等有非常好的支持。 – MariuszS

6

我觉得你的tomcat安装不使用你的context.xml。请创建新鲜的tomcat,配置context.xml和libs并直接从系统运行Tomcat(无需Eclipse等)。


问题进行了更新,回答以下是过时:/

最重要的部分是:

Cannot create JDBC driver of class '' for connect URL 'null' 

你的驱动程序类是null和连接URL是null

应用配置需要在服务器上配置资源jdbc/TestDB

<resource-ref> 
    <description>DB Connection</description> 
    <res-ref-name>jdbc/TestDB</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

<jee:jndi-lookup id="dataSource" 
    jndi-name="jdbc/TestDB" 
    expected-type="javax.sql.DataSource" 
    resource-ref="true"/> 

但是你的Tomcat配置Servers/tomcat-config/context.xml是错误的。它看起来像弹簧应用程序配置。

<web-app id="WebApp_ID" version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

... 

标准的Tomcat context.xml看起来是这样的:

<?xml version='1.0' encoding='utf-8'?> 
<Context> 
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" 
    username="user" password="pass" 
    driverClassName="com.mysql.jdbc.Driver" 
    url="jdbc:mysql://localhost:3306/testDB?characterEncoding=utf8" maxActive="8"/> 

</Context> 
+1

Out of票或我会+1这个。 –

+0

教你请指导http://stackoverflow.com/questions/39548268/nested-exception-is-java-sql-sqlexception-cannot-create-jdbc-driver-of-class? – Prateek

相关问题