占位符属性未解决

时间:2016-09-19 09:52:02

标签: java spring

我正在使用@Configuration并使用ehCacheConfig注释设置属性@Value

@Configuration
public class CacheConfig {    
    @Value("${configPath}")
    private Resource ehCacheConfig;   
}

但是当运行项目时出现如下错误。由于错误表明弹出容器未解析占位符属性configPath。谁能告诉我为什么?

  

java.io.FileNotFoundException:无法打开ServletContext资源   [/ $ {用configPath}]         org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)         org.springframework.cache.ehcache.EhCacheManagerUtils.parseConfiguration(EhCacheManagerUtils.java:107)

1 个答案:

答案 0 :(得分:0)

您需要定义PropertySource以从中加载configPath的值:

@Configuration
@PropertySource("classpath:/com/myco/app.properties")
public class CacheConfig {    

    @Value("${configPath}")
    private Resource ehCacheConfig;   

}

<强> app.properties

configPath: /home/[...]/myConfig.xml
相关问题