[英]load multiple springboot app with annotation in springboot
I am having a springboot application to load different classes dynamically based on the user input.我有一个 springboot 应用程序,可以根据用户输入动态加载不同的类。
Can someone suggest any better and optimised way for doing this.有人可以建议任何更好和优化的方法来做到这一点。
Below is my approach:-以下是我的方法:-
//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;
}
Now I want to load these action applications with just an annotation.现在我只想用注释加载这些动作应用程序。 Can someone suggest any way to do the same.
有人可以建议任何方法来做同样的事情。
Use conditional Bean concept as below使用条件 Bean 概念如下
@Service
@ConditionalOnProperty(
value="action.name",
havingValue = "a",
matchIfMissing = false)
public class TestBeanConditional {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.