软件编程
位置:首页>> 软件编程>> java编程>> Springboot启动不检查JPA的数据源配置方式

Springboot启动不检查JPA的数据源配置方式

作者:jieniyimiao  发布时间:2022-10-10 06:47:05 

标签:Springboot,JPA,数据源,配置

Springboot启动不检查JPA的数据源配置

1.问题

有时我们使用spring boot ,在依赖中配置了spring data jpa的依赖,此时spring boot启动时会自动检测数据源的配置,如果没有则报无数据源的错误。

但是这个依赖必须要有,因为代码需要根据一些条件选择是否启用数据源,则么办?

2.方案

在SpringApplication实例中设置如下的配置即可:


spring.autoconfigure.exclude = org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

实例如下:

Springboot启动不检查JPA的数据源配置方式

设置Springboot项目忽略JPA启动

解决方案

在@SpringbootApplication注解后面加上


(exclude=DataSourceAutoConfiguration.class)

来源:https://jieniyimiao.blog.csdn.net/article/details/90757853

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com