java - 在 Spring starter 项目中是否必须配置 DataSource?
问题描述
我想创建一个基本的 Spring 启动应用程序并发出获取请求。我已经添加了 Spring JPA、Spring Web 依赖项并开始在端口 8080 中运行,但我的应用程序要启动。它说“说明:
无法配置数据源:未指定“url”属性,并且无法配置嵌入式数据源。原因:无法确定合适的驱动程序类“。
我没有添加任何数据库依赖项,因为我不需要它,在我的项目中是否必须具有数据库依赖项?这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
4.0.0 org.springframework.boot spring-boot-starter-parent 2.3.1.RELEASE com.example java-sample-project 0.0.1-SNAPSHOT java-sample-project Spring Boot的演示项目
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
解决方案
是的,这是强制性的。但是,如果您不想运行真正的数据库,请使用内存数据库 H2。只需将 com.h2database:h2 添加到依赖项即可。
推荐阅读
- python - 附加新列,从不同数据帧(不同长度)的列中识别匹配的日期时间日期
- reactjs - 如何在FullCalendar的反应js中附加和显示具有其他属性的标题?
- python - 实时更改 tkinter 小部件的最佳方法
- fortran - 从文本文件中读取一个变量作为fortran中同一文件中其他两个变量的函数
- powershell - Powershell 输出被 powershell 切断。输出中的点
- html - *ngFor 中的 NgModel 函数在启动时运行次数过多
- apache-karaf - 如何在 Karaf Osgi 上安装 ActiveMQ Artemis 控制台
- python - 如何获得 str.split 就地重命名列的结果?
- javascript - 什么是删除除 jquery 中的一个之外的所有类的更清洁方法,如果还没有该类,也无需添加该类
- react-native - 始终显示底部选项卡导航器 React Naive 中的 React Navigation 5