reset password
Author Message
ajoshi5
Posts: 7
Posted 20:11 Feb 01, 2016 |

Hello ,

When i m trying to run test cases , it skips all the time and getting configuration failures error as shown as bellow . Awaiting for some favorable and prompt response.

...

...

....

.....

.....
 

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: gapp.web.model.dao.UserDao gapp.model.dao.UserDaoTest.userDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [gapp.web.model.dao.UserDao] 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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 30 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [gapp.web.model.dao.UserDao] 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:1301)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ... 32 more

FAILED CONFIGURATION: @BeforeClass springTestContextPrepareTestInstance
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gapp.model.dao.UserDaoTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: gapp.web.model.dao.UserDao gapp.model.dao.UserDaoTest.userDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [gapp.web.model.dao.UserDao] 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)}

 

...

...

...

 

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: gapp.web.model.dao.UserDao gapp.model.dao.UserDaoTest.userDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [gapp.web.model.dao.UserDao] 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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 30 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [gapp.web.model.dao.UserDao] 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:1301)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
    ... 32 more

SKIPPED CONFIGURATION: @BeforeMethod springTestContextBeforeTestMethod
SKIPPED: checkStudentApplication

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

 

 

 

 

ajoshi6
Posts: 46
Posted 20:14 Feb 01, 2016 |

it seems that Spring can't find bean to be injected.

check if that related bean is present or not.

@Autowired exception it is

ajoshi5
Posts: 7
Posted 20:16 Feb 01, 2016 |

yea of course have seen @Autowired exception in the given error para, and looked for the solution on google as well but every dependency has been checked and is exist even tho it keeps coming .

SavinSachdev
Posts: 3
Posted 21:05 Feb 01, 2016 |
I think u r forgetting @Repository annotation in the Dao implementation classes
ajoshi5
Posts: 7
Posted 21:07 Feb 01, 2016 |

@SAVIN , Thanks for your reply .I Got the same solution on stackoverflow :) and double checked all dao-s and daoimpl-s but all those annotations (specially @repository) are OK . :/

anto004
Posts: 4
Posted 21:38 Feb 01, 2016 |

Try adding a base-package in your applicationContext.xml

eg:

<context:component-scan base-package="hw3.model" />

 

Last edited by anto004 at 21:39 Feb 01, 2016.
ajoshi5
Posts: 7
Posted 21:41 Feb 01, 2016 |

@ANT , thanks as well .

But i already have config and scan with base-package in context tabs as bellow :

<context:annotation-config />

    <tx:annotation-driven />

    <context:component-scan base-package="modelname" />
in my XML :(

cysun
Posts: 2935
Posted 21:53 Feb 01, 2016 |

Assuming everything else is correct, it may be because you have two <component-scan> (one in gapp-servlet.xml and one in applicationContext.xml) that scan overlapping packages.

Move your model package out of gapp.web to gapp.model. The <component-scan> in gapp-servlet.xml should scan gapp.web and the one in applicationContext.xml should scan gapp.model.

ajoshi5
Posts: 7
Posted 07:00 Feb 02, 2016 |
cysun wrote:

Assuming everything else is correct, it may be because you have two <component-scan> (one in gapp-servlet.xml and one in applicationContext.xml) that scan overlapping packages.

Move your model package out of gapp.web to gapp.model. The <component-scan> in gapp-servlet.xml should scan gapp.web and the one in applicationContext.xml should scan gapp.model.

Thank You professor . You are right about  two <component-scan> But I have already checked it on the same time and both XML-s are scanning two different models as shown in attachments .

cysun
Posts: 2935
Posted 11:30 Feb 02, 2016 |

The error message says "Could not autowire field: gapp.web.model.dao.UserDao gapp.model.dao.UserDaoTest.userDao ..." which shows that your UserDao is under the web package. The test cases only uses applicationContext.xml, i.e. the <component-scan> in gapp-servlet.xml is not run so the bean was not created. Move it to gapp.model should fix the problem.