Java 多个SpringBoot应用,只想运行一个
我目前正在使用SpringBootApplications,我有两个不同的@SpringBootApplication,一个用于Web应用程序,另一个用于CommandLineRunner 问题是,无论我执行哪一个,它都会尝试运行这两个应用程序Java 多个SpringBoot应用,只想运行一个,java,spring,spring-boot,Java,Spring,Spring Boot,我目前正在使用SpringBootApplications,我有两个不同的@SpringBootApplication,一个用于Web应用程序,另一个用于CommandLineRunner 问题是,无论我执行哪一个,它都会尝试运行这两个应用程序 package com.ws; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoCon
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应用程序。我需要能够分别运行它们。但我不知道如何配置它 谢谢 春季医生说:
因此,实际上您添加了2个EnableAutoConfiguration注释,这是spring boot所不允许的。我建议使用spring概要文件来实现您所需的功能。请将包包含到主类源中。您是否在使用maven构建代码?