在java文件夾下面創建EsTest.java @RunWith(SpringRunner.class) @SpringBootTest public class EsTest { @Autowired ElasticsearchTemplate template; @Test public void createTemple() { //創建索引 template.createIndex(Item.class); //創建映射 template.putMapping(Item.class); } }
常見問題解決
@RunWith爆紅 maven中junit.runner.RunWith無法導入問題
去掉<scope>test</scope>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
Caused by: java.lang.IllegalStateException: SpringJUnit4ClassRunner requires JUnit 4.12 or higher.
at org.springframework.util.Assert.state(Assert.java:73)
說明版本過低最低使用用4.12,但springboot v2.0.4.RELEASE 版本使用4.12 @RunWith仍然爆紅 使用4.13版本即可