現在SpringBootApplicationsで作業しています.2つの異なる@SpringBootApplication、1つはWebアプリケーション、もう1つはCommandLineRunnerです。複数のSpringBootアプリ、1つだけを実行したい
問題は、どちらのアプリケーションを実行しても、両方のアプリケーションを実行しようとすることです。
package com.ws;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Configuration;
@EnableAutoConfiguration
public class Init extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Init.class);
}
/**
* Main method.
*
* @param args String[].
* @throws Exception Exception.
*/
public static void main(String[] args) throws Exception {
SpringApplication.run(Init.class, args);
}
そして、これは私の他のInitBatch.javaです:
package com.batch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class InitBatch implements CommandLineRunner {
@Autowired
private Batch batch;
@Override
public void run(String... args) throws Exception {
batch.processFiles();
}
public static void main(String[] args) throws Exception {
SpringApplication.run(InitBatch.class, args);
}
}
、それが実行された後、私は、CommandLineRunnerアプリを実行する場合は、Webアプリケーションをロードし続けています。
それぞれを個別に実行する必要があります。しかし、私はこれを設定する方法を知らない。
ありがとうございます!
メインクラスのソースにパッケージを含めてください。 – luboskrnac
[実行可能なjarにどのメインクラスを使用するかSpring Bootに指示するにはどうすればよいですか?](http://stackoverflow.com/questions/23217002/how-do-i-tell-spring-boot-which-main -class-to-the-executable-jar) –
コードをビルドするためにmavenを使用していますか? – Jobin