Showing posts with label circular dependencies. Show all posts
Showing posts with label circular dependencies. Show all posts

Thursday, 19 June 2014

How to test circular dependencies in Spring

This will raise an exception if your dependencies have circular dependency problem

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class IngesterCircularReferencesTest {

        @Test
        public void circularReferencesTest() {
                ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
                context.setAllowCircularReferences(false);
                String[] configLocations = new String[] { "/your-beans.xml" };
                context.setConfigLocations(configLocations);
                context.refresh();
                context.close();
        }
}