Tomcat maven插件:无法找到jdbc

时间:2016-11-17 15:55:23

标签: java spring tomcat tomcat7 maven-tomcat-plugin

使用tomcat7-maven-plugin我启动需要连接到Mysql数据库的spring web应用程序。但是,在尝试此操作时,我收到错误"unable to find jdbc"

Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: N
ame [jdbc/contentDataSource] is not bound in this Context. Unable to find [jdbc].

我的pom文件包括。

     <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <port>9001</port>
            <path>/webapp</path>
            <serverXml>./src/main/tomcat/config/server.xml</serverXml>
            <contextFile>./src/main/tomcat/config/context.xml</contextFile>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <type>jar</type>
                <version>5.0.8</version>
            </dependency>
        </dependencies>
    </plugin>

Context.xml文件:

<?xml version='1.0' encoding='utf-8'?>
<Context>
    <ResourceLink global="jdbc/contentDataSource" name="jdbc/contentDataSource" type="javax.sql.DataSource"/>
</Context>

Server.xml包括:

<GlobalNamingResources>
    <Resource name="jdbc/contentDataSource"
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="org.gjt.mm.mysql.Driver"
              url="jdbc:mysql://database.lan/databaseName"
              username="root"
              password="pass" />
</GlobalNamingResources>

web.xml包含在最后:

    <resource-ref>
        <res-ref-name>jdbc/contentDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

WEB-INF / applicationContext.xml包含在开头:

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

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
    </bean>

为什么JDBC无法识别?

0 个答案:

没有答案