Created
December 5, 2013 10:27
-
-
Save Qkyrie/7803192 to your computer and use it in GitHub Desktop.
A simple JavaConfig @configuration class. The equivalent xml is also added
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 AppConfig { | |
@Bean | |
public MyService myService() { | |
return new MyServiceImpl(); | |
} | |
} |
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
<beans> | |
<bean id="myService" class="com.acme.services.MyServiceImpl"/> | |
</beans> |
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 static void main(String[] args) { | |
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); | |
MyService myService = ctx.getBean(MyService.class); | |
myService.doStuff(); | |
} |
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 static void main(String[] args) { | |
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); | |
ctx.register(AppConfig.class, OtherConfig.class); | |
ctx.register(AdditionalConfig.class); | |
ctx.refresh(); | |
MyService myService = ctx.getBean(MyService.class); | |
myService.doStuff(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment