如题,我有两个配置文件,db.properties和config.properties,db.properties没问题,唯有config.properties读取有问题。
请教:如何通过@value方式读取这个properties文件,代码如图。
问题已解决,是做单元测试的没有加载spring.两种方法:1、创建IOC容器,从容器中获取Bean.ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");2、使用SpringTest。@RunWith(SpringJunit4ClassRunner.class)
https://www.cnblogs.com/shuaiandjun/p/7242609.html
你的引入config.properties方式错误了。应该和db.properties的引入方法一样,这样spring就会保存config.properties数值到域中,这样你要使用就可以通过@Value方法获取了。