MENU

Spring Boot中health报错问题

October 12, 2017 • Read: 150 • 无码

今天部署了一个最简单的Spring Boot项目,但是curl localhost:9090/health一直报500;报错信息显示是rabbitmq相关的错误,但是项目中根本没有用到rabbitmq。

{
    "timestamp": 1507777390848,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "java.lang.NoSuchMethodError",
    "message": "com.rabbitmq.client.ConnectionFactory.newConnection(Ljava/util/concurrent/ExecutorService;[Lcom/rabbitmq/client/Address;Ljava/lang/String;)Lcom/rabbitmq/client/Connection;",
    "path": "/health"
}

NoSuchMethodError错误感觉是缺少依赖包;这就奇怪了,明明没用到rabbitmq啊。还是从maven依赖入手,查看关于rabbitmq的依赖mvn dependency:tree | grep rabbitmq

[INFO] |  +- com.rabbitmq:amqp-client:jar:3.5.7:compile
[INFO] |  |  +- com.rabbitmq:http-client:jar:1.1.1.RELEASE:compile

果然是存在rabbitmq的相关依赖,是在依赖另一个时导致间接依赖的;猜测问题是Spring Boot强大的自动配置引起的,排除这两个依赖:

<exclusions>
    <exclusion>
        <groupId>com.rabbitmq</groupId>
        <artifactId>amqp-client</artifactId>
    </exclusion>
    <exclusion>
        <groupId>org.springframework.amqp</groupId>
        <artifactId>spring-rabbit</artifactId>
    </exclusion>
</exclusions>

再次访问health,一切正常了;哈哈,确实是最简单的项目,什么都没有。

{
    "status": "UP",
    "diskSpace": {
        "status": "UP",
        "total": 120473067520,
        "free": 21131587584,
        "threshold": 10485760
    }
}
Archives QR Code
QR Code for this page
Tipping QR Code