创建springBoot项目及启动报错遇到的问题解决:Failed to configure a DataSource: 'url' attribute is not specified and no embedd
IDEA 如何快速创建 Springboot 项目,请查看这篇:https://blog.csdn.net/sunnyzyq/article/details/108666480
一、启动报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedd
***************************
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).
翻译就是:无法配置DataSource:未指定'url'属性,也无法配置嵌入数据源。
很明显,就是你在应用中没有配置datasource的一些相关属性,例如:地址值啊,数据库驱动啊,用户名啊,密码啊,
都知道,SpringBoot的最大一个好处就是自动配置:所以我们只是需要给他配置文件的值,它就会自动配置。配置在application.properties文件中。
所以有2个解决方案:
1、第1种,在application.yml里配置上数据库的相关信息,比如
spring:
application:
name: openGauss Exam
datasource:
url: jdbc:postgresql://***
driver-class-name: org.postgresql.Driver
username: **
password: ***
hikari:
login-timeout: 30
connection-timeout: 10000
idle-timeout: 600000
max-lifetime: 1800000
connection-test-query: select 1
2、第2种,也可以不配置,但是你需要声明一下,启动类头部声明就可以
注解这样写:@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class ExamApplication {
public static void main(String[] args) {
SpringApplication.run(ExamApplication.class, args);
}
}
二、非法反射,报错信息
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/%e5%85%b3%e6%96%87%e5%b3%b0/.m2/repository/org/springframework/spring-core/5.0.6.RELEASE/spring-core-5.0.6.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
警告信息,暂时没影响
三、idea运行springBoot项目报错 Process finished with exit code 0
Deleting provided scope of spring-boot-starter-tomcat dependency helps me.
在pom.xml中添加,然后导入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
四、alt + enter 导入类
在使用idea开发java项目的时候,经常需要导入jdk或者是第三方类库的类,如果是自己手工导入的话,非常麻烦,效率很低,下面来介绍下如何设置idea,就可以实现自动导入
设置自动导入的方式,来自动批量导入,打开idea的settings设置对话框
在左上角的输入框中输入auto import关键字搜索,找到Editor>General>Auto Import
勾选上add unambiguous imports on the fly选项,点击确认,关闭对话框
在设置自动导入的窗口,还有一个Optimize imports on the fly选项,也可以勾选上,可以帮助我们自动去除不需要的导入类。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律