簡體   English   中英

占位符屬性未解析

[英]place holder property is not resolved

我正在使用@Configuration並使用@Value注釋設置屬性ehCacheConfig

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

但是,在運行項目時,將發生以下錯誤。 由於錯誤表明占位符屬性configPath不能被spring容器解析。 誰能告訴我為什么?

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

您需要定義一個PropertySource從那里加載configPath的值:

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

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

}

app.properties

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM