需要帮助,问题在哪里?@Value在春季不工作@Configuration
我有加载性能
WebConfig.java配置类
@Configuration
@PropertySource(value={"classpath:application.properties"})
class WebConfig extends WebMvcConfigurerAdapter{
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
我有,我想使用的属性
MyServerConfig另一个配置类.java
@Configuration
class MyServerConfig {
@Value("${server.url}")
private String url;
...
}
个
application.properties
server.url=http://localhost:8080/test/abc
但要:
java.lang.IllegalArgumentException异常:无法解析占位符 'server.url'。
不知道这里缺少什么吗?有什么想法吗?
你为什么在类'WebConfig'' static'中创建方法'propertySourcesPlaceholderConfigurer'? – Jesper
你可以发布你的配置** application.properties **文件吗? – 2017-10-04 12:39:08
@Jesper只是尝试我在谷歌找到的解决方案之一,即使你删除静态或完全删除方法,它不工作 –