Looking up spring beans defined in java configuration classes
Recently I got rid of XML files in Spring app used for configuration by using annotated classes. A basic issue -how to “lookup” these instance if required, took me some time. The good old way with XML
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("/META-INF/application-context-root.xml");
It’s still simple, use a different class with configuration class as argument
ApplicationContext context = new AnnotationConfigApplicationContext(RootConfig.class); sessionManager = (SessionManager) context.getBean("sessionManager");
Posted on July 26, 2013, in Java, Spring and tagged Annotation, configuration, loading spring configuration beans, spring annotation. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0