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:
Issue Links:
1 votes, 4 watchers
Stepan Koltsov opened SPR-8396 and commented
Obviously outputs
and property specified in
@Beanmethod has lower priority.Requesting a
@Bean(properties=...) attribute, so theBean() declaration could be written as:In this case Spring would call setBla only once with "from
@Bean" parameter value.Assume HttpServer library class with
@AutowiredthreadPool 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:
Issue Links:
@Bean1 votes, 4 watchers