相关疑难解决方法(0)

为什么要使用@PostConstruct?

在托管bean中,@PostConstruct在常规Java对象构造函数之后调用.

我为什么要使用@PostConstructbean初始化,而不是常规构造函数本身?

java dependency-injection jsr299 java-ee cdi

274
推荐指数
4
解决办法
20万
查看次数

@Value未注入

我正在尝试将属性文件中的值注入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}而不是字符串值本身.

spring properties code-injection

5
推荐指数
1
解决办法
5758
查看次数