Spring Boot报错

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.


一、情况一

报错

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2022-07-24 17:54:00.774 ERROR 12512 — [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :

/***************************
APPLICATION FAILED TO START
/***************************

Description:

Field carMapper in com.sgz.service.CarServiceImpl required a bean of type ‘com.sgz.dao.CarMapper’ that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type ‘com.sgz.dao.CarMapper’ in your configuration.

截图

在这里插入图片描述

解决

在启动类上加上注解 @MapperScan(“com.sgz.dao”)

@SpringBootApplication
@MapperScan("com.sgz.dao")	// 在启动类中加上这个注解即可
public class RunApp {
    public static void main(String[] args) {
        SpringApplication.run(RunApp.class);
    }
}

二、情况二

报错

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2022-07-24 18:06:12.632 ERROR 18812 — [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :

/***************************
APPLICATION FAILED TO START
/***************************

Description:

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

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

截图

在这里插入图片描述

解决

方法一

pom.xml中mybatis依赖包版本过低,换成高版本的即可
在这里插入图片描述

方法二
  1. 将mybatis的依赖包注释掉
    在这里插入图片描述
  2. 然后刷新maven配置
    在这里插入图片描述
方法三
  1. 将mybatis的依赖包注释掉
    在这里插入图片描述

  2. clean命令清除整个工程
    在这里插入图片描述

  3. 然后再刷新maven配置
    在这里插入图片描述

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐