Starting with Spring 3.0, XML configuration files are no longer necessary when developing a Spring application.
They can be replaced with annotations and configuration classes.
Configuration classes are Java classes annotated with @Configuration that contain bean definitions (methods annotated with
@Bean)
@Configuration
public class HelloWorldConfiguration {
// equivalent to
@Bean
public MessageProvider provider() {
return new HelloWorldMessageProvider();
}
// equivalent to
@Bean
public MessageRenderer renderer(){
MessageRenderer renderer = new StandardOutMessageRenderer();
renderer.setMessageProvider(provider());
return renderer;
}
}
Starting with Spring 3.0, XML configuration files are no longer necessary when developing a Spring application. They can be replaced with annotations and configuration classes. Configuration classes are Java classes annotated with @Configuration that contain bean definitions (methods annotated with @Bean)
@Configuration public class HelloWorldConfiguration { // equivalent to
@Bean
public MessageProvider provider() {
return new HelloWorldMessageProvider();
}
// equivalent to
@Bean
public MessageRenderer renderer(){
MessageRenderer renderer = new StandardOutMessageRenderer();
renderer.setMessageProvider(provider());
return renderer;
}
}