【发布时间】:2016-05-07 07:55:58
【问题描述】:
这是我的测试类中的注解配置。
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource("classpath:jdbc.properties")
@ContextConfiguration({"classpath:applicationContext.xml","classpath:mvc-dispatcher-servlet.xml"})
@WebAppConfiguration
applictionCotnext.xml包括jpa-context.xml,数据库配置在jpa-context.xml,dataSource配置在jdbc.properties。
当我运行测试方法时,由于 jdbc.properties 中的所有值都为空而导致无法打开连接。
然后我在同一个测试类中添加一个访问属性的方法。
@Inject
private ApplicationContext context;
@Test
public void accessProperties(){
MutablePropertySources sources = ((ConfigurableApplicationContext) context)
.getEnvironment().getPropertySources();
System.out.println("jdbcUrl=="+sources.iterator().next().getProperty("jdbcUrl"));
}
我获得了jdbc 网址成功。怎么了?
【问题讨论】:
标签: java spring jpa jdbc junit