【问题标题】:place holder property is not resolved占位符属性未解决
【发布时间】:2016-09-19 17:57:47
【问题描述】:

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

@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)

【问题讨论】:

    标签: java spring


    【解决方案1】:

    您需要定义一个PropertySource 以从那里加载configPath 的值:

    @Configuration
    @PropertySource("classpath:/com/myco/app.properties")
    public class CacheConfig {    
    
        @Value("${configPath}")
        private Resource ehCacheConfig;   
    
    }
    

    app.properties

    configPath: /home/[...]/myConfig.xml
    

    【讨论】:

    • 我在 中添加属性文件,我想这样可以喜欢使用 PropertySource
    • 可以发一下base.properties的内容吗?
    • configPath=classpath:ehcache.xml authenticationCacheName=authenticationCache authorizationCacheName=authorizationCache
    • 我也试过了,效果很好。你能把ignore-resource-not-found="true" 去掉,看看它在启动时是否显示错误?
    猜你喜欢
    • 2017-09-15
    • 1970-01-01
    • 2016-02-28
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 2012-08-03
    • 2016-03-04
    相关资源
    最近更新 更多