I'm trying to disable autocommit, but I'm not lucky. I'm using the Spring Boot version 2.1.3.RELEASE
application.properties
spring.jpa.database=oracle
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
spring.jpa.generate-ddl=false
spring.jpa.open-in-view=true
spring.jpa.show-sql=false
spring.datasource.hikari.auto-commit=false
Use
spring.datasource.auto-commit=false
This property (and some more too) were not documented.
Please refer below github issue for more undocumented properties.
https://github.com/spring-projects/spring-boot/issues/1829
Related
I made a project from scratch just with the schema.sql and the data.sql just to try the schema.sql and the data.sql:
https://github.com/rmmcosta/TestSchema
Everything works fine. The table inside schema.sql is created in a MySql database (previously created and the grants were given to the user defined in application.properties) and the data.sql populates the data as it's supposed to do.
But, when I change schema.sql and data.sql to schema-mysql.sql and data-mysql.sql and I put in the application.properties the property spring.datasource.platform=mysql the schema-mysql.sql and the data-mysql.sql are not being executed.
No errors are being thrown, simple nothing happens on the database.
I tried with spring boot 2.2.4 and it works fine, but with spring boot 2.7.5 it isn't working.
Do you know if the spring.datasource.platform was deprecated? And if so, do you know how can I set the application.properties in order to run schema-mysql.sql?
Thank you in advance,
Ricardo
Note:
I tried without using spring.datasource.platform=mysql and with schema.sql and data.sql and everything works fine.
I tried with an old project, spring boot 2.2.4 and java 1.8, and works fine.
Do you know if the spring.datasource.platform was deprecated? And if so, do you know how can I set the application.properties in order to run schema-mysql.sql?
The property name changed to spring.sql.init.platform
https://github.com/spring-projects/spring-boot/blob/d870474fcd4899fac94d51311c4163832d6b109d/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json#L1148
Which occurred in Spring Boot 2.5: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5.0-RC1-Configuration-Changelog
You need to use spring.sql.init.platform instead of spring.datasource.platform property in application.properties.
Please see the comment from latest documentation -
In addition, Spring Boot processes the schema-${platform}.sql and
data-${platform}.sql files (if present), where platform is the value
of spring.sql.init.platform
When I was working on a Spring Boot application that used scheduling and acted as a config client, I was unable to pull the crontab expression from the application-cloud.yml file.
This:
#Scheduled(cron = "${cron.expression}")
did not work.
Putting the cron.expression in the jar's internal application.yml was not an option. As a workaround, I changed the source of that property to the appropriate environment variable, CRON_EXPRESSION.
Does anyone know why I had to do that? Why was Spring Scheduled unable to resolve an externalized configuration property?
Edit:
Here is the bootstrap.yml that the project was setup with:
spring:
profiles: cloud
application:
name: application-name
cloud:
config:
uri: https://config-server.com
fail-fast: false
I want to have Liquibase configured with my Spring Boot application, so I added dependencies to pom.xml and set the path to master.xml in application.properties. This works fine and Spring Boot runs Liquibase at startup. The problem is that now I want to run Liquibase manually, not at startup of application. Should I completely disable auto-configuration for Liquibase or can I use it and only disable running evaluations at startup?
The relevant property name has changed between Spring versions:
For Spring 4.x.x: the liquibase.enabled=false application property disables Liquibase.
For Spring 5.x.x: the spring.liquibase.enabled=false application property disables Liquibase.
P.S. And for Flyway:
Spring 4.x.x: flyway.enabled=false
Spring 5.x.x: spring.flyway.enabled=false
Add liquibase.enabled=false in your application.properties file
Reference
But if you don't want to use liquibase from application anymore, remove liquibase starter altogether from pom.
If you see on the LiquibaseProperties, there is a prefix like
prefix = "spring.liquibase"
So, My suggestion is to use
spring.liquibase.enabled=false
It solved my problem with spring boot 2.0.0.RC1
I faced an issue where I wasn't able to disable Liquibase from properties for some reason, so this is how I disabled Liquibase with #Bean annotation:
#Bean
public SpringLiquibase liquibase() {
SpringLiquibase liquibase = new SpringLiquibase();
liquibase.setShouldRun(false);
return liquibase;
}
There is one more programmatic approach.
#EnableAutoConfiguration(exclude = LiquibaseAutoConfiguration.class)
on Application main class
If you want to run Liquibase manually, you could use the liquibase maven plugin. Just add something like this to your pom.xml:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<changeLogFile>src/main/liquibase/master.xml</changeLogFile>
<propertyFile>src/main/liquibase/liquibase.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
You can take a look at the plugin documentation for the configuration details.
And don't use the liquibase support from Spring Boot, as it is only meant to be used in runtime. Just remove the liquibase starter and/or any related dependencies as you'll only need the maven plugin.
You can use the spring.liquibase.enabled=true/false
Whilst the documented Spring Boot solution is spring.liquibase.enabled=false, it didn't work for me. To disable liquibase you can also use the following property:
liquibase.shouldRun=false
I passed this as a command line parameter when launching the Spring Boot jar
-Dliquibase.shouldRun=false
see https://docs.liquibase.com/parameters/should-run.html
Is there anything special to say to Springboot to take in account as configuration yaml files instead the properties files? I'm using Maven and Springboot in a project, if I place the file application.properties in the resources file the configuration is automatically recognised by Springboot.
However just replacing the properties file by a yml file does not work, the file is not taking in account anymore.
Anything to add to splicitely say to SpringBoot to use the yml files?
Below both files:
application.properties:
# THYMELEAF (ThymeleafAutoConfiguration)
spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=/WEB-INF/views/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
and application.yml
spring:
profiles:
active: ${dario.environment:dev}
thymeleaf:
check-template-location: true
thymeleaf.prefix: /WEB-INF/views/
thymeleaf.suffix: .html
thymeleaf.mode: LEGACYHTML5
spring.thymeleaf.encoding: UTF-8
spring.thymeleaf.content-type: text/html
cache: false
If you refer to the section 'Using YAML instead of Properties' in the Spring Boot reference documentation, it says that Spring Boot should pick it up automatically given you have the SnakeYAML library on your classpath.
Having that said, it also states
If you use ‘starter POMs’ SnakeYAML will be automatically provided via
spring-boot-starter
I am using spring cloud to bind services to a spring boot application deployed to CloudFoundry. When running locally, I can pass Java options to the application as follows:
-Dspring.jpa.hibernate.ddl-auto=create-drop
Now I would like to do the same thing when running the application on CloudFoundry. What's the usual way to do this?
An alternative to setting a system property or environment variable is to set this as a Spring property in src/main/resources/application.properties or src/main/resources/application.yml.
application.properties:
spring.jpa.hibernate.ddl-auto=create-drop
application.yml
spring:
jpa:
hibernate:
ddl-auto: create-drop
With this approach, the configuration will be applied regardless of now the app is deployed - locally, on CF, or on another platform.
You can put an env entry in your manifest.yml file like so:
env:
spring.jpa.hibernate.ddl-auto: create-drop
See more information here:
http://docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#env-block