Reputation: 593
I develop back-end application for my web app. In my project (SpringBoot + Maven) I would like to add h2 database. According to tutorials from web:
Added following lines in application.properties file:
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
Added following dependencies in pom.xml file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
PROBLEM:
in application.properties : "Cannot resolve class or package 'h2'"
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."
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.
Upvotes: 5
Views: 8877
Reputation: 56
I was facing the same error and I solved this by defining the scope of h2 dependency like in the pic below:
Upvotes: 0
Reputation: 1001
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>
Once you spring boot will start, check h2-console: http://localhost:8088/h2
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.
Upvotes: 1