繁体   English   中英

在springboot中加载多个带有注释的springboot应用程序

[英]load multiple springboot app with annotation in springboot

我有一个 springboot 应用程序,可以根据用户输入动态加载不同的类。

有人可以建议任何更好和优化的方法来做到这一点。

以下是我的方法:-

//I have a map of actions available with their respective classes(which is also a springboot app)
private static Map<String,Class> actions = ImmutableMap.<String,Class>builder()
                                                       .put("A",A.class),
                                                       .put("B",B.class);

//main method of springboot root app
public static void main(String args[]){
 new MainApplication().run(args);
}

//get the action class and run that application
public void run(String args){
 Class action = getAction();
 SpringApplication app = new SpringApplicationBuilder(job).build();
 app.run(args);
}

//action.name is passed as an argument while starting the application( for.ex action.name="A")
private Class getAction(){
 String action = System.getProperty("action.name");
 Class classType = actionMap.get(action);
 return classType;
}

现在我只想用注释加载这些动作应用程序。 有人可以建议任何方法来做同样的事情。

使用条件 Bean 概念如下

@Service
@ConditionalOnProperty(
        value="action.name", 
        havingValue = "a", 
        matchIfMissing = false)
public class TestBeanConditional {

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM