启动程序时无法申请到足够的内存,会出现以下错误
物理机无法提供足够的内存,可以减少申请的内存或者关闭一些非必要的程序。或已经启动的一个程序(大内存)。
使用错误的包
情况一:
1. 使用这个包执行也会成功,但是JUnit Vintage会报错import org.junit.Test;)
2. springboot所在的包与srpingbootTest所在包不同也会出现以下错误
情况二:
正确的示范
pom
## springboot父工程推荐2.7.3以上
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
代码
package com.yuanda.erp9.syn;
import com.yuanda.erp9.syn.config.RestClientConfig;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@SpringBootTest(classes = SynApplication.class)
@RunWith(value = SpringRunner.class)
public class ESTest {
@Resource
private RestClientConfig restClientConfig;
@Test
public void test() {
AtomicInteger i = new AtomicInteger(1);
List<RestClientConfig> list = new ArrayList<>();
Thread thread = new Thread(() -> {
while (i.getAndIncrement() <= 20000) {
RestHighLevelClient restHighLevelClient = restClientConfig.restHighLevelClient();
try {
System.out.println("第" + i+ "次"+restHighLevelClient.toString());
Thread.sleep(50);
// restHighLevelClient.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}