Spring Boot Data Starter cannot automatically generate DDL with invalid liquibase configuration - spring-boot

I'm using spring-boot-starter-data-jpa:2.0.2.RELEASE. The database is H2 (embedded).
I have defined some #Entity classes in my #SpringBoot application. spring.data.generate-ddl is turned on and spring.data.hibernate.ddl-auto is create-drop. However, on application startup, the following exception occurred:
Caused by: java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.yaml] (please add changelog or check your Liquibase configuration)
Only after I added the liquibase changelog could the application start and database work properly. Why would this happen? Shouldn't Spring Boot already take care of the DDL? How should I configure my Spring Boot app to remove the step to write db changelogs?
application.properties:
server.port=8888
logging.level.root=INFO
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.h2.console.settings.web-allow-others=true
dependencies:
compile "org.springframework.boot:spring-boot-starter-web:$spring_boot_version"
compile "org.springframework.boot:spring-boot-starter-security:$spring_boot_version"
compile "org.springframework.boot:spring-boot-starter-data-jpa:$spring_boot_version"
compile 'com.h2database:h2:2.1.210'
compile 'io.springfox:springfox-boot-starter:3.0.0'

So, thanks to the hint from #htshame, the cause is dependency leak from other modules in my project. According to spring's documentation, the migration is automatically run when spring-boot-starter-liquibase is present (Although I'm not depending on spring's liquibase solution directly, there are liquibase packages leaked out)
To disable liquibase, in application.properties, add:
spring.liquibase.enabled=false

Related

Spring boot logging.file.max-size not working

I've following configuration in Spring boot application.properties file. The log is getting generated but not rolling after 1 MB.
logging.level.root=INFO
logging.file=C:/logs/Application.log
logging.file.max-size=1MB
logging.file.max-history=10
logging.pattern.rolling-file-name=Application-%d{yyyy-MM-dd}.%i.log
I test on my local and found rolling file is made at application running directory.
So I think following will work as expected.
logging.file.name=C:/logs/Application.log
logging.pattern.rolling-file-name=C:/logs/Application-%d{yyyy-MM-dd}.%i.log
I tested with spring-boot version 2.4.1
Problem solved after commenting below lines. Earlier I used log4j2 so for that I had to exclude default logging provided by spring-boot. In order to use logback we need to make sure spring-boot-starter-logging is enabled.
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile.exclude module: 'spring-boot-starter-logging'

gradle build fails from terminal for lombok annotation in spring boot application

I am trying to generate war of spring boot application and using lombok for getter setter. Running gradle build command from terminal and getting error in all getter setter and constructors ie. can not find symbol. I am using STS and able run project successfully from sts. but from command line it throws 100s of errors. I have lombok dependency in gradle file.
Please help me to resolve this issue.
Thanks
It seems you need to set preprocessor for annotations in your build.gradle file. In STS or IntelliJ, the IDEs provide preprocessing for annotations. However when you want to build via command, you need to specify it in the build.gradle config.
dependencies {
annotationProcessor("org.projectlombok:lombok")
compileOnly("org.projectlombok:lombok")
}
Hope it helps! Happy Coding. :)

Spring Boot Flyway AutoConfiguration

Hy,
I'm using Spring Boot 1.5.7RELEASE with Flyway 4.2.0.
I have a problem with the configuration of the flyway.locations property for file system locations.
If I use file: prefix, I have Flyway error:
Caused by: org.flywaydb.core.api.FlywayException: Unknown prefix for location (should be either filesystem: or classpath:):
If I use filesystem: prefix, I have
Caused by: java.lang.IllegalStateException: Cannot find migrations location in:
What am I doing wrong ? (If I use classpath: everything is ok)
This appears to be a bug with FlywayAutoConfiguration in Spring Boot.
A workaround is to use the filesystem: prefix but disable location checking:
spring.flyway.check-location=false # spring boot 2.0.x
flyway.check-location=false # spring boot 1.5.x
I have raised an issue and submitted a PR.
Update
The fix was merged into Spring Boot 1.5.15 and 2.0.4.

Why isn't this jar packaging valid for Spring Boot?

I am trying to understand the packaging of Spring Boot into "fat" jars. From what I know "fat" jars have their own special classes that load up the main class when the jar is running and also sets the classpath accordingly.
What I cannot understand is why when I use Eclipse to extract all my dependencies into a folder structure in the jar, the jar no longer runs as a correct Spring Boot application.
To repeat what I have done here just take a simple Spring Boot app and from Eclipse select the following-:
Export --> Runnable Jar --> Select Main Class --> Extract required libraries into jar.
Just run the jar from the command line as you would any jar. Spring Boot initially starts up but fails with the following message-:
2017-05-02 22:06:40.484 WARN 3468 --- [ main]
ationConfigEmbeddedWebA pplicationContext : Exception encountered
during context initialization - cancel ling refresh attempt:
org.springframework.beans.factory.BeanDefinitionStoreExcep tion:
Failed to process import candidates for configuration class
[com.main.Test Main]; nested exception is
java.lang.IllegalArgumentException: No auto configuration classes
found in META-INF/spring.factories. If you are using a custom packa
ging, make sure that file is correct.
Can I somehow edit the spring.factories file to include my classses ?
I just trying to understand how Spring actually packages the files through its Maven plugin.
I think that because it's a Spring Boot application, you need to use their plugin for building. It is because, spring Boot has its own jar loading mechanism for that (the BOOT-INF introduction in Spring Boot 1.4).
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
From documentation:
The Spring Boot Maven Plugin provides Spring Boot support in Maven, allowing you to package executable jar or war archives and run an application “in-place”.
Link to documetantion (Appendix E)
Something about spring.factories and locating auto-configuration candidates - Auto-configuration

How to use spring-boot integrated liquibase

I would like to use spring-boot integrated liquibase, maven project application configuration file and pom.xml should be how to configure? Please advise.
You can find integration examples at this GitHub Project
just add liquibase dependancy in your pom.xml - the schema update will be launched automatically at startup of your application.
By default your master changelog is located in db/changelog/db.changelog-master.[json|xml|yml] as resource

Resources