运行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;
}