jingshen 发表于 2017-1-29 06:19:06

tomcat-maven-plugin数据源配置问题

  根据google出的文章,在src/main/resources/下建了contextFile.xml并在其中配置了数据源,然后在web.xml中做了如下引用
  <resource-ref>
<description>ConnectionPool DataSource Reference</description>
<res-ref-name>sysDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
  启动报如下错误
  nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
  中间的解决过程就省略了,摸索出如下解决方法
  在pom.xml中做如下的配置
  <build>
    <finalName>lgn</finalName>
    <plugins>
    <plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>tomcat-maven-plugin</artifactId>
       <version>1.1</version>
      <configuration>
          <contextFile>src/main/resources/contextFile.xml</contextFile>
      </configuration>      
      <dependencies>
      <dependency>
          <groupId>com.oracle</groupId>
          <artifactId>ojdbc</artifactId>
          <version>10.2.0.5</version>
      </dependency>
      </dependencies>      
   </plugin>
</plugins>   
</build>
  其中ojdbc是需要自己配置到nexus的私服中的
  一定要指定contextFile文件位置,google出的很多文章中介绍的时候没指出这点
  web.xml中的resource-ref配置在我的环境中不配置也可以,我就去掉了,正因为有了这个配置而tomcat又没正确加载数据源才报了如上的错误,我理解应该是引用错误吧,如果不加resource-ref配置,就会报找不到数据源的错误,可能朝这个方向解决错误更好解决点,其实用不用是不是配resource-ref跟用不用maven也没关系,只是在maven中使用tomcat很多配置都要在插件配置中用configuration配置
页: [1]
查看完整版本: tomcat-maven-plugin数据源配置问题