spring boot运行报错

本文详细记录了SpringBoot结合Eureka作为服务注册中心时遇到的配置错误,包括未指定数据源导致的启动失败及解决方法,以及引入数据源后因JAXBContext类型缺失引发的问题及解决方案。

spring boot运行报错

springboot 版本 2.0.6

配置文件
server:
port: 10086
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://127.0.0.1:${server.port}/eureka/

启动类
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
public static void main(String[] args) {
SpringApplication.run(EurekaServer.class, args);
}
}
父工程依赖



org.springframework.cloud
spring-cloud-dependencies
Finchley.SR4
pom
import


依赖

org.springframework.cloud
spring-cloud-starter-netflix-eureka-server

运行结果
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2019-09-07 09:36:32.749 ERROR 4400 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :


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).

Process finished with exit code 1

网上查找资料说是启动springboot必须引入数据源,,,,以前也做过发送短信的微服务,没引入数据源,这个问题现在不明确,,以前的springboot是1.6的,,,还有网上说的在注解加上(exclude = DataSourceAutoConfiguration.class),问题依然存在

解决问题:
引入数据源
#spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
#MySQL配置
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/***?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: root
运行后报错
java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present

因为JAXB-API是java ee的一部分,在jdk9中没有在默认的类路径中;

java ee api在jdk中还是存在的,默认没有加载而已,jdk9中引入了模块的概念,可以使用

模块命令–add-modules java.xml.bind引入jaxb-api;

(别人的,自己还看不懂)
地址::https://blog.youkuaiyun.com/qq_15807167/article/details/79346607

在pom文件引入

javax.xml.bind
jaxb-api
2.3.0


com.sun.xml.bind
jaxb-impl
2.3.0


org.glassfish.jaxb
jaxb-runtime
2.3.0


javax.activation
activation
1.1.1

问题解决
求大神指点 问题解决了但还是不懂问题所在
1.springboot启动必须引入数据源么?还是版本不同不同的配置?
2.只是简单的启动不需要数据库的。。。。那些依赖是干什么的

### 错误原因分析 在运行Spring Boot项目时,遇到错误提示 **“java: 错误: 不支持发行版本 24”**,这表明当前项目配置使用了 JDK 24 的特性,但实际使用的 JDK 版本可能不支持该发行版本。JDK 发行版本通常与 Java 语言版本相关,例如: - 发行版本 24 对应 Java 24(即 JDK 24)。 - 如果系统中没有安装对应的 JDK 24,或者 IDE(如 IntelliJ IDEA)未正确配置 JDK 24,就会导致该错误。 根据 Spring Boot 的版本兼容性要求,Spring Boot 3.x 开始支持 JDK 17 及更高版本,而更高版本的 Spring Boot(如 3.3.x 或 4.x)可能会要求 JDK 21 或 JDK 24。因此,如果项目配置使用了 Spring Boot 的较新版本,但未安装 JDK 24,就会出现此错误。 --- ### 解决方案 #### 1. **确认当前 JDK 版本** 首先,检查本地是否安装了 JDK 24: ```bash java -version ``` 如果输出中没有显示 `24`,则需要安装 JDK 24 或者降级 Spring Boot 版本以兼容当前 JDK。 #### 2. **安装 JDK 24** 如果希望继续使用 Spring Boot 的最新版本,建议安装 JDK 24。可以从以下来源获取: - [Oracle JDK](https://www.oracle.com/java/technologies/downloads/) - [OpenJDK](https://adoptium.net/) 安装完成后,确保 IDE(如 IntelliJ IDEA)中的 JDK 配置指向新安装的 JDK 24。 #### 3. **配置 IntelliJ IDEA 使用 JDK 24** 进入 IntelliJ IDEA 设置: - **File > Project Structure > SDKs**:添加 JDK 24。 - **File > Settings > Build, Execution, Deployment > Compiler > Java Compiler**:设置 **Project bytecode version** 为 24。 - **File > Settings > Editor > Language Levels**:设置 **Project language level** 为 **24**。 #### 4. **修改 Spring Boot 版本以兼容现有 JDK** 如果不希望安装 JDK 24,可以选择降级 Spring Boot 版本,以匹配当前 JDK。例如: - **Spring Boot 2.7.x** 支持 JDK 11。 - **Spring Boot 3.0.x** 要求最低 JDK 17。 - **Spring Boot 3.2.x** 支持 JDK 21。 - **Spring Boot 3.3.x** 支持 JDK 24。 在 `pom.xml` 中修改 Spring Boot 版本: ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.18</version> <!-- 修改为支持当前 JDK 的版本 --> <relativePath/> <!-- lookup parent from repository --> </parent> ``` #### 5. **更新 Maven 依赖** 在修改 Spring Boot 版本后,执行以下命令更新依赖: ```bash mvn clean install ``` 确保所有依赖与当前 Spring Boot 版本兼容。 --- ### 6. **验证运行环境** 修改配置后,重新运行项目: ```bash mvn spring-boot:run ``` 如果没有错误,则说明问题已解决。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值