在不使用Spring Boot的测试中进行DI(@SpringBootTest)

时间:2019-05-23 13:34:32

标签: spring

从Spring Boot切换回“正常” Spring,因为该应用程序仅使用一些jdbc代码来“更新”到Postgresql数据库中。

1)
    尝试用以下方法注释测试类:

@RunWith(SpringJUnit4ClassRunner.class)
public class DBIntegration {

results in:
java.lang.IllegalStateException: Failed to load ApplicationContext

2)
   尝试通过以下方式为课程添加注释:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {})
public class DBIntegration {

[main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [de.mydomain.myproject.DBIntegration]: no resource found for suffixes {-context.xml}.

No exceptions, but java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=insertDataFrom_sometest], 

3)尝试通过以下方式注释该类:

@Component
public class DBIntegration {

dependency injection does not work in this case, the expected service
(to be injected) throws a nullpointerexception

0 个答案:

没有答案