【发布时间】:2017-03-13 11:03:29
【问题描述】:
我正在启动一个 Spring Boot Rest 服务,该服务可能会根据发行版加载不同的包。这意味着有时分发会包含某些 REST 控制器所在的 jar,有时这些控制器不存在。
那么我如何能够告诉 spring-boot 在哪里可以找到带有配置文件的控制器。现在我通过注释发送此信息,迫使我为每个发行版创建一个“主要”。我想定义一个唯一的 main 来导入文件中定义的控制器。换句话说,我想手动访问@Importannotation,如下图所示:
@Configuration
@PropertySource("conf.cfg")
@Import(value = {RestContorller1.class, RestContorller2.class})
@EnableAutoConfiguration
@ConfigurationProperties
@SpringBootApplication
@RestController
@EnableSwagger2
public class Application {
public static void main(String[] args) {
String confFile = Const.DEFAULT_CONFIGURATION_FILE;
if(args.length>0)
confFile= args[0];
System.setProperty("spring.config.name",confFile);
Boolean hasStarted = DataProcessingCore.start(confFile);
if(hasStarted) {
SpringApplication springApp = new SpringApplication(Application.class);
try {
springApp.setDefaultProperties(Utils.createPropertyFiles(confFile));
} catch (IOException e) {
e.printStackTrace();
}
springApp.addInitializers();
springApp.run(args);
}
}
}
【问题讨论】:
标签: java spring rest spring-boot