When trying to start a Spring Boot application for tests (with H2 database) with R2DBC and Liquibase configured, I get the following error:
2022-10-04 12:50:18.893 INFO 57774 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 67 ms. Found 2 R2DBC repository interfaces.
org.h2.message.DbException: Log file error: "/.testdb.trace.db", cause: "java.nio.file.FileSystemException: /.testdb.trace.db: Read-only file system" [90034-214]
Here's my config:
spring:
liquibase:
change-log: classpath:liquibase/db.changelog.xml
contexts: production
url: jdbc:h2:file:///./.testdb;MODE=MySQL
r2dbc:
url: r2dbc:h2:file:///./.testdb
h2:
console:
enabled: false
Is there anything I can do to fix that error?
The problem was caused by the URL, R2DBC requires it to look like this:
r2dbc:
url: r2dbc:h2:file:///./.testdb
But then if you try to copy it over to Liquibase part, the error appears. To fix that, remove forward slashes from Liquibase URL:
spring:
liquibase:
change-log: classpath:liquibase/db.changelog.xml
contexts: production
url: jdbc:h2:file:./.testdb;MODE=MySQL
Final version:
spring:
liquibase:
change-log: classpath:liquibase/db.changelog.xml
contexts: production
url: jdbc:h2:file:./.testdb;MODE=MySQL
r2dbc:
url: r2dbc:h2:file:///./.testdb
h2:
console:
enabled: false
I have an simple spring boot application.
Client's application.yaml file:
spring:
config:
import: optional:configserver:http://localhost:1717
application.name: config-client
profiles:
active: profile1
---
spring:
config:
activate:
on-profile: profile1
option:
local: profile1-local
And application gets properties from config server.
Config Server provides next config-client.yaml file:
spring:
application.name: config-client
---
spring:
config:
activate:
on-profile: profile1
option:
local: profile1-remote
remote: profile1-remote
But when I trying use:
#Value("${option.local}")
String local;
I gets profile1-local (value from application.yaml) value instead of profile1-remote (value by server config).
But if I use ${option.remote} value gets from config server.
The problem reproduces if I want override profile properties only, properties outside the profile are overridden!
Why Spring Boot not override profile local property by property from config server?
Maybe problem caused by Spring changed config file processing in Spring Boot 2.4, but option spring.config.use-legacy-processing: true not helps me!
I has confused! Thanks you very much!
I’m migrating an application from Spring Boot 2.3 to Spring Boot 2.4, I have some problems with profiles order loading.
In my application, I have some profiles :
default (application-default.yml) : default values for the application. There is a lot of default values, the goal is not to complicate the file application.yml, so it's very important to have this file
quality (application-quality.yml) : quality profile
environment profile (for example application-Dev.yml) : profile of the current environment. It must override application.yml and application-default.yml values
database profile for the environment (for example application-databaseDev.yml) : profile for the database connection for the current environment
In Spring Boot 2.3, configuration is :
application.yml
spring:
profiles:
include:
- default
redis:
jedis:
pool:
max-active: 4
application-default.yml
spring:
profiles:
include:
- quality
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-Dev.yml
spring:
profiles:
include:
- databaseDev
myApplication:
cache:
enabled: false
I'm starting application with parameter --spring.profiles.active=Dev
In this case, here is the order of the active profile The following profiles are active: default,quality,Dev,databaseDev
This is order I want. For exemple value for key myApplication.cache.enabled is false
I read the documentation to migrate to Spring Boot 2.4, so my configuration is now :
application.yml
spring:
profiles:
group:
"Dev": "default, quality, databaseDev"
redis:
jedis:
pool:
max-active: 4
application-default.yml
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-Dev.yml
myApplication:
cache:
enabled: false
But now I have the active profile The following profiles are active: Dev,default,quality,databaseDev
In this case the value for key myApplication.cache.enabled is true
Now profile Dev doesn't override default profile as 2.3 but inversely default profile override Dev profile.
Is there a way to modify the configuration to work as 2.3 (without using use-legacy-processing: true)? Did I make a mistake somewhere?
I found a solution that works :
Rename the profile Dev to dev and create a group named Dev
Here is the result :
application.yml
spring:
config:
import: classpath:application-groups.yml
redis:
jedis:
pool:
max-active: 4
application-groups.yml
spring:
profiles:
group:
"base": "default, quality"
"Dev": "base, databaseDev"
application-default.yml
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-dev.yml
myApplication:
cache:
enabled: false
Starting with parameter --spring.profiles.active=Dev
The following profiles are active: Dev,base,default,quality,databaseDev
What do you think about this solution ?
I have a Spring Boot Application with a couple Entity classes and I'm trying to implement database migrations with flyway. It appears that, on startup, Spring Boot is not running flyway at all.
Here is my application.properties
spring.datasource.url= jdbc:postgresql://localhost:5555/mfidb
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=validate
spring.flyway.enabled=true
Here are the lines in my build.gradle that have something to do with flyway
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id "org.flywaydb.flyway" version "6.4.1"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtime('org.postgresql:postgresql:42.2.12')
}
flyway {
url = 'jdbc:postgresql://localhost:5555/mfidb'
user = 'postgres'
password = 'postgres'
}
I am able to run my migrations by entering gradle flywayMigrate -i in the terminal.
But I want the migrations to run on startup.
Any help would be greatly appreciated, thanks in advance.
EDIT:
Here is the console output when running the application
2020-05-05 11:55:59.022 INFO 50754 --- [ main] com.ubm.mfi.MfiApplication : Starting MfiApplication on MacBook-Pro.local with PID 50754 (~/Downloads/mfi 5/build/classes/java/main started by will in ~/Downloads/mfi 5)
2020-05-05 11:55:59.024 INFO 50754 --- [ main] com.ubm.mfi.MfiApplication : No active profile set, falling back to default profiles: default
2020-05-05 11:55:59.457 INFO 50754 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-05 11:55:59.495 INFO 50754 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 33ms. Found 2 JPA repository interfaces.
2020-05-05 11:55:59.778 INFO 50754 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-05 11:55:59.783 INFO 50754 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-05 11:55:59.784 INFO 50754 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-05-05 11:55:59.838 INFO 50754 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-05 11:55:59.838 INFO 50754 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 768 ms
2020-05-05 11:55:59.917 INFO 50754 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-05-05 11:55:59.944 INFO 50754 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-05-05 11:55:59.991 INFO 50754 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-05-05 11:56:00.051 INFO 50754 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-05 11:56:00.114 INFO 50754 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-05-05 11:56:00.124 INFO 50754 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-05-05 11:56:00.545 INFO 50754 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-05 11:56:00.548 INFO 50754 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-05 11:56:00.818 WARN 50754 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-05-05 11:56:00.891 INFO 50754 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-05 11:56:01.005 INFO 50754 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-05 11:56:01.007 INFO 50754 --- [ main] com.ubm.mfi.MfiApplication : Started MfiApplication in 2.255 seconds (JVM running for 2.983)
Here is the path to the data migrations
Add logging.level.root=debug your application.properties file to see detailed information during start application.
Also just add flyway user and password to application.properties.
spring.flyway.url = 'jdbc:postgresql://localhost:5555/mfidb'
spring.flyway.password=postgres
spring.flyway.user=postgres
if you dont need to run flyway from gradle, you can remove flyway config from build.gradle
My dependencies weren't getting refreshed when i did a gradle clean build so the flyway source was never there. I had to manually refresh my dependencies in my IDE and it started working. Sad when you spend hours on something so simple. Giga's comment to change the logging level helped me to find the issue. Thanks
Your application.properties looks perfect to me.
I am using Flyway as well, it works like a charm and executes migrations on startup of my application. The only entry in my build.gradle related to flyway is the dependency
runtime("org.flywaydb:flyway-core")
I think you should remove all other flyway related entries from build.gradle.
In my case this is what happened:
I spent almost 4 hours to figure this out, My assumption was Spring JPA starter bring the flyway core dependency along with it. I didn't add the dependency for flyway-core explicitly. So if we dont do it spring boot flyway auto configuration will not give any error but just simply ignore the migration setup.
By tracing the auto configuration I figured out this, auto configuration ignoring the flyway setup if dependency not added manually rather than throwing exception using conditional annotation like this #ConditionalOnMissingBean({Flyway.class})
In my case it, was a missing character in the filename of the flyway init script.
Bad-Filename: V1_init.sql
Good-Filename: V1__init.sql (double '_')
I was missing an underscore in the filename, it needs 2 instead of 1.
Using spring-boot 2.6.7, my application.properties
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=validate # or 'none'
Resource-Folder
src/main/resources
- db/migration
- V1__init.sql
Example of V1__init.sql
create sequence hibernate_sequence start with 1 increment by 1;
CREATE TABLE person
(
id INT NOT NULL,
name VARCHAR(255),
age INT,
CONSTRAINT pk_person PRIMARY KEY (id)
);
Described correctly in the spring docs, but I recognised too late
Check if your script already run.
The trick is, once Flyway has succeeded in running the update script, it has created the table flyway_schema_history, that recorded that I have already run the create script successfully once.
When I tried to run the script second time, that was rejected but since the originally created table (in my case called 'bike') was deleted when the app shut down when run in spring.jpa.hibernate.ddl-auto=create-drop mode previous time, I was getting the
SchemaManagementException: Schema-validation: missing table [bike] Exception.
drop the flyway_schema_history table or delete a record corresponding to previous script run and roll again!
After checking the SQL manually, here's what worked for me (using Spring Boot + Cloud):
important part in my build.gradle:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.flywaydb:flyway-core'
implementation 'org.hibernate:hibernate-core'
implementation 'org.hibernate.validator:hibernate-validator:7.0.1.Final'
no gradle plugins. And in application.yml / application-local.yml:
spring:
flyway:
baseline-on-migrate: true
jpa:
database: POSTGRESQL
show-sql: true
hibernate:
ddl-auto: validate
open-in-view: true
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5432/your_db
username: your_db_user
password: your_db_passwd
driverClassName: org.postgresql.Driver
Note that you do not need the flyway specific config for DB user/url. Spring Boot detects Flyway (or Liquibase if you were using that...) on the classpath. It then uses the primary datasource. See: https://docs.spring.io/spring-boot/docs/2.5.6/reference/html/howto.html#howto.data-initialization . Then the last trick is to make your first script V2__init.sql . This is critical as the baseline-on-migrate: true bit creates the flyway_schema_history table and its action is the first thing, so version 1, or V1_ ie the first row... so your script won't go if it is V1__init.sql or whatever. It will think it has already run. It needs to be the next one, V2__init.sql or whatever.
I'm using maven, and solved this issue by running mvn clean install
spring-boot-starter-data-jpa and mysql-connector-java dependencies are required for flyway to run. You can check that in debug output by enabling logging.level.root=DEBUG in your application properties.
Just add following dependencies to fix the issue:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
In my case I had the db/migration incorrectly spelled :)
I found my way here after days of trying different permutations of configurations. For me when trying to upgrade all the way from 6.2.1 to 8.5.11 I simply needed to add flyway.migrate() to the before each in my integration tests.
Tried all of the listed answers, and nothing helped.
Version incompatibility was the cause!
Spring Boot 2.7.0 goes with Flyway 8.5.13
In my case, I had not named the migration correctly.
I had this name v1_0_7__addEws.sql but it should start with capital V
,ie, V1_0_7__addEws.sql
I am using a JHipster to create a spring boot application with PostgreSQL.
Actualy, when i execute the command mvnw the application-dev config file is "cleaned" to the initial properties.
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/test
username: test
password:
In this case, my database properties (user, password ...) are cleaned. I obtain the error:
"2017-08-06 18:17:10.726 ERROR 10844 --- [ restartedMain]
com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception
during pool initialization.
org.postgresql.util.PSQLException: The server requested password-based
authentication, but no password was provided."
Anyone can help me?
Need to put password into password .
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://localhost:5432/test
username: test
password:<YOUR PASSWORD>