Created
January 18, 2012 15:36
-
-
Save keesun/1633571 to your computer and use it in GitHub Desktop.
Spring 3.1's Configurer Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| @EnableHello | |
| public class AppConfig implements NameConfigurer { | |
| @Override | |
| public void configure(Hello hello) { | |
| hello.setName("Thank you very much, Toby."); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Retention(value = RetentionPolicy.RUNTIME) | |
| @Import(HelloConfig.class) | |
| public @interface EnableHello { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| public class HelloConfig { | |
| @Autowired NameConfigurer configurer; | |
| @Bean | |
| public Hello hello() { | |
| Hello h = new Hello(); | |
| configurer.configure(h); | |
| return h; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface NameConfigurer { | |
| void configure(Hello hello); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment