在托管bean中,@PostConstruct在常规Java对象构造函数之后调用.
我为什么要使用@PostConstructbean初始化,而不是常规构造函数本身?
我正在尝试将属性文件中的值注入spring配置类,如下所示:
@Configuration
@EnableWebMvc
public class ImagesContext {
@Autowired
@Value("${some.property.com}")
private String property;
@Bean
public MyClass getMyClass() {
return new MyClass(property);
}
}
Run Code Online (Sandbox Code Playgroud)
但该属性未正确注入.相反,当我调试时,我看到property字符串包含${some.property.com}而不是字符串值本身.