我有一节课:
@Configuration
@PropertySource("file:/opt/server/server.properties")
public class ServerConfiguration {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
// @Value("${path}")
private String path;
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
如果不注释@Value注释,它就能正常工作。但我希望它能自动完成。它在Spring应用程序中这样做,但这是一个普通的Spring5MVC应用程序。
难道不需要注释每个属性就能做到这一点吗?
发布于 2017-10-08 16:03:29
在SpringBoot中,您可以使用@ConfigurationProperties来避免对每个字段使用@Value。但是,据我所知,@ConfigurationProperties仅适用于SpringBoot (它是一个春季引导包)。
https://stackoverflow.com/questions/46637139
复制相似问题