I am trying out spring’s java configuration. While using xml config files my unit tests use to have the following
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(....)
If I am using java configuration, How do i do it. or should I just use
ApplicationContext appConfig = new AnnotationConfigApplicationContext(SimpleConfiguration.class);
As of Spring 3.1, @ContextConfiguration now has full support for @Configuration classes; no XML required.
See http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#d0e1392
Or more specifically, http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#testcontext-ctx-management-javaconfig, which shows the following code snippet:
AppConfigandTestConfigare @Configuration classes (aka “Java config” classes in @user373201’s comments)