下面是我的测试类中的注释配置。
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource("classpath:jdbc.properties")
@ContextConfiguration({"classpath:applicationContext.xml","classpath:mvc-dispatcher-servlet.xml"})
@WebAppConfigurationapplictionCotnext.xml包括jpa-context.xml,数据库配置为jpa-context.xml,dataSource由jdbc.properties配置。
当我运行测试方法时,由于jdbc.properties中的所有值都为null,无法打开连接。
然后在同一个测试类中添加一个访问属性的方法。
@Inject
private ApplicationContext context;
@Test
public void accessProperties(){
MutablePropertySources sources = ((ConfigurableApplicationContext) context)
.getEnvironment().getPropertySources();
System.out.println("jdbcUrl=="+sources.iterator().next().getProperty("jdbcUrl"));
}我获得了jdbc网址的成功。怎么了?
发布于 2016-05-07 08:06:49
如果您正在使用Apache,则需要将属性文件放在src/test/resources中。那应该是你的财产。
https://stackoverflow.com/questions/37086010
复制相似问题