Integrate Liquibase Groovy DSL in Spring Boot - spring-boot

Trying to integrate like this:
build.gradle
dependencies {
implementation 'org.liquibase:liquibase-core'
implementation 'org.liquibase:liquibase-groovy-dsl:2.1.1'
runtimeOnly 'com.h2database:h2'
runtime 'org.liquibase:liquibase-core'
runtime 'org.liquibase:liquibase-groovy-dsl:2.1.1'
}
In Spring Boot application.properties
spring.liquibase.changeLog=classpath:db/changelog/changeset0002.groovy
Have a corresponding changeset0002.groovy file under src/main/resources/db/changelog.
While doing gradle bootRun, getting the following exception:
Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

It works. In my application.properties file, with the following setting, I got it working:
spring.liquibase.change-log=classpath:META-INF/scripts/changeset0001.groovy
where the directories META-INF/scripts exist under src/main/resources of my Gradle project structure and changeset0001.groovy is a usual Groovy DSL file.

Related

reactor.netty error when depending on spring-boot-starter-webflux

I have a java project based on Spring framework, which is based on gradle build tool.
The gradle configures a parent project Par and sub-project Child.
The Par project has the build.gradle setting spring framework boot version as 2.2.6:
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
...
}
The Child project has the build.gradle as below:
ext.versions = [
spring: '5.2.9.RELEASE',
spring_boot: '2.2.10.RELEASE',
slf4j: '1.7.30',
grpc_helpers_java: '^19.0'
]
I tried to use WebClient of spring framework, so I added spring-boot-starter-webflux dependency to the build.gradle file of the child project as below:
dependencies {
...
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: versions.spring_boot
...
}
I don't have other code change yet.
However, although the build passed, the bootRun from the Par project failed with the following error:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory.createHttpServer(NettyReactiveWebServerFactory.java:163)
The following method did not exist:
'reactor.netty.transport.Transport reactor.netty.http.server.HttpServer.runOn(reactor.netty.resources.LoopResources)'
The method's class, reactor.netty.http.server.HttpServer, is available from the following locations:
jar:file:/C:/Users/XXX/.gradle/caches/modules-2/files-2.1/io.projectreactor.netty/reactor-netty/0.9.12.RELEASE/41022546d07f1499fb9d8617bba4a1a89d3549db/reactor-netty-0.9.12.RELEASE.jar!/reactor/netty/http/server/HttpServer.class
The class hierarchy was loaded from the following locations:
reactor.netty.http.server.HttpServer: file:/C:/Users/XXX/.gradle/caches/modules-2/files-2.1/io.projectreactor.netty/reactor-netty/0.9.12.RELEASE/41022546d07f1499fb9d8617bba4a1a89d3549db/reactor-netty-0.9.12.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.http.server.HttpServer
I think the transitive dependency reactor.netty has a version of 0.9.12 is correct based on the spring-boot-starter-webflux version of 2.2.10. So I do not understand why the bootRun is trying to look for reactor.netty.http.server.HttpServer.runOn method which doesn't exist for reactor.netty version 0.9.12
Thank you very much.

javax.enterprise.inject.UnsatisfiedResolutionException:Unsatisfied dependency for type com.test.model.TestService and qualifiers [#Default] in Quarkus

I have created Quarkus project and added a SpringBoot project dependency in build.gradle file, dependency downloaded successfully.
Now when I am trying to inject a class which is available in dependancy, the build is getting failed.
Note: The Class which I am trying to inject does not have #ApplicationScope annotation.
getting below error:
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type com.test.model.TestService and qualifiers [#Default]
Look here:
https://quarkus.io/guides/cdi-reference
See the section 1 in the document above about creating the bean archive.
What worked for me is adding references to the dependencies in my application.properties.
quarkus.index-dependency.[name].group-id=[group]
quarkus.index-dependency.[name].artifact-id=[artifact]
For instance, in my project I injected some OpenTracing beans, ended up with:
quarkus.index-dependency.opentracing.group-id=io.opentracing
quarkus.index-dependency.opentracing.artifact-id=opentracing-api

Mapstruct: Consider defining a bean of type ''FooMapper" in your configuration

I'm trying to get Mapstruct working with gradle. The implementations generate and work great when I run the service from the boot dashboard in eclipse, but they don't generate when run with gradlew bootrun, and the bean can't be found. Here is the error:
*************************** APPLICATION FAILED TO START
Description:
Field fooMapper in ServiceImpl required a bean of type 'FooMapper'
that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'FooMapper' in your configuration.
And here is my build.gradle file:
plugins {
id "org.springframework.boot"
id "groovy"
id "com.diffplug.eclipse.apt" version "3.31.0"
}
configurations {
// configuration to enable running bootRun locally
// with embedded h2 database
runlocal
}
ext {
mapstructVersion = "1.5.0.Beta1"
}
dependencies {
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testImplementation "org.testng:testng:6.10", "org.easytesting:fest-assert:1.4"
implementation project(":common")
implementation "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
implementation "org.springframework.boot:spring-boot-starter-validation:$springBootVersion"
implementation "org.codehaus.gpars:gpars:1.2.1"
developmentOnly "org.springframework.boot:spring-boot-devtools:$springBootVersion"
runlocal project(":test-db")
testImplementation project(":test-db")
}
sourceSets.main.groovy.srcDirs += ["build/generated/sources"]
bootRun {
classpath = sourceSets.main.runtimeClasspath + configurations.runlocal
}
tasks.withType(JavaCompile) {
options.compilerArgs = [
"-Amapstruct.suppressGeneratorTimestamp=true",
"-Amapstruct.defaultComponentModel=spring",
"-Amapstruct.verbose=true"
]
}
Is it because my code is written in groovy? But then why would it work with the boot dashboard in eclipse? I am using #Mapper(componentModel = 'spring'), but that hasn't fixed the issue. Using version 1.4.2.FINAL also doesn't work. Any help would be really appreciated!
had the same problem in eclipse, solved configuring my project properties:
Go to:
Java Compiler > Annotation Processing
Set Enable Project specific settings to true
Go to:
Java Compiler > Annotation Processing > Factory Path
Add external jar:
Here find the location of your mapstruct-processor-1.4.2-Final.jar on the gradle cache directory, i am using debian 11, my path is on:
/.gradle/caches/modules-2/files-2.1/org.mapstruct/mapstruct-processor/1.4.2.Final/e55bd90d51cddd638c07d5bd89fc7535d4e3d069/mapstruct-processor-1.4.2.Final.jar
Apply and close, and gradle should rebuild the project, generating two new folders .apt_generated and .apt_generated_tests on the package explorer with the mapper code

Spring Boot 2.0.5 - Activemq 5.14.0 issues with setup logger with gradle

I am getting the following runtime error after adding activemq to my build.gradle.
compile("org.apache.activemq:activemq-all:5.14.0")
I have tried to exclude modules, but that does not seem exclude the logback like I expected. Please advise on what I can do to exclude logback. One other note, this is a kotlin application, however I don't think this is relevant.
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
{
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
Here is the exception:
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/C:/Users/z037640/.gradle/caches/modules-2/files-2.1/org.apache.activemq/activemq-all/5.14.0/858a3bd95d20e7a8949006cdb50a7c362f8825ec/activemq-all-5.14.0.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.slf4j.impl.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext
If you don't want to use logback as a logger, then you just have to exclude it from all configurations , as follows:
configurations.all {
exclude group: "ch.qos.logback"
}
dependencies {
// ... all your dependencies here.
}
In your github project sample: you have declared the exclusion rules in the buildscript block , which is wrong. You need to configure these exclusions outside this block (=> at the same level as repositories or dependencies blocks)
Note the root cause of your logging issue is that both spring-boot and active-mq-all dependencies provide Slf4j binding implementation in their transitive dependencies , so you need to either exclude logback (see solution above) or the implementation from active-mq (which seems more complicated : see https://stackoverflow.com/a/11786595/6899896 )

Issue with maven + surefire-plugin and Spring #Autowired

I have been breaking my head in getting Spring #Autowired to work inside maven tests. When I run the JUnit tests inside IntellJ (did not try Eclipse) it works. But when I run mvn clean install, the JUnit tests fail with the following error
testApp(com.sample.spring.AppTest): Error creating bean with name 'com.sample.spring.AppTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.sample.spring.AppB com.sample.spring.AppTest.appB; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.sample.spring.AppB] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
I have created a self contained sample project that exhibits this behaviour consistently. I am using Spring 3.1.1. I am sure someone faced the same issue and cracked it. Looking for some pointers regarding this issue.
This is a build path issue:
Working in eclipse I changed your ContextConfiguration to :
#ContextConfiguration(locations = "classpath:applicationContext.xml")
and it runs both with standard eclipse runner and maven(maven test or maven install).
Make sure you have:
src/main/java
src/test/java and
src/test/resources
declared as source folders in your buildpath

Resources