Guys for 3 days I am searching for an answer and can't find the exact answer for my problem. So I am doing some tutorials on Spring and Hibernate and get stuck when trying to establish a connection between Spring Boot project, MySQL database and Tomcat server. Here is my "pom.xml" 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.bookstore</groupId>
<artifactId>bookstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Bookstore</name>
<description>frontend part for our bookstore project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
And here are my properties:
spring.thymeleaf.cache=false
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
spring.datasource.url=jdbc:mysql://localhost:3306/bookstoredatabase?autoReconnect=true&useSSL=false
# Username and secret
spring.datasource.username=root
spring.datasource.password=target
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
I am using Tomcat from XAMPP - version 7.0.56. MySQL Server and the connector are both version 8. Without using Tomcat, I am perfectly able to connect to any database, edit it, etc.
Here are the errors, which occur:
INFO 15816 --- [main] org.hibernate.Version: HHH000412: Hibernate Core {5.0.11.Final}
INFO 15816 --- [main] org.hibernate.cfg.Environment: HHH000206: hibernate.properties not found
INFO 15816 --- [main] org.hibernate.cfg.Environment: HHH000021: Bytecode provider name:javassist
INFO 15816 --- [main] o.hibernate.annotations.common.Version: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
ERROR 15816 --- [main] o.a.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool. com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
The full error log can be seen here . I have tried so many things. Please help me guys.
EDIT:
Okay. I have read the error log more carefully. I am using Tomcat from XAMPP, version 7.056, but Spring starts Tomcat with version 8. I don't know if I should make another question, but when I added <tomcat.version>7.0.56</tomcat.version> to my properties, the error log changed into this
I'm sorry. I checked Trace now.
When you check the bug report, was probably fixed in connector/J 5.1.41.
change this to your pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
Have you created database called bookstoredatabase on mysql?
and I think you should add dependency of mysql connector to pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Related
i made a new project with Spring Initializr and run it after import in the Intellij without any change in the code that generated by the IDE and i get the following error :
restartedMain] 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 0
my pom.xml is:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<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>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</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>
MariaDB version: 10.3.23
Spring Ver: 2.3.2
Java Ver: openjdk 1.8.0_252
This Error comes from bad database configuration of the application.properties under the: /src/main/resources
read the: this github repo for knowing all the setting that you can and should use in the application.properties but for your simple project use the below instruction:
add this lines of code to the application.properties:
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
# Connection url for the database "netgloo_blog"
spring.datasource.url = jdbc:mysql://localhost:3306/netgloo_blog?useSSL=false
# Username and password
spring.datasource.username = root
spring.datasource.password = root
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# ===============================
# = JPA / HIBERNATE
# ===============================
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager).
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in
# the project
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
this basic configuration will get you out of trouble but remember to change the username and password for your MySQL or MariaDB Database.
you can use this topic for more information about change User and Pass for Database in spring and jhipster projects
I have already added ojdbc ddriver and included the dependency in pom, but I still get the error mentioned in the title. Please help.
Earlier I ran the application with a local postgres db. Now trying to connect to a remote oracle db, and encountered this problem. I am logged into the necessary firewalls.
The appplication started and performed as exected with the postgresdb.
I get the following logs when trying to start my application now -
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-06 12:08:51.786 ERROR 27236 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driverclassname
Value: oracle.jdbc.OracleDriver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class oracle.jdbc.OracleDriver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
Process finished with exit code 1
The pom file is as below
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>package</groupId>
<artifactId>QualityScore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>QualityScore</name>
<description>Demo project in Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</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>
</project>
Application.properties -
##Postgres settings
##spring.datasource.url=jdbc:postgresql:*****
##spring.datasource.username=*****
##spring.datasource.password=*****
##spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true
# Oracle settings
spring.datasource.url=jdbc:oracle:*****
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver
# HikariCP settings
spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
I got the solution or fix.
I added the following property in application.properties
spring.datasource.driver-class=oracle.jdbc.driver.OracleDriver
and explicitly specified the driver(ojdbc8) in the modules of the project structure.
Now it works!!! Thank you everyone for your help!!
you application.properties is wrong. You have:
#spring.datasource.url=jdbc:*****
#spring.datasource.username=****
#spring.tasource.password=*****
#spring.jpa.database-platform = *****
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:oracle:****
spring.datasource.username=*****
spring.datasource.password=*****
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Recipientlist=*****
but you don't have your driver-class-name set. should be:
#spring.datasource.url=jdbc:*****
#spring.datasource.username=****
#spring.tasource.password=*****
#spring.jpa.database-platform = *****
spring.jpa.hibernate.ddl-auto = none
spring.jpa.hibernate.show-sql=true
spring.datasource.url=jdbc:oracle:****
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
#spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Recipientlist=*****
Regards!
In my controller test classes, this error occurred when running the tests. Even with the spring.datasource.driver-class-name property set.
To resolve this, we added the DataSouce attribute with the #MockBean annotation in the controller test classes:
#MockBean
private DataSource dataSource;
The test classes performed perfectly.
I was trying to connect to my table and insert some data.We are using oracle database.
In the code I have used oracle thin driver ojdbc14.I am getting
2018-12-27 11:08:58.810 INFO 16548 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
2018-12-27 11:08:58.810 ERROR 16548 --- [ main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Failed to execute isValid() for connection, configure connection test query (oracle.jdbc.driver.T4CConnection.isValid(I)Z).
I am fairly new to spring boot and was actually trying to
do
this demo -
https://www.devglan.com/spring-jdbc/working-with-springboot-jdbctemplate
only changes I have done is in my pom.xml and application.properties.
Is there any thing else needed for oracle? How i should solve this?All the example I see for oracle in net is with hibernate.Is is necessary to include hibernate approach?
Thank you in advance.
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- HikariCP connection pool -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
application.properties
spring.datasource.url=jdbc:oracle:thin:#//url/service
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
That is because you are using a very old version of ojdbc.
You should be using the latest versions of the Oracle JDBC driver to connect to your Oracle database.
From a quick test here:
the warning is still present with version 11.2.0.1
there is no warning with version 12.1.0.2
oracle.jdbc.driver.T4CConnection.getNetworkTimeout API is in Oracle JDBC 12.1.0.2(https://docs.oracle.com/database/121/JAJDB/toc.htm).
but oracle.jdbc.driver.T4CConnection.getNetworkTimeout API is not in Oracle JDBC 11.2.0.1(https://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/jdbc/OracleConnectionWrapper.html)
I'm trying to cf push my spring boot app to Pivot Cloud Foundry, but the container fails to start. This is the error output:
2018-08-21T12:48:55.34+0200 [CELL/0] OUT Starting health monitoring of container
2018-08-21T12:48:55.81+0200 [APP/PROC/WEB/0] OUT JVM Memory Configuration: -Xmx427509K -Xss1M -XX:ReservedCodeCacheSize=240M -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=109066K
2018-08-21T12:48:55.81+0200 [APP/PROC/WEB/0] OUT Failed to start a browser to open the URL http://10.246.203.10:8082: Browser detection failed and system property h2.browser not set
2018-08-21T12:49:56.15+0200 [HEALTH/0] ERR Failed to make TCP connection to port 8080: connection refused
2018-08-21T12:49:56.15+0200 [CELL/0] ERR Timed out after 1m0s: health check never passed.
I tried to set the h2.browser property to "opera", false and true in Application.yml but that did not solve the problem. I also removed the h2 dependency because I don't want to use h2 in PCF and rebuilded the artifact before cf push. When I run the JAR file, it opens my browser with the h2 webinterface (I don't want that).
What am I missing here?
EDIT: I think I might need to pass an argument to the java app in PCF to disable the console (browser part) of H2 but not sure..
Application.yml:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://my_url_here
username: my_username_here
password: my_password_here
jpa:
hibernate.ddl-auto: none
show_sql: false
manifest.yml
---
applications:
- name: cookie-backend
memory: 1024M
instances: 1
random-route: true
buildpack: java_buildpack
path: out/artifacts/cookie_backend_jar/cookie-backend.jar
services:
- mysql
pom.xml
<?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</groupId>
<artifactId>cookie</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cookie</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>0.15</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I solved it by first starting a new Spring project, secondly importing all the dependancies in my new project POM file and and than adding back all classes (code) in that order. I ended up with a new project on the same codebase without the error.
This is not the exact answer to what was going wrong with it, but it might be helpfull for someone trying to solve the same problem. I'm using h2 now on a production server. Also, the answer from #Daniel in respond to the issue might be helpful.
I am trying to make migration demo on embedded H2 data base in Spring Boot application using Flyway.
application.properties
logging.level.org.org.springframework=DEBUG
server.port=8181
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.driver-class-name=org.h2.Driver
spring.flyway.baseline-on-migrate=true
spring.jpa.hibernate.ddl-auto=none
migration-script(V2__create_shipwreck.sql) under db/migration
CREATE TABLE SHIPWRECK(ID INT AUTO_INCREMENT,
NAME VARCHAR(255),
DESCRIPTION VARCHAR(2000),
CONDITION VARCHAR(255),
DEPTH INT,
LATITUDE DOUBLE,
LANGITUDE DOUBLE,
YEARS_DISCOERED INT);
console log
INFO 7284 --- [main] o.f.c.internal.database.DatabaseFactory:
Database: jdbc:h2:mem:testdb (H2 1.4)
INFO 7284 --- [main] o.f.core.internal.command.DbValidate:
Successfully validated 1 migration (execution time 00:00.031s)
INFO 7284 --- [main] o.f.c.i.s.JdbcTableSchemaHistory: Creating Schema
History table: "PUBLIC"."flyway_schema_history"
INFO 7284 --- [main] o.f.core.internal.command.DbMigrate: Current
version of schema "PUBLIC": << Empty Schema >>
INFO 7284 --- [main] o.f.core.internal.command.DbMigrate: Migrating
schema "PUBLIC" to version 2 - create shipwreck
INFO 7284 --- [main] o.f.core.internal.command.DbMigrate :
Successfully applied 1 migration to schema "PUBLIC" (execution time
00:00.098s)
INFO 7284 --- [main] j.LocalContainerEntityManagerFactoryBean :
Building JPA container EntityManagerFactory for persistence unit
'default'
INFO 7284 --- [main] o.hibernate.jpa.internal.util.LogHelper :
HHH000204: Processing PersistenceUnitInfo [name: default...]
main] org.hibernate.Version : HHH000412: Hibernate
Core {5.2.14.Final}
main] org.hibernate.cfg.Environment : HHH000206:
hibernate.properties not found
main] o.hibernate.annotations.common.Version : HCANN000001:
Hibernate Commons Annotations {5.0.1.Final}
main] org.hibernate.dialect.Dialect : HHH000400: Using
dialect: org.hibernate.dialect.H2Dialect
main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default'
pom.xml
<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.boot</groupId>
<artifactId>das-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>das-boot</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.0.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
H2 database tables UI
After starting the Spring Boot application, the table has not been created, so what's the problem here?
I had the same issue, it was solved after making the change to application.properties as
datasource.url to file instead of mem
able to create table with details
Correct:
spring.datasource.url=jdbc:h2:file:~/dasboot
application.properties
logging.level.org.org.springframework=DEBUG
server.port=8080
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:file:~/dasboot
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.flyway.baseline-on-migrate=true
spring.jpa.hibernate.ddl-auto=none
POM.xml
<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.boot</groupId>
<artifactId>das-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<name>das-boot</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
shipwreck table was created and persisted in h2 db
Based on your description (Flyway executes properly, but no schema changes are observed afterwards) this sounds like Spring Boot does not persist the H2 changes. You might try to add spring.jpa.hibernate.ddl-auto=none to your application.properties so that JPA configuration does not override your schema changes following the Flyway migration, as per this question.