最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring?boot應用無法啟動也沒報錯信息的解決辦法

 更新時間:2025年11月05日 10:08:11   作者:常樂_smile  
在使用Spring Boot開發(fā)應用程序時,偶爾會遇到啟動不起來的問題,這是一種讓人沮喪的情況,尤其是當日志中沒有任何錯誤信息時,這篇文章主要介紹了spring?boot應用無法啟動也沒報錯信息的解決辦法,需要的朋友可以參考下

問題描述

springboot應用昨天還能正常好好啟動,忽然之間就啟動不了了,也不報任何錯誤,只見到控制臺輸出"Stopping service".這個問題已經連續(xù)出現過3次了,這次狠下決心要找出個所以然。

在此,先說下個人經歷的前面三次無法啟動沒有報錯。

舉例說明

第一次:和環(huán)境有關

當某個中間件無法連接的時候,我們的同事在try catch中錯誤的使用了System.exit()導致異常;

try{
  ……
}catch(Exception e){
  System.exit();
  log.error(e)
}

第二次:和jar包沖突有關

當時項目中用到了hbase,需要集成hbase,所以引入了hbase-client 2.1.0 版本,但是該包對curator包版本有要求,導致和其他組件的curator版本沖突,最終程序輸出的信息中,只有幾行INFO日志。

2019-09-12 10:39:30.350  INFO 37343 --- [5311@0x040943a6] org.apache.zookeeper.ZooKeeper           : Session: 0x16b72a291d73e73 closed
2019-09-12 10:39:30.351  INFO 37343 --- [3a6-EventThread] org.apache.zookeeper.ClientCnxn          : EventThread shut down for session: 0x16b72a291d73e73
2019-09-12 10:39:30.566  INFO 37343 --- [tor-Framework-0] o.a.c.f.imps.CuratorFrameworkImpl        : backgroundOperationsLoop exiting

最終通過jar包沖突,不斷試錯,不斷對比和其他能正常啟動應用的依賴,才解決沖突。

第三次:和代碼編寫有關

也就是剛剛發(fā)生的,讓筆者決定狠下心挖掘"無報錯信息"的罪魁禍首。一定是有異常的,只是不知道在哪個環(huán)節(jié)丟失了。

先說結論:本次"無緣無故"無法啟動的原因,其實是昨天筆者開發(fā)過程中,代碼中添加了一個dubbo服務依賴,但是沒有在dubbo xml文件中注冊reference,所以導致依賴缺失,最終應用起不來。

當然,和前面幾次一樣,控制臺,日志文件,沒有任何地方有錯誤信息輸出。

排查分析

根據下面這篇文章,給出了提示。

引用:SpringBoot啟動項目后自動關閉: https://blog.csdn.net/laoxilaoxi_/article/details/83654186

先說結論:不是沒有輸出異常,是新版本的Spring boot 在出錯后,不再輸出錯誤到控制臺了,而是將異常在Application main方法中拋出。

劃重點:新版本Spring boot 2.x 不再輸出錯誤到日志中,將異常在Application main方法中拋出。 而低版本Spring boot 1.3.x,1.4.x版本,是會直接在控制臺輸出錯誤的。

解決方法

**解決:**有了上面的靈感,那好辦我在main 啟動方法中捕捉,自己打印,不就能看出來錯誤原因了嗎?

事實上,確實應該如此。

最后,筆者在main方法啟動spring boot 時,進行一場捕捉并輸出日志。然后錯誤就一目了然了。

@Slf4j
@ImportResource("classpath*:spring-*.xml")
@SpringBootApplication
public class SupportApplication {
    public static void main(String[] args) {
        try {
            SpringApplication.run(SupportApplication.class, args);
            System.out.println("Server startup done.");
        }catch (Exception e){
            log.error("服務xxx-support啟動報錯", e);
        }
    }
}

最終在控制臺輸出久違的異常信息:

2019-09-12 11:18:18.799 ERROR 38420 --- [           main] c.c.xxx.support.xxxSupportApplication    : 服務xxx-support啟動報錯

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxxCoreService': Unsatisfied dependency expressed through field 'xxxSpotService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.test.xxx.api.service.XxxSpotService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.0.10.RELEASE.jar:5.0.10

擴展驗證

接下來讓我們驗證下低版本Spring boot 1.3.x,1.4.x版本,是否會直接在控制臺輸出錯誤。

下面的實驗是基于spring boot 1.4.7版本進行的,低版本的spring boot 都會在控制臺或日志文件中先輸出錯誤信息,再退出啟動main方法。所以,對于從低版本升到高版本的,請在main啟動時,自行捕捉異常。

@Controller
@RequestMapping("/test")
public class TestErrorController {
  /**
   * 1.制造一個不存在的Spring bean;
   * 2.并對其進行依賴;
   * 3.啟動應用XxxApplication;
   * 4.控制臺有明顯報錯信息輸出;
   * 2019-09-12 10:44:38.014 INFO 37477 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
   * 2019-09-12 10:44:38.026 INFO 37477 --- [ main] utoConfigurationReportLoggingInitializer :
   *
   * <p>Error starting ApplicationContext. To display the auto-configuration report re-run your
   * application with 'debug' enabled. 2019-09-12 10:44:38.155 ERROR 37477 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
   * <p>*************************** APPLICATION FAILED TO START ***************************
   * <p>Description:
   * <p>A component required a bean of type
   * 'cn.test.lee.service.TestErrorService' that could not be found.
   * <p>Action:
   * <p>Consider defining a bean of type 'cn.test.service.TestErrorService'
   * in your configuration.
   * <p>Disconnected from the target VM, address: '127.0.0.1:57403', transport: 'socket'
   * <p>Process finished with exit code 1
   */
    @Resource 
    private TestErrorService testErrorService;

    public String testError(){
        testErrorService.testError();
        return "啟動就報錯了!";
    }
}

總結 

到此這篇關于spring boot應用無法啟動也沒報錯信息解決辦法的文章就介紹到這了,更多相關spring boot應用無法啟動沒報錯信息內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

长春市| 秦皇岛市| 宁化县| 松滋市| 武定县| 张家口市| 特克斯县| 梓潼县| 三穗县| 沧州市| 西宁市| 改则县| 成都市| 桂平市| 卫辉市| 西乌珠穆沁旗| 康乐县| 昭觉县| 海盐县| 凤城市| 成安县| 兴义市| 遂昌县| 扎赉特旗| 西藏| 丹寨县| 喀喇沁旗| 伊宁县| 柳林县| 高陵县| 额济纳旗| 察隅县| 九台市| 汶川县| 肃北| 湖口县| 兴文县| 镇原县| 科技| 杭州市| 浏阳市|