ERROR org.springframework.boot.SpringApplication - Application run failed

背景:

升级了 spring boot 版本,从1.x 升级到了2.x

报错如下:

ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:157)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:98)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:64)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:137)
 

寻找原因:

1. 一开始查了下源码,发现自己并看不懂

2.还是老老实实排查jar 包吧,项目中引入了 spring-cloud-starter-feign, 这个 jar 里引入了 spring-cloud 的东西。spring-cloud 和 spring-boot 版本冲突

解决过程:

1.引入 spring-cloud 依赖

<dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

 2.替换 spring-cloud-starter-feign 为 spring-cloud-starter-openfeign

3. 重新启动报错:

ERROR o.s.boot.SpringApplication - Application run failed 
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)

仔细查看了一下 错误日志发现

ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization. 
java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useUnicode=true&amp;characterEncoding=utf-8'.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:79)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:131)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)

看到这里明白了,是 数据源链接配置的问题。

因为:升级了 springboot 版本,mysql 驱动版本也升级了,不支持 jdbc:mysql://localhost:3306/customer?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8。改成 jdbc:mysql://192.168.1.204:3306/customer?autoReconnect=true&useUnicode=true&characterEncoding=utf-8 启动成功

这个错误信息表明在启动应用程序时遇到了问题。具体来说,应用程序无法启动嵌入式的Tomcat服务器,导致应用程序无法正常运行。 要解决这个问题,可以尝试以下几个步骤: 1. 检查端口是否被占用:确保Tomcat要使用的端口没有被其他进程占用。可以尝试更改应用程序使用的端口,或者停止占用该端口的进程。 2. 检查依赖和配置:确保应用程序的依赖项正确配置,并且Tomcat的相关配置正确设置。检查应用程序的pom.xml或build.gradle文件,确保Tomcat依赖项正确添加,并且版本与应用程序兼容。另外,检查应用程序的配置文件,确保Tomcat的配置正确设置。 3. 检查Tomcat版本兼容性:确保所使用的Tomcat版本与应用程序兼容。如果使用的是较新的Tomcat版本,请尝试降低Tomcat版本或更新应用程序以适应较新的Tomcat版本。 4. 检查日志文件:查看应用程序的日志文件,特别是错误日志,可以提供更详细的错误信息,帮助确定问题所在。检查日志文件中是否有其他错误或异常信息。 5. 更新或修复依赖项:如果问题是由于依赖项的冲突或损坏引起的,可以尝试更新或修复相关的依赖项。可以使用依赖项管理工具(如Maven或Gradle)来管理和更新依赖项。 如果上述步骤无法解决问题,可能需要进一步调查和诊断。可以尝试在开发环境中运行应用程序,使用调试工具来跟踪和定位问题。另外,查阅相关文档、搜索类似问题的解决方案、咨询开发社区等也是解决问题的有效途径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值