无法解析类或包"h2" [英] Cannot resolve class or package 'h2'
问题描述
我为我的Web应用准备了后端. 在我的项目(SpringBoot + Maven)中,我想添加h2日期基础. 根据网络上的教程:
I prepere back-end for my web app. In my project (SpringBoot + Maven) i would like to add h2 date base. According to tutorials from web:
-
已添加到 application.properties
Added to application.properties
server.port = 8088
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver //h2 seems to be NOT found
spring.jpa.show-sql=true
将依赖项添加到 pom.xml
Added dependencies to pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
问题:
PROBLEM:
在 application.properties 中:无法解析类或程序包'h2'"
in application.properties : "Cannot resolve class or package 'h2'"
全面检查:检查Spring Boot应用程序.properties配置文件.突出显示未解决和不建议使用的配置密钥和无效值.仅适用于Spring Boot 1.2或更高版本."
full inspection: "Checks Spring Boot application .properties configuration files. Highlights unresolved and deprecated configuration keys and invalid values. Works only for Spring Boot 1.2 or higher."
当然,我的Spring Boot高于1.2(1.5.8). 我在网络中发现了类似的问题,但是消除依赖关系"不起作用,因此我仍然没有解决方案:).请帮忙.
Certainly, my Spring Boot is higher than 1.2 (1.5.8). I've found similar problem in web, but "reloding dependencies" doesnt work, so still i dont have a solution :). Please help.
推荐答案
问题似乎出在pom文件中.请找到我与您的application.properties
文件一起检查过的pom.xml文件.
Looks like the issue is somewhere in your pom file. Please find my pom.xml file which I checked with your application.properties
file.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mberazouski.stackoverflow</groupId>
<artifactId>spring-boot-hibernate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-hibernate</name>
<description>Demo project for Spring Boot And Hibernate</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<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>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
一旦弹簧启动将开始,请检查h2-console: http://localhost:8088/h2
Once you spring boot will start, check h2-console: http://localhost:8088/h2
希望这会有所帮助. P.S.如果您不知道,我建议您使用 http://start.spring.io/来生成您的项目.在这里,您可以选择计划使用的任何组件.您可以在此处中阅读有关此内容的更多信息.
Hope this will help. P.S. If you are not aware I suggest you use http://start.spring.io/ for generating of your projects. There you can pick any component which you plan to use. More about that you can read for example here.
这篇关于无法解析类或包"h2"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!