【发布时间】:2014-08-24 16:10:05
【问题描述】:
我在我的应用程序中添加了两个配置文件,它的外观如下:
<profiles>
<profile>
<id>dev</id>
<properties>
<db.username>root</db.username>
<db.password>root</db.password>
<db.connectionURL>localhost:3306</db.connectionURL>
<db.driverClass>com.mysql.jdbc.Driver</db.driverClass>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<db.username>prodroot</db.username>
<db.password>prodpass</db.password>
<db.connectionURL>localhost:3306</db.connectionURL>
<db.driverClass>com.mysql.jdbc.Driver</db.driverClass>
</properties>
</profile>
</profiles>
在我的 jdbc.properties 文件中,我更改了如下值:
jdbc.driverClassName=${db.driverClass}
jdbc.dialect=org.hibernate.dialect.MySQLDialect
jdbc.databaseurl=jdbc:mysql://${db.connectionURL}/dbname
jdbc.username=${db.username}
jdbc.password=${db.password}
这是来自spring-container.xml的bean
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
当我尝试部署我的应用程序时出现以下错误:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Could not resolve placeholder 'db.driverClass'
项目结构:
任何想法我做错了什么? 提前致谢!
已编辑:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp/WEB-INF/</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
【问题讨论】:
-
您在运行 Maven 构建时是否激活了您的配置文件之一?
-
manouti,当然,无论如何我可以让 maven clean 然后打包,当我使用 tomcat 运行我的应用程序时出现上面提供的错误