I have a spring boot project, and I need to configure Flyway in my application.yml file.
Does anyone know how to do this with Yaml?
Look into this Flyway doc
Application.yml
spring:
datasource:
driverClassName: ${DRIVER}
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
jpa:
show-sql: true
flyway:
enabled: true
validate-on-migrate: true
Dependency
implementation 'org.flywaydb:flyway-core'
Related
spring-boot-starter-parent:2.7.5
I have configured the following in my src/main/resources/application.yml file:
spring:
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
---
spring:
config:
activate:
on-profile: prod
datasource:
driver-class-name: org.postgresql.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
Additionally, the following resource exists in the project repository:
src/main/resources/db/changelog/db.changelog-master.xml
I also have the following configured in src/test/resources/application.yml:
spring:
config:
activate:
on-profile: test
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
username: sa
password: sa
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
When I try to build this project the build fails with the following error message:
Liquibase failed to start because no changelog could be found at 'classpath:/db/changelog/db.changelog-master.yaml'
Is there some way to configure spring boot to allow an xml based liquibase changelog file? If so, what am I missing? Or does it only support the yaml format?
Your configurations seems valid, but some configuration still points to classpath:/db/changelog/db.changelog-master.yaml (based by on provided error message)
If there is no some typo, than may be you should look for this property in some other configuration (.properties files, command line arguments and other, see doc for all possible ways)
I'm having a problem on spring cloud configuration 2020.0.3, spring boot 2.4.5 for details:
Yaml configuration file is following Multi-profile YAML documents
I have a configuration yaml file on the config server.
my_cofig.yaml
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
profiles: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"
I have loaded the config from the config server by browser, it's correct.
But:
When I run Spring application with specific configuration (e.g. dev), Spring application must not apply global configuration variables defined on configuration file from configuration server. It only loads dev's configuration variables.
bootstrap.yaml
server:
port: 8081
spring:
application:
name: auth-service
cloud:
config:
enabled: true
fail-fast: true
allow-override: true
profile: dev
uri: http://localhost:5000
Error detail:
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Please help me, many thanks!
spring:
profiles:
This does not exist (it was deprecated if I am not mistaken). Please check the reference documentation.
I believe that what you are looking for is the following (reference documentation):
spring:
datasource:
url: "jdbc:mariadb://localhost:3306/default_db"
driver-class-name: org.mariadb.jdbc.Driver
username: my_db
password: 12345
---
spring:
config:
activate:
on-profile: dev
datasource:
url: "jdbc:mariadb://localhost:3306/dev_db"
Finaly, I solved the problem by upgrading spring boot version to 2.5.1
Thanks all
Having a really annoying issue with my Spring Boot API.
So I have a MySQL db and a MongoDB which I connect to. Everything with the Mysql works fine i.e. the settings from the Application.yaml file but not Mongo. It ignores the Database name and creates its own one called "test". Even if I put in a random host and port it still connects locally. Anyone able to spot what i'm doing wrong?
server:
servlet:
contextPath: /api/v1/
port: 8080
spring:
data:
mongo.database: springboot-rest
mongo.host: localhost
mongo.port: 27017
output:
ansi:
enabled: ALWAYS
datasource:
url: jdbc:mysql://localhost:3306/spring_social?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
username: test
password: test
servlet:
multipart:
max-file-size: -1
max-request-size: -1
jpa:
show-sql: true
hibernate:
ddl-auto: update
naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
EDIT worth noting i also tied this way with no luck either:
spring:
data:
mongo:
database: springboot-rest
host: localhost
port: 27017
output:
ansi:
enabled: ALWAYS
datasource:
url: jdbc:mysql://localhost:3306/spring_social?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
username: test
password: test
mongodb should be there instead of mongo
spring:
data:
mongodb:
database: springboot-rest
I am working on a project integrating Hadoop, Hive and accessing it via Spring.
Currently my project works with a default Spring repository: "org.springframework.data.jpa.repository.support.SimpleJpaRepository#757b7c0a" but I would want to work with a repository able to understand HIVE queries.
For example, inserting a user into a HIVE database.
Actually I have a connection to HIVE in my project but everything is chaos and nothing works and I believe it is because the repository I am using is not the correct one.
So my question is ... how, where and what values to insert in order to change that repository for a Hive-friendly one ?
I have this in my application.yml:
spring:
profiles:
include: swagger, no-liquibase
devtools:
restart:
enabled: true
livereload:
enabled: false # we use gulp + BrowserSync for livereload
datasource:
type: org.springframework.jdbc.datasource.DriverManagerDataSource
url: jdbc:hive2://localhost:10000/default;DB_CLOSE_DELAY=0
username: catalin
password:
default-auto-commit: true
jpa:
show-sql: true
properties:
hibernate:
format_sql: true
mail:
host: localhost
port: 25
username:
password:
thymeleaf:
cache: false
liquibase:
contexts: hive
Thank you.
I've got a working Spring Boot Application that connects to a Postgres database. I've got the project set up with an application.properties file, but would like to make the switch over to an application.yml file. However when I make the switch, my application errors out while attempting to connect to the db.
Original applications.properties file:
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=foo
spring.datasource.password=bar
And Here's what I've got so far in the application.yml file:
spring.jpa:
database: POSTGRESQL
hibernate.ddl-auto: create-drop
show-sql: true
spring.datasource:
platform: postgres
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/mydb
username: foo
password: bar
Am I missing something in the translation between file types?
You need to treat each . character in property names as levels in the yaml file:
spring:
jpa:
database: POSTGRESQL
show-sql: true
hibernate:
ddl-auto: create-drop
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5432/mydb
username: foo
password: bar
driverClassName: org.postgresql.Driver
EDIT: edits have been suggested, thanks for that. The driverClassName property actually should be under spring.datasource. However, the purpose of this answer was to show how a properties file is converted into yaml format. So I have changed the driverClassName property to be at the right path, that is not part of the transformation from properties to yaml.
Please upvote the other answer (Z0lt#n's answer)
But pasting here for future readers... a sql server version.
spring:
jpa:
show-sql: true
hibernate:
ddl-auto: update
properties:
hibernate.jdbc.batch_size: 20
hibernate.cache.use_query_cache: false
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_structured_entries: false
hibernate.cache.use_minimal_puts: false
datasource:
#SPRING_DATASOURCE_URL environment variable will be something like -> jdbc:sqlserver://MySqlServer\\MyInstance:1433;DatabaseName=MyDbName;
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
and maven entry
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>7.0.0.jre8</version>
</dependency>
APPEND
This seems to be the "standard" name for the driverClassName.
SPRING_DATASOURCE_DRIVER-CLASS-NAME
And of course, in my example, you would use the value of:
com.microsoft.sqlserver.jdbc.SQLServerDriver
NOW, some spring, springboot, environment variable voodoo alert.
Sometimes, when specifying the environment variable...for some command lines items, I would have to change the hyphens and make them underscores.
(aka, "SPRING_DATASOURCE_DRIVER-CLASS-NAME" vs "SPRING_DATASOURCE_DRIVER_CLASS_NAME"
below the -e generically represents "passing environment variable values via the command line"
MyCommandLineProgram.exe -e SPRING_DATASOURCE_URL="jdbc:sqlserver://myServerName:1433;DatabaseName=MyDB;" -e SPRING_DATASOURCE_USERNAME="myUserName" -e SPRING_DATASOURCE_PASSWORD="myPassword" -e SPRING_DATASOURCE_DRIVER_CLASS_NAME="com.microsoft.sqlserver.jdbc.SQLServerDriver"
There's some voodoo for you.
Those interested in the logging (logback.xml) issue, maybe want to find my answer here as well:
Spring Boot Logback DB Appender Properties
application.yml file for postgresql
Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring:
datasource:
driver-class-name: org.postgresql.Driver
username: postgres
password: root
url: jdbc:postgresql://localhost/postgres
platform: postgres
initialization-mode: always
continue-on-error: true
jpa:
show-sql: true
generate-ddl: true
hibernate:
ddl-auto: create
database: postgresql
server:
port: 1111
spring:
application:
name: client-one
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=education
username: postgres
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
show-sql: true