@SpringBootApplication 怎么排除数据源引用
时间: 2023-08-12 13:15:05 浏览: 48
如果在使用 Spring Boot 时想要排除默认的数据源引用,可以在 `@SpringBootApplication` 注解上使用 `exclude` 属性,指定要排除的配置类。例如:
```java
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class MyApplication {
// ...
}
```
这样就会排除默认的数据源配置,从而避免不需要的数据源依赖被引入。
相关问题
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
回答: @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })这个注解的作用是排除自动注入数据源的配置,即取消数据库配置。在Spring Boot中使用多数据源时,可以使用这个注解来排除默认的数据源配置,以便使用自定义的数据源配置。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* *2* [@SpringBootApplication exclude = {DataSourceAutoConfiguration.class} 失效的解决方案](https://blog.csdn.net/shi860715/article/details/113737078)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [SpringBoot @SpringBootApplication(exclude={DataSourceAutoConfiguration.calss})](https://blog.csdn.net/wangrongfei136/article/details/108622712)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
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 ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)