私は春のブートアプリケーションの周りにいくつかの統合テストを記述しようとしています方法は
は、私はすべてのtest.Thisでアプリケーションを起動SpringJunitRunnerを使用したくないを終了すると、スプリングブートアプリケーションダイをしない方法私は多くのテストをしているので、テストごとに1回アプリケーションを開始したくないからです。また、私の会社のインフラストラクチャと統合されているいくつかのものがあり、2回目のテストはバネアプリケーションの起動中に失敗します(他のコンテキストは1回しか作成できないため)
TestNGを使用し、スイートの開始時に一度アプリケーションとテストがアプリケーションに対して実行し、その後、私は、アプリケーションを起動することができていますが、それはすぐにそれが出て起動方法の後に死ぬ
をアプリケーションをシャットダウンすることを確認します。私は、アプリケーションが
を生きることができます方法は、私が直面しています問題はrunApplication()メソッドが終了した後に、Springアプリケーションが死ぬということです
私は、アプリケーションのライフサイクルを管理するためにシングルトンクラスを作成しているpublic final class IntegrationTestContext {
private static IntegrationTestContext INSTANCE = null;
private Boolean isInitialized = false;
private ConfigurableApplicationContext applicationContext;
SpringApplication app = null;
public static synchronized IntegrationTestContext getInstance() {
if (INSTANCE == null){
INSTANCE = new IntegrationTestContext();
}
return INSTANCE;
}
private IntegrationTestContext() {
if (!isInitialized) {
runApplication();
isInitialized = true;
}
}
public ApplicationContext getContext() {
return applicationContext;
}
private PropertySourcesPlaceholderConfigurer getBeanFactoryPostProcessor(){
Properties properties = new Properties();
properties.setProperty("some.companyrelated.property.1", "false");
properties.setProperty("some.companyrelated.property.2", "false");
PropertySourcesPlaceholderConfigurer pph = new PropertySourcesPlaceholderConfigurer();
pph.setProperties(properties);
return pph;
}
/**
* This runs the application and sets the spring application context
* that we can query to get the client beans
*/
private void runApplication() {
try {
final String[] args = {};
app = new SpringApplication(Application.class, ClientConfig.class);
app.setBannerMode(Banner.Mode.OFF);
app.addInitializers(new MyCompanyInitializer());
applicationContext = app.run(args);
applicationContext.addBeanFactoryPostProcessor(getBeanFactoryPostProcessor());
applicationContext.refresh();
}
catch (Exception exception) {
}
}
public void shutDownApplication(){
try {
applicationContext.close();
isInitialized = false;
app = null;
INSTANCE = null;
}
catch (Exception e) {
}
}
}
あります。
これを行うには何ができますか?新しいプロセス作業でアプリケーションを開始しますか?
'System.exit(0);'メソッドを試してみてください。 – DimaSan
私はそれが終了しないようにしようとしている...私は文脈をリフレッシュしないと死に至ることが分かった – SK176H