Closed as not planned
Description
Stepan Koltsov opened SPR-8396 and commented
public class AutowireOverrides {
public static class TheBean {
@Autowired
@Value("from property")
public void setBla(String value) {
System.out.println("setBla: " + value);
}
}
@Configuration
public static class ContextConfiguration {
@Bean
public TheBean theBean() {
TheBean r = new TheBean();
r.setBla("from @Bean");
return r;
}
}
public static void main(String[] args) {
new AnnotationConfigApplicationContext(ContextConfiguration.class);
}
}
Obviously outputs
setBla: from @Bean
setBla: from property
and property specified in @Bean
method has lower priority.
Requesting a @Bean
(properties=...) attribute, so theBean() declaration could be written as:
@Bean(
properties={
@Property(name="bla", value="from @Bean")
}
)
public TheBean theBean() {
return new TheBean();
}
In this case Spring would call setBla only once with "from @Bean
" parameter value.
Assume HttpServer library class with @Autowired
threadPool property. I cannot declare two HttpServer instances that use different thread pools in the same application (without disabling autowire, switching to xmlconf etc).
Affects: 3.1 M1
Attachments:
- mylyn-context.zip (10.84 kB)
Issue Links:
- Support for autowire-candidate with @Bean [SPR-16204] #20752 Support for autowire-candidate with
@Bean
1 votes, 4 watchers