簡體   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