您可以添加@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
到您的代码在这里。
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class BaseTestService {
......
}
神奇的是这里的代码,你的情况,如果条件符合,所以将与在线的init性能。
org.springframework.boot.test.context.SpringBootContextLoader#getInlinedProperties
protected String[] getInlinedProperties(MergedContextConfiguration config) {
ArrayList<String> properties = new ArrayList<String>();
// JMX bean names will clash if the same bean is used in multiple contexts
disableJmx(properties);
properties.addAll(Arrays.asList(config.getPropertySourceProperties()));
if (!isEmbeddedWebEnvironment(config) && !hasCustomServerPort(properties)) {
properties.add("server.port=-1");
}
return properties.toArray(new String[properties.size()]);
}
请说明您的具体问题或添加额外的细节,突显正是你需要的。正如目前所写,很难确切地说出你在问什么。请参阅如何问问页面以获取帮助以澄清此问题。 –