java - How to get Spring to autowire integration test class using multiple contexts? -


One of my integration tests uses multiple spring reference files. It appears that spring is only auto-borne in the beans from the first reference and not the second. Anyone I know how wrong I am doing or how to solve the problem

 @RunWith (SpringJUnit4ClassRunner.class) @ContextConfiguration (locations = {? "Classpath: / META-INF / spring / applicationContext.xml "," classpath: /META-INF/spring/applicationContext-security.xml "}) @Configurable public square UserDetailsServiceImplIntegrationTest {@Autowired UserDataOnDemand DOD; // @ etoWire does not work with this application for this bean. Tag-security.exml User Development Users; @ Before public idle setup () {dod.init (); // Optional solution for Autovalan problem userDetailsService = (UserDetailsService) ctx.getBean ("userDetailsService"); } @Test Public Zero Test Leader Up () {UserDetails ud = userDetailsService.loadUserByUsername ("david@somewhere.co.za"); Assert.assertEquals ("david@somewhere.co.za", ud.getUsername ()); }} 

I'm using Spring 3.0.3

Here trace trace is when I uncomment the @Autowired line for UserDetailsService.

 org.springframework. beans.factory.BeanCreationException: Error creating bean with name 'za.co.acme.app.security.UserDetailsServiceImplIntegrationTest': autowired failed dependency injection; Nested exception org.springframework.beans.factory.BeanCreationException the region could not autowire: org.springframework.security.core.userdetails.UserDetailsService za.co.acme.app.security.UserDetailsServiceImplIntegrationTest.userDetailsService; [Org.springframework.security.core.userdetails.UserDetailsService] follows a similar got beans dependency: expected at least one bean that nested exception org.springframework.beans qualifies as autowire candidate for this dependence. Factory.NoSuchBeanDefinitionException is Dependency Annotation: {org.springframework.beans.factory.annotation.Autowired (required = true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues ​​(AutowiredAnnotationBeanPostProcessor.java, 200286) at org.springframework.beans . factory.support.AbstractAutowireCapableBeanFactory.populateBean org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties (AbstractAutowireCapableBeanFactory.java:374) to (AbstractAutowireCapableBeanFactory.java:1064) org.springframework.beans.factory.wiring.BeanConfigurerSupport.configureBean on ( org.springframework.beans.factory.aspectj.AbstractDependencyInjectionAspect.ajc $ afterReturning $ org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect $ 2 59 to $ 1ea6722c) (AbstractD: org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect.configureBean (BeanConfigurerSupport.java:140 on AnnotationBeanConfigurerAspect.aj ) EpendencyInjectionAspect.aj: 89) at za.co.acme.app.security.UserDetailsServiceImplIntegrationTest Sun.reflect.NativeConstructorAccessorImpl.newInstance0 (on the original method) at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java: 39) sun.reflect.DeligatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorIst.Java.2) on (UserDetailsServiceImplIntegrationTest.java:25) java.lang.reflect.Constructor.newInstance (Knstrctorkjawa / 1313) at org.junit.runners.BlockJUnit4ClassRunner.createTest (BlockJUnit4ClassRunner.java: 202) 

Bean definitely "lookup function called" , And it's the right type.

An alternative solution is to create a new single configuration file (let's call it "test-configuration.xml"). ) Which is both applicationContext.xml and applicationContext-security.xml. After this you can use these tests in your tests.

test-configuration.xml:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Bem xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schema location = "http: // Www .springframework.org / schema / beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> & Lt; Import Resources = "Classpath: /META-INF/spring/applicationContext.xml" / & gt; & Lt; Import Resources = "Classpath: /META-INF/spring/applicationContext-security.xml" /> & Lt; / Bean & gt; @ConfigurablePublic Category UserDetailsServiceImplIntegrationTest {...}  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -