我是编程世界的新手,所以我说的可能看起来很傻.
我试图在Eclipse下运行一个Spring-boot测试作为JUnit,但我无法弄清楚如何使用spring-boot注释...我已经阅读了几个指南并浏览了这个网站,但没有发现任何解决的问题我的问题.
我正在尝试运行下面的JUnit测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={CBusiness.class,CService.class,CDao.class}, loader = AnnotationConfigContextLoader.class)
@SpringBootTest
public class CalculTest {
@Autowired
CBusiness business;
@Test
public void testCalcul() throws TechnicalException {
Object object= new Object();
object.setId1("00");
object.setId2("01");
object.setNombrePlacesMaximum(new BigInteger("50"));
Long result=business.calcul(object);
assertTrue(result>0);
}
Run Code Online (Sandbox Code Playgroud)
将其作为JUnit测试运行会给出以下异常:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cDao': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManagerFactory' available
Run Code Online (Sandbox Code Playgroud)
来自CDao类的EntityManager参数有@PersistenceContext注释,我认为这意味着它是由Hibernate自动生成的,但显然它不是......我怎样才能仅使用java代码实现EntityManager?我没有任何.xml或.properties文件......
仅供参考,这是测试所调用的类:
业务层:
@Component("cBusiness")
public class CBusiness {
@Autowired
CService cService;
public long calcul(Object …Run Code Online (Sandbox Code Playgroud)