一、APPLICATION FAILED TO START 异常报错原因分析

1. 异常报错描述:

APPLICATION FAILED TO START 应用程序无法启动/应用程序启动失败

这个错误提示只是告诉了我们应用程序启动失败,可能造成的原因很多,而仅仅只是这个提示无法告诉我们具体的原因,我们需要根据具体的原因进行具体的分析。

二、端口号被占用(Port 8080 was already in use) 导致的 APPLICATION FAILED TO START

1. 详细描述:

1.1 详细描述1(对应案例1):

Description:

Web server failed to start. Port 8080 was already in use.

2. 异常报错信息案例:

2.1 案例1:

在这里插入图片描述

2.1.1 异常错误描述:

错误原因:端口号 8080 被占用 导致的应用程序启动失败

2.1.2 解决方案:
  1. 关闭对应端口号的应用程序(服务)
  2. 修改要启动项目的端口号
    此项目应该为 SpringBoot 项目,可以通过修改配置文件的方式修改该项目的端口号
    • application.properties
      server.port=8090
      
    • application.yml
      server:
        port: 9000
      

三、Mybatis 导致的 APPLICATION FAILED TO START

1. 详细描述:

1.1 详细描述1(对应案例1):

Description:

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

2. 异常报错信息案例:

2.1 案例1:

请添加图片描述

2.1.1 异常错误描述:

错误原因:数据源没有配置导致的应用程序启动失败

2.1.2 解决方案(一):

解决思路:这里,我们只需要检查我们的配置文件是否添加了正确的数据源信息

  • application.properties(创建项目默认)
    请添加图片描述

    spring.datasource.url=jdbc:mysql://localhost:3306/demo_admin?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
    spring.datasource.username=root
    spring.datasource.password=root
    
  • application.yml
    请添加图片描述

    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/demo_admin?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai
        username: root
        password: root
    
2.1.3 解决方案(二):

当然如果我们不需要使用这个配置源,我们也可以忽略/排除这个数据源
我们可以在 SpringBoot 项目的启动类上添加 exclude 属性

// exclude= {DataSourceAutoConfiguration.class} 忽略数据源的自动配置
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class MallOssApplication {
    public static void main(String[] args) {SpringApplication.run(MallOssApplication.class, args);}
}

四、Knife4J 导致的 APPLICATION FAILED TO START

1. 详细描述:

1.1 详细描述1(对应案例1):

Description:

Field openApiExtensionResolver in cn.cy.config.Knife4jConfiguration required a bean of type ‘com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver’ that could not be found.

1.2 详细描述2(对应案例2):

Description:

Parameter 0 of constructor in com.github.xiaoymin.knife4j.spring.plugin.DynamicResponseModelReader required a bean of type ‘springfox.documentation.schema.TypeNameExtractor’ that could not be found.

2. 异常报错信息案例:

2.1 案例1:

在这里插入图片描述

2.1.1 异常错误描述:

错误原因:类 Knif4jConfiguration 中的 openApiExtensionResolver 属性没有被注入

2.1.2 解决方案:

解决思路:这里,我们只需要检查我们的配置文件是否添加了正确的 knif4j 配置

  • application.properties(创建项目默认)
    在这里插入图片描述

    knife4j.enable=true
    
  • application.yml
    在这里插入图片描述

    #开启Knife4j的增强模式
    knife4j:
      enable: true
    

2.2 案例2:

在这里插入图片描述

2.2.1 异常错误描述:

错误原因:类 DynamicResponseModelReader 因为没有无参构造方法所以没有被注入

2.2.2 解决方案:

解决思路:这里,我们只需要检查我们的配置类中是否添加了 @EnableSwagger2WebMvc 注解,或者检查是否添加了 @ComponentScan({"springfox.documentation.schema"})

  • 解决方案一:添加 @EnableSwagger2WebMvc 注解
    在这里插入图片描述

  • 解决方案二:添加 @ComponentScan({"springfox.documentation.schema"})
    在这里插入图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐