我在pom.xml中有這樣的:春天測試配置忽略行家過濾
<build>
<finalName>${project.artifactId}</finalName>
<filters>
<filter>${project.basedir}/src/main/resources/filters/${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
...
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>qa</id>
<properties>
<env>qa</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
和我在的src /主/資源/過濾器這些文件:dev.properties,qa.properties和prod.properties 。
但我的Spring配置測試-DB-config.xml文件中的src /測試/資源不撿的性質我有文件中的值:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>${db.driver}</value>
</property>
<property name="url">
<value>${db.url}</value>
</property>
<property name="username">
<value>${db.usename}</value>
</property>
<property name="password">
<value>${db.password}</value>
</property>
</bean>
有人能指出我在正確的方向?由於
這是我收到的錯誤:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.185 sec <<< FAILURE!
testCustomerExists(com.xxxx.hcs.persistence.repository.CustomerRepositoryTest) Time elapsed: 1.973 sec <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
...
在dev.properties我:
db.driver=oracle.jdbc.OracleDriver
db.url=jdbc:oracle:thin:@hrsdev.xxxx.net:1548:yyyy
db.usedb.passwordrname=xxxx
db.password=yyyy
當我把這些值在測試-DB-config.xml中,測試案件運行良好。所以我知道它是由變量替換引起的。
什麼是錯誤訊息?拼寫正確嗎? 「db.usenamer」 – bgth
你用什麼Spring配置來包含屬性文件? – geoand
我犯了一個錯字。更正的db.usename不幸的是它不是導致錯誤的原因。 – user3260768