Skip to content

Instantly share code, notes, and snippets.

@Qkyrie
Created December 5, 2013 10:27
Show Gist options
  • Save Qkyrie/7803192 to your computer and use it in GitHub Desktop.
Save Qkyrie/7803192 to your computer and use it in GitHub Desktop.
A simple JavaConfig @configuration class. The equivalent xml is also added
@Configuration
public class AppConfig {
@Bean
public MyService myService() {
return new MyServiceImpl();
}
}
<beans>
<bean id="myService" class="com.acme.services.MyServiceImpl"/>
</beans>
public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
MyService myService = ctx.getBean(MyService.class);
myService.doStuff();
}
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