Dait层在Junit类中未自动接线

时间:2019-07-24 05:52:09

标签: junit

运行Junit时,无法自动装配Dao层的问题: org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为“单位名称”的Bean

// AuditDaoImpl.Java

@Repository
public class AuditDaoImpl implements AuditDao {

    //** The eman. */
    @PersistenceContext(unitName = "unit-name")
    protected EntityManager eman;

}


// AuditServiceTest.java

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
public class AuditServiceTest {

        @Configuration
        static class ContextConfiguration {

        @Bean
        public AuditDao auditDao() {
            return new AuditDaoImpl();
        }
    }

     @Autowired
     public AuditDao auditDao;
}

0 个答案:

没有答案