2016-11-30 72 views
1

的同事,我有主類,它看起來像:如何上傳不同的上下文配置類?

public class App { 

    static final Logger LOG = Logger.getLogger(App.class.getName()); 

    public static void main(String[] args) { 


     for(int i = 0; i < args.length; i++) { 



      switch (args[i]) { 
       case "OrderUpload": 
        ApplicationContext ctxOrderUpload = new AnnotationConfigApplicationContext(AppConfigBasic.class); 
        OrderUpload OrderUpload = ctxOrderUpload.getBean(OrderUpload.class); 
        OrderUpload.process(); 
        break; 
       case "TrdUpload": 
        ApplicationContext ctxTrdUpload = new AnnotationConfigApplicationContext(AppConfig.class); 
        TrdUpload TrdUpload = ctxTrdUpload.getBean(TrdUpload.class); 
        TrdUpload.process(); 
        break; 
       default: 
        LOG.info("Process is not defined - > " + args[i]); 
        System.exit(0); 
      } 

     } 
} 

而且我有兩個配置類:

@Configuration 
@EnableTransactionManagement 
@ComponentScan 

public class AppConfigBasic {} 

和擴展配置

@Configuration 
@EnableTransactionManagement 
@ComponentScan 

public class AppConfig extends AppConfigBasic {} 

爲什麼當執行java -jar app.jar OrderUpload彈簧負載豆來自AppConfig(不僅來自AppConfigBasic`)? 如何在交換機中爲不同情況使用不同的上下文配置文件? 謝謝。

回答

1

由於您的@ComponentScanAppConfigBasic - 它應該包括您的AppConfig(不要忘記@ComponentScan也掃描@Configuration豆)。

更具體的在您的@ComponentScan不包括您的AppConfig或替代(可能最好)的包裝使用@ComponentScanexcludeFilters functionality

相關問題