When running the junit test, I cannot force the application context to load properties from external property files.
Given the following:
Testclass
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:spring/app-config.xml") public class JdbcWatsonDaoTests { @Autowired JdbMyDao jdbcMyDao; @Before public void setUp() throws Exception { } @Test public void testMethod() { doSomeStuff(); } }
app-config.xml
<util:properties id="aProperties" location="classpath:spring/a.properties" /> <util:properties id="bProperties" location="classpath:spring/b.properties" /> <bean id="oracleDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="${oracle.url}"/> <property name="username" value="${oracle.username}"/> <property name="password" value="${oracle.password}"/> </bean>
and the a.properties and b.properties files are in the same place as app-config.xml ...
I found that when I run the test, the placeholders properties (literal "$ {property}") are what is sent to the oracle server instead of the values ββin the properties files.
I also tried using the bean configuration using PropertyPlaceholderConfigurer instead, but it still cannot find / enable properties.
I am using eclipse helios, spring 3.0.5, the latest release of m2eclipse and 4.4 junit. I had to lower junit for another maven / junit error.
When published to tomcat, properties are read and used correctly. I see the problem only when running the junit test.
java spring eclipse maven junit
camada
source share