Java @配置不自动加载属性

Java @配置不自动加载属性,java,spring,Java,Spring,我有这门课: @Configuration @PropertySource("file:/opt/server/server.properties") public class ServerConfiguration { @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceh

我有这门课:

@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应用程序


这甚至可以在不注释每个属性的情况下完成吗?

True,在SpringBoot中,您可以使用@ConfigurationProperties来避免对每个字段使用@Value。然而,据我所知@ConfigurationProperties仅适用于SpringBoot,它是一个SpringBoot包

有关更多详细信息: