【发布时间】:2016-08-05 09:54:16
【问题描述】:
我发现了许多类似的相关问题,但我仍然无法使其正常工作。 这是我的网络应用程序的 pom.xml
<profiles>
<profile>
<id>mysql</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<dialect>org.hibernate.dialect.MySQLDialect</dialect>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost/exercisedb</url>
<username>root</username>
<password>password</password>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp/WEB-INF</directory>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
这是我试图在我的 applicationContext 中过滤的 bean,它位于 src/main/webapp/WEB-INF/spring/appServlet 文件夹中
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</bean>
我运行应用程序并收到此错误
Cannot load JDBC driver class '${driver}'
java.lang.ClassNotFoundException: ${driver}
我假设属性没有在构建时过滤。
编辑:webapp pom.xml
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp/WEB-INF/spring/appServlet</directory>
<targetPath>WEB-INF/spring/appServlet</targetPath>
<includes>
<include>applicationContext.xml</include>
</includes>
</resource>
</webResources>
现在过滤但使用 mvn jetty:run,同样的错误 我尝试部署到 tomcat(不是 maven 中的插件)并且它可以工作。
【问题讨论】:
-
试试不带引号的
${driver}