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里这么配置

  

原文地址:https://www.cnblogs.com/juniorMa/p/15131309.html