reset password
Author Message
afetiso
Posts: 84
Posted 20:36 Jul 11, 2015 |

I have mistake when I am trying run testNG:

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

Maybe you can help me to point how to fix it?

It is just one test code for testing: There are a total of two job positions in the system.

it is similar to UserDaoTest, so I think it is ok that I am add it here

@Test(groups = "PositionDaoTest")
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class PositionDaoTest extends AbstractTransactionalTestNGSpringContextTests {

    @Autowired
    PositionDao positionDao;
    
    // There are a total of two job positions in the system
    @Test
    public void getPositions()
    {
        assert positionDao.getPositions().size() == 2;
    }
    

cysun
Posts: 2935
Posted 22:59 Jul 11, 2015 |

The error message says: No qualifying bean of type [csjobs.model.dao.PositionDao] found for dependency

So check if @Repository is there in PositionDaoImpl, and also make sure there's something like <context:component-scan base-package="csjobs.model" /> in applicationContext.xml.

These things should become clear after the Spring lectures next week.