spring boot 不连接数据库启动的解决

网友投稿 3039 2022-12-14

spring boot 不连接数据库启动的解决

spring boot 不连接数据库启动的解决

目录spring boot 不连接数据库启动原因在于解决方法SpringBoot项目取消数据库配置1. 错误2. 原因3. 如何不配

spring boot 不连接数据库启动

用spring boot 搭建的项目,在配置文件不连接数据库启动项目会报错。

原因在于

spring boot默认会加载

org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。

解决方法

在Application类上增加:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

SpringBoot项目取消数据库配置

1. 错误

springboot项目启动时,如果没有配置数据库配置,启动时会抛出如下异常。

Description:

Cannot determine embedded database driver class for database typhttp://e NONE

Action:

If you want an embedded database please put a supported one on the classpath.

If you have database settings to be loaded from a particular profile you may

need to active it (no profiles are currently active).

2. 原因

springboot会自动注入数据源,而你却没有配,所以他就抛出该异常。

3. 如何不配

如果你只是简单的想建个项目,并不需要数据库支持,那么你可以让他不去注入数据源。

一般你启动springboot项目,都会写一个有@SpringBootApplication注解的类

你在这个注解中添加

exclude={DataSourchttp://eAutoConfiguration.class,HibernateJpaAutoConfiguration.class}

即可无数据库运行

如下

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Springboot启动不检查JPA的数据源配置方式
下一篇:SpringBoot使用JPA实现查询部分字段
相关文章

 发表评论

暂时没有评论,来抢沙发吧~