@SpringApplicationContext("test-applicationContext.xml")
@DataSet
public class MyServiceTest extends UnitilsJUnit4 {
@SpringBeanByName
private MyService myService;
...
@Test
public void testFoo() {
myService.foo(...)
...
This test works on Eclipse and on Maven (mvn test).
But the test fails on Sonar :-( I do not understand why…
Here is the error msg :
Unable to create application context for locations [test-applicationContext.xml]
org.unitils.core.UnitilsException: Unable to create application context for locations [test-applicationContext.xml]
at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:121)
at org.unitils.spring.util.ApplicationContextManager.createInstanceForValues(ApplicationContextManager.java:36)
at org.unitils.core.util.AnnotatedInstanceManager.getInstanceImpl(AnnotatedInstanceManager.java:234)
at org.unitils.core.util.AnnotatedInstanceManager.getInstance(AnnotatedInstanceManager.java:121)
at org.unitils.spring.util.ApplicationContextManager.getApplicationContext(ApplicationContextManager.java:65)
at org.unitils.spring.SpringModule.getApplicationContext(SpringModule.java:235)
at org.unitils.spring.SpringModule$1.isApplicableFor(SpringModule.java:108)
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.foo.MyService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:924)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:793)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
Please help…
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Probably your wiring goes wrong.
->Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching …
This is the real cause of the exception
So check the classpath and the compontent scanning
My best gues is a classpath issue. If you would write the test the "old fashion" way (create the application context yourself) you will see that you get the same exception.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So probably a classpath issue when running on the sonar, not all your libraries are correctly loaded.
You'll need to search in that direction. Put op some extra debug info and check what jar's are loaded when running the tests.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
public class NotAutowiredTest {
@Test
public void testOldFashionBeanFetching() {
final ApplicationContext context = new ClassPathXmlApplicationContext("/test-applicationContext.xml");
final UserService localUserService = (UserService) context.getBean("userService");
System.out.println(localUserService);
Assert.assertNotNull(localUserService);
}
}
It works on Eclipse/Maven but still not on Sonar :
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2015-04-30
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Controller': Injection of autowired dependencies failed; nested exception is
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2015-04-30
could anybody help me.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
Using Java 6, Unitils 3.3, I wrote a test :
This test works on Eclipse and on Maven (mvn test).
But the test fails on Sonar :-( I do not understand why…
Here is the error msg :
Please help…
Probably your wiring goes wrong.
->Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching …
This is the real cause of the exception
So check the classpath and the compontent scanning
My best gues is a classpath issue. If you would write the test the "old fashion" way (create the application context yourself) you will see that you get the same exception.
But it works on Eclipse and on Maven…
What do you mean by old fashion ? I allready use the test-applicationContext.xml…
But it might be not enough
when you add a normal Junit test, without unitils/default Junit Runner
something like this :
@Test
public void oldFashionBeanFetchingTest(){
ApplicationContext context = new ClassPathXmlApplicationContext("test-ApplicationContext.xml");
MyService myService = (MyService) mycontext.getBean("myServiceId");
Assert.assertNotNull(myService);
}
You will probably get the same error.
Hello,
I've tried something else. It might help. It works on Eclipse and Maven (command line) but not on Sonar :-(
Also works on Eclipse/Maven but not on Sonar with just that :
So probably a classpath issue when running on the sonar, not all your libraries are correctly loaded.
You'll need to search in that direction. Put op some extra debug info and check what jar's are loaded when running the tests.
So, I just tested your proposal :
It works on Eclipse/Maven but still not on Sonar :
By the way, my services are :
For future readers having the same problem a solution :-)
I had the same problem until a colleague came with a solution, instead of defining a controller that I wanted to be autowired for testing as
<bean id="administrationController" class="<domain>.web.controller.AdministrationController" />
define it as
<bean id="administrationController" class="<domain>.web.controller.AdministrationController" >
<aop:scoped-proxy proxy-target-class="true"/>
</bean>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Controller': Injection of autowired dependencies failed; nested exception is
could anybody help me.