Spring Boot Flyway AutoConfiguration - spring-boot

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.

Related

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

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

In spring-boot 2.6.2 Could not initialize Logback logging from classpath:logback-spring.groovy

I migrated my spring boot app for spring-boot 2.5.6 to spring-boot 2.6.2, but since then the start up tells
java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-spring.groovyCaused by: ch.qos.logback.core.LogbackException:
Caused by: ch.qos.logback.core.LogbackException:Unexpected filename extension of file [file:/xyz/out/production/resources/logback-spring.groovy]. Should be either .groovy or .xml
Can someone help if you have a solution?
Thanks
Logback 1.2.9 dropped the support for Groovy.
You can either migrate your logback.groovy to logback.xml or downgrade the logback version to 1.2.7 (logback.version=1.2.7) and see if they’ll come around and support Groovy again (which they might).

Wildcard locations cannot work in spring boot 2.4.1

Wildcard locations cannot work in spring boot 2.4.1
java -Dspring.config.additional-location=/work/*/ -jar test.jar
Error:
java.lang.IllegalStateException: Location '/work/*/' must not be a pattern
What should we do to solve this probelm?
It should be this:
java -Dspring.config.additional-location=/work/**

Unit tests print exception after upgrading liquibase to 3.2.2

I have a spring boot/liquibase app and after upgrading liquibase to 3.2.2 unit tests starts to print this exception, but tests still pass:
[WARN] liquibase - Error initializing SpringLiquibase
java.io.FileNotFoundException: ServletContext resource [/] cannot be resolved to URL because it does not exist
at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:156) ~[spring-web-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.init(SpringLiquibase.java:74) [liquibase-core-3.2.2.jar:na]
at liquibase.resource.AbstractResourceAccessor.(AbstractResourceAccessor.java:19) [liquibase-core-3.2.2.jar:na]
at liquibase.integration.spring.SpringLiquibase$SpringResourceOpener.(SpringLiquibase.java:64) [liquibase-core-3.2.2.jar:na]
at liquibase.integration.spring.SpringLiquibase.createResourceOpener(SpringLiquibase.java:388) [liquibase-core-3.2.2.jar:na]
at liquibase.integration.spring.SpringLiquibase.createLiquibase(SpringLiquibase.java:349) [liquibase-core-3.2.2.jar:na]
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:300) [liquibase-core-3.2.2.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613) [spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550) [spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
at ...
Spring Boot doesn't support Liquibase 3.2.2 at the moment. I haven't seen the exact error that you've posted in the question, but I suspect it's another symptom of the incompatibilities between Liquibase 3.0.x and 3.2.x.
To be safe, you should stick with Liquibase 3.0.x for now, although I believe that 3.1.x may work as well.
There's an open Spring Boot issue describing some of the problems with 3.2.x. There's also an open Spring Boot pull request that provides compatibility with Liquibase 3.2.x. It's scheduled for inclusion in Spring Boot 1.2 which is due for release in Novemeber.

Grails 1.2.1 with Spring 3.0.0 dependency problem under Jetty

Just moved to Grails 1.2.1 (used 1.1.1 before). Changed application.properties, ran grails upgrade, fixed BuildConfig and Bootstrap - everything works just fine from grails console.
However, getting a problem when deploy packaged war under jetty 6.1.22:
1581 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.setParameterNameDiscoverer(Lorg/springframework/core/ParameterNameDiscoverer;)V
My project is built with maven2. I researched the war dependencies and see that both spring 2.5.6 and 3.0.0.RELEASE are used there.
I then tried to suppress use of spring 2.5.6 and got a problem with Acegi plugin (using version 0.5.1):
2010-03-10 21:06:56.440:WARN::Nested in org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is java.lang.NoSuchMethodError: org.springframework.web.context.ConfigurableWebApplicationContext.setId(Ljava/lang/String;)V
Any help would be greatly appreciated.
The problem is caused by the fact that in new version of Spring
ConfigurableWebApplicationContext is located in spring-web.jar, but the interface it inherits ConfigurableApplicationContext, which contains setId(String) method is in located in spring-context.jar.
If you have a library which has been compiled against older version of spring-context it will fail with NoMethodFound exception.
The solution is to locate and recompile that library against latest Spring version.
If you are using Spring version below 3.0 you could try to put full Spring bundle Jar instead of separate packages.

Resources