For automatic injection, @Autowired
is enough, why use @Value
. I think it maybe ambiguous and semantic inconsistency.
see AutowiredAnnotationBeanPostProcessor.
I have to emphasize that the function of @Autowired
and @Value
is equivalent for AutowiredAnnotationBeanPostProcessor
. Refer to the following code, They all implement injection functions.
@SuppressWarnings("unchecked")
public AutowiredAnnotationBeanPostProcessor() {
this.autowiredAnnotationTypes.add(Autowired.class);
this.autowiredAnnotationTypes.add(Value.class);
try {
this.autowiredAnnotationTypes.add((Class<? extends Annotation>)
ClassUtils.forName("javax.inject.Inject", AutowiredAnnotationBeanPostProcessor.class.getClassLoader()));
logger.info("JSR-330 'javax.inject.Inject' annotation found and supported for autowiring");
}
catch (ClassNotFoundException ex) {
// JSR-330 API not available - simply skip.
}
}
the placeholder function for @Value
is supported by PropertySourcesPlaceholderConfigurer
other than AutowiredAnnotationBeanPostProcessor
.