テストインタフェースで問題が発生

3598 ワード

1エラーjava.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
イニシエータを加える
import lombok.extern.slf4j.Slf4j;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.concurrent.CountDownLatch;
@SpringBootApplication
//@ComponentScan(value={"test.test.test","com.test.test"})ComponentScan注記関数/@MapperScan(basePackages={"com.test.test"})MapperScan注記関数@Slf 4 jpublic class ServiceBootstrap{
public static void main(String[]args)throws Exception{SpringApplicationアプリケーション=new SpringApplication(ServiceBootstrap.class);アプリケーション.run(args);log.info(「起動成功!」final CountDownLatch cdl = new CountDownLatch(1); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { cdl.countDown(); } }); cdl.await(); }}
 
2出会い
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
注入されたクラスには実装されていないインタフェースがあり、@Autowired(required=false)で実装されていないインタフェースを省略できます.
 
3 Null PointerExceptionの問題に遭遇した場合@RunWith(SpringRunner.class)を追加する必要があります.
java.lang.NullPointerException at com.zebra.carcloud.minioperationsrd.service.api.impl.**** at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
 
Spring自動注釈のDAOはインタフェースであり、具体的な実装はなく、テスト呼び出し時に起動プログラムに詳細なmapとcomponentscanを追加する必要がある.
@MapperScan(basePackages = {"com.test.mapper"})
@ComponentScan(basePackages = {"com.test1.common", "com.test2.service", "com.test3.message"})


4新しいプロジェクトを開くと、Error:java:java.lang.ExceptionInInitializerError
JDKバージョンが一致せず、1.8バージョンに変更すると