SpringBoot啟動后直接退出Process finished with exit code 1


問題描述

出現這個問題時,控制台沒有任何輸出,進程直接退出Process finished with exit code 1

問題解決

嘗試加了一行打印語句
System.out.println("SpringBoot Start....");

結果是可以打印出來的:

SpringBoot Start....
Process finished with exit code 1

此時突然想到,那程序入口沒問題,就是下一行的問題了。

try {
  SpringApplication.run(Application.class, args);
}catch(Exception e) {
  e.printStackTrace();
}

結果是依然沒有任何輸出。但是作為踩坑無數的Java程序員,我們知道Exception還不是最頂級的異常類,於是換成Throwable

try {
  SpringApplication.run(Application.class, args);
}catch(Throwable e) {
  e.printStackTrace();
}

啟動SpringBoot項目的時候控制台輸出的log如下:

Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

Spring boot集成swagger3出現錯誤:

原因: 這是因為Springfox使用的路徑匹配是基於AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher。
解決:

1、在application.properties里配置:spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
2、在SwaggerConfig添加以下bean

    @Bean
    public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
        List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
        Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
        allEndpoints.addAll(webEndpoints);
        allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
        allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
        String basePath = webEndpointProperties.getBasePath();
        EndpointMapping endpointMapping = new EndpointMapping(basePath);
        boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
        return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
    }
    private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
        return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM