zoukankan      html  css  js  c++  java
  • SpringBoot之使用外部的启动类

    公司内部统一包装了启动类,TradeBootStrap

    @EnableLionConfig
    @SpringBootApplication(
        excludeName = {"${exclude.auto-configuration.name}"},
        scanBasePackages = {"${scan.basePkg.path}", "com.ymm.trade", "com.ymm.architecture.*", "com.ymm.unify.authorization.*", "com.ymm.framework.healthcheck.client.*"}
    )
    @ServletComponentScan
    @PropertySource(
        value = {"classpath:default.properties", "classpath:application.properties"},
        factory = TradePropertySourceFactory.class
    )
    @ImportResource(
        locations = {"${custom.resource.import:classpath*:spring/spring-*.xml}", "classpath*:authorization/pigeon-service.xml"},
        reader = TradeImportResourceReader.class
    )
    public class TradeBootStrap {
        private static final BusinessLogger LOGGER = TLoggerFactory.getBusinessLogger(TradeBootStrap.class);
    
        public TradeBootStrap() {
        }
    
        public static void main(String[] args) {
            long startTime = System.currentTimeMillis();
            boolean var10 = false;
    
            long endTime;
            label50: {
                try {
                    var10 = true;
                    LOGGER.warn(BusinessLogSchema.of().message("TradeBootStrap start at = {}", new Object[]{DateFormats.DATE_TIME.format(startTime)}));
                    checkSwimlane();
                    SpringApplication springApplication = new SpringApplication(new Class[]{TradeBootStrap.class});
                    springApplication.addListeners(new ApplicationListener[]{new ApplicationPidFileWriter()});
                    springApplication.run(args);
                    var10 = false;
                    break label50;
                } catch (Throwable var11) {
                    LOGGER.error(BusinessLogSchema.of().errorCode(ErrorCode.code("INNER_BOOTSTRAP_001", new Object[0])).exception(var11));
                    var10 = false;
                } finally {
                    if (var10) {
                        long endTime = System.currentTimeMillis();
                        BusinessLogSchema.of().message("TradeBootStrap end at = {}, Cost = {}", new Object[]{DateFormats.DATE_TIME.format(startTime), endTime - startTime + "ms"});
                    }
                }
    
                endTime = System.currentTimeMillis();
                BusinessLogSchema.of().message("TradeBootStrap end at = {}, Cost = {}", new Object[]{DateFormats.DATE_TIME.format(startTime), endTime - startTime + "ms"});
                return;
            }
    
            endTime = System.currentTimeMillis();
            BusinessLogSchema.of().message("TradeBootStrap end at = {}, Cost = {}", new Object[]{DateFormats.DATE_TIME.format(startTime), endTime - startTime + "ms"});
        }

      之前一直没注意到这个注解 @SpringBootApplication

      其实他包含了 @EnableAutoConfiguration

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Inherited
    @SpringBootConfiguration
    @EnableAutoConfiguration
    @ComponentScan(excludeFilters = {
            @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
            @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
    public @interface SpringBootApplication {

      公司里每个应用要本地启动的话,要在idea里这么配置

      

  • 相关阅读:
    P2114 [NOI2014]起床困难综合症(二进制)
    P4577 [FJOI2018]领导集团问题
    P5290 [十二省联考2019]春节十二响(堆+启发式合并)
    P2048 [NOI2010]超级钢琴(RMQ+堆+贪心)
    P4890 Never·island(dp)
    P2617 Dynamic Rankings(树状数组套主席树)
    P5241 序列(滚动数组+前缀和优化dp)
    P3243 [HNOI2015]菜肴制作(拓扑排序)
    【LeetCode每天一题】Combination Sum II(组合和II)
    【LeetCode每天一题】Combination Sum(组合和)
  • 原文地址:https://www.cnblogs.com/juniorMa/p/15131309.html
Copyright © 2011-2022 走看看