cainawuha / Pro-Spring-5th-notes

0 stars 0 forks source link

annotation #1

Open cainawuha opened 3 years ago

cainawuha commented 3 years ago

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; } }