springboot启动时排除mybatis
时间: 2023-11-08 15:03:43 浏览: 68
在Spring Boot启动时排除Mybatis可以通过在pom.xml中添加exclude标签来实现,如下所示:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 排除 Mybatis -->
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
```
这里我们排除了Mybatis的Spring Boot Starter依赖,从而避免了在应用程序启动时加载Mybatis相应的配置。
相关问题
springboot排除数据源
为了排除Spring Boot中的数据源,可以使用注解`@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})`。这个注解可以在启动类上添加,用于告诉Spring Boot不要自动配置数据源。
排除数据源的原因通常是因为引入了一些starter插件,比如spring-boot-starter-mongodb,但没有配置数据源的URL,或者在将旧业务升级为Spring Boot时出现的情况。
在一些老项目中,可能已经使用了Spring MVC中预先配置好的数据库连接池,比如Redis、MongoDB、MyBatis等。当这些项目迁移到Spring Boot框架时,可能会出现错误。这是因为Spring Boot在存在相关jar包的情况下会自动加载连接池的自动配置,但我们并没有进行相应的配置,也不需要进行配置。所以需要通过排除数据源的方式来解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Spring Boot排除自动加载数据源](https://blog.csdn.net/fenglllle/article/details/95023981)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
mybatis-plus的generate启动时产生Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
这个错误提示表明在启动mybatis-plus的generate时,没有配置数据源或者数据源的url属性没有被指定。解决这个问题的方法有两种:
1.在application.yml或application.properties文件中配置数据源的url属性,例如:
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydatabase
username: root
password: 123456
```
2.在@SpringBootApplication注解中排除DruidDataSourceAutoConfigure类和DataSourceAutoConfiguration类,例如:
```java
@SpringBootApplication(exclude = { DruidDataSourceAutoConfigure.class, DataSourceAutoConfiguration.class })
@MapperScan("com.example.mybatistest.mapper")
public class MybatistestApplication {
public static void main(String[] args) {
SpringApplication.run(MybatistestApplication.class, args);
}
}
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)