I'm migrating a small java 8 Spring-Boot 2.1.0 project to Java 17 with Spring-Boot 2.6.3
The project uses RabbitMQ and is basically a serializer-deserializer.
The problem I'm encountering is that I cannot run the application because it fails to initialize this bean:
#Autowired
private ConnectionFactory connectionFactory;
#Bean
public IntegrationFlow fromDocToLDocFlow(AmqpTemplate amqpTemplate) {
return IntegrationFlows
.from(DOCUMENT_ROUTE)
.handle(Amqp.outboundAdapter(amqpTemplate).routingKey(documentBinding).exchangeName(documentExchange))
.get();
}
And the exception I get is this:
Error creating bean with name 'fromDocToLDocFlow.amqp:outbound-channel-adapter#0' defined in class path resource [publisher/config/IntegrationFlowConfiguration.class]: Invocation of init method failed;
nested exception is java.lang.IncompatibleClassChangeError: Expecting non-static method 'java.lang.Object org.springframework.integration.context.IntegrationObjectSupport.extractTypeIfPossible(java.lang.Object, java.lang.Class)'... 14 common frames omitted
Caused by: java.lang.IncompatibleClassChangeError: Expecting non-static method 'java.lang.Object org.springframework.integration.context.IntegrationObjectSupport.extractTypeIfPossible(java.lang.Object, java.lang.Class)'
at org.springframework.integration.amqp.outbound.AbstractAmqpOutboundEndpoint.doInit(AbstractAmqpOutboundEndpoint.java:409) ~[spring-integration-amqp-5.1.0.RELEASE.jar:5.1.0.RELEASE]
... 26 common frames omitted
Here is my gradle configuration:
buildscript {
ext {
springBootVersion = '2.6.3'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.group'
sourceCompatibility = 17
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-amqp')
implementation('org.springframework.boot:spring-boot-starter-integration')
implementation("org.springframework.integration:spring-integration-feed:5.1.0.RELEASE")
implementation("org.springframework.integration:spring-integration-amqp:5.1.0.RELEASE")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.1")
implementation("org.apache.commons:commons-lang3:3.12.0")
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testImplementation("junit:junit")
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('commons-io:commons-io:2.11.0')
}
Compiled dependencies:
Gradle: org.springframework.amqp:spring-rabbit:2.4.22
Gradle: org.springframework.amqp:spring-amqp:2.4.22
Gradle: org.springframework.boot:spring-boot:2.6.32
Gradle: org.springframework.retry:spring-retry:1.3.1
Related
I need to convert this gradle-java (gradle 6.3, java 8, camel 3.4.2),
plugins {
id 'java-library'
}
repositories {
jcenter()
}
dependencies {
compile group: 'org.apache.camel', name: 'camel-rest', version: '3.4.2'
}
To this (gradle 7.3.3, java 8, camel 3.14.3 springboot 2.7.0),
plugins {
id 'java-library'
id 'org.springframework.boot' version '2.7.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
}
repositories {
mavenCentral()
}
targetCompatibility = '1.8'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.camel:camel-rest::3.14.3'
}
But I get this error,
What went wrong:
Execution failed for task ':compileJava'.
Could not resolve all files for configuration ':compileClasspath'.
Could not find org.apache.camel:camel-rest:.
Required by:
What should I do?
Thanks
Ric
The double colon,
:camel-rest::3.14.3'
What I'm trying to do is to extract all of spring-boot-starters to a separate app, pack all of it into a single JAR (using gradle shadow plugin) and then deploy it to local nexus artifacts repository, so I can import it and all of its dependencies to my spring boot application.
Here is build.gradle of app that contains spring-boot-starters:
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
mavenCentral()
jcenter()
maven {
url "http://localhost:8081/repository/testowe/"
credentials {
username 'admin'
password 'admin123'
}
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
subprojects {
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
version = '1.0'
sourceCompatibility = 1.11
jar { enabled = true }
shadowJar { classifier(null) }
repositories {
jcenter()
mavenCentral()
maven {
url "http://localhost:8081/repository/testowe/"
credentials {
username 'admin'
password 'admin123'
}
}
}
publishing {
publications {
shadow(MavenPublication) { publication ->
project.shadow.component(publication)
}
}
repositories {
maven {
url "http://localhost:8081/repository/testowe/"
credentials {
username 'admin'
password 'admin123'
}
}
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web') {
transitive = true
}
compile('org.springframework.boot:spring-boot-starter-actuator') {
transitive = true
}
compile('org.springframework.boot:spring-boot-starter-data-jpa') {
transitive = true
}
compile('org.springframework.boot:spring-boot-starter-security') {
transitive = true
}
compile('org.springframework.boot:spring-boot-starter-test') {
transitive = true
}
}
}
Here is build.gradle of spring-boot app that I want to run with all spring-boot-starter dependencies coming from built JAR:
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 11
repositories {
mavenCentral()
maven {
url "http://localhost:8081/repository/testowe/"
credentials {
username 'admin'
password 'admin123'
}
}
}
dependencies {
// When I'm running app with starters placed here everything works fine
// implementation('org.springframework.boot:spring-boot-starter-data-jpa')
// implementation('org.springframework.boot:spring-boot-starter-security')
// implementation('org.springframework.boot:spring-boot-starter-test')
// implementation('org.springframework.boot:spring-boot-starter-web')
// When I'm trying to run it with my JAR it doesn't work
implementation("pl.mplan:web-common:1.0")
compile group: 'org.javassist', name: 'javassist', version: '3.23.2-GA'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
runtimeOnly('org.postgresql:postgresql')
compileOnly('org.projectlombok:lombok')
testImplementation('org.springframework.boot:spring-boot-starter-test')
compile("com.querydsl:querydsl-core:4.2.1")
compile("com.querydsl:querydsl-jpa:4.2.1")
compile("com.querydsl:querydsl-apt:4.2.1:jpa")
}
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("$projectDir/generated/java")
}
idea {
module {
sourceDirs += file("$projectDir/generated/java")
}
}
When I'm trying to run app with gradle bootRun task here's what I get:
17:55:32.169 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'objectPostProcessor': [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration]
17:55:32.169 [main] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy() on bean with name 'objectPostProcessor'
17:55:32.175 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
at pl.mplan.brew.it.BrewItBackendApplication.main(BrewItBackendApplication.java:12)
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152)
... 8 common frames omitted
(I'm using gradle 4.8 and shadow plugin 4.0.4)
Any ideas how to fix it? Thanks in advance!
I am trying to setup AWS Polly Java SDK with Gradle in IntelliJ by following this. I have already created a simple Spring Boot application using the spring intializr, so I added the items specified in the tutorial to my build.gradle file. When try to import
import com.amazonaws.services.polly.AmazonPollyClient
IntelliJ fails to resolve name polly.
This is my full build.gradle file
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.ai.vivid'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'com.amazonaws:aws-java-sdk-s3'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Also IntelliJ complains that it can't resolve the name manvenBom in my build.gradle. I have already tried SO solutions to this like invalidate cache/restart but could not resolve the issue.
I used your build.gradle file to replicate the issue and was able to import AmazonPollyClient after making the following changes to the dependencies
dependencies {
compile 'com.amazonaws:aws-java-sdk-s3'
compile group: 'com.amazonaws', name: 'aws-java-sdk-polly', version: '1.11.67'
The Gradle version used 4.8
I started to learn Spring Framework as my first ever app.I tried to get defined Beans count but i can't run it.
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class runDemo {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext();
System.out.println(context.getBeanDefinitionCount());
}
}
and my gradle file
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
and when i run this:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext ...
I have spring context and spring core in the External Libraries loaded.
EDIT:I upgraded to Intellij idea 2017.2 and it still give the same error
i replaced
compile('org.springframework.boot:spring-boot-starter')
with
compile('org.springframework.boot:spring-boot-starter-web')
I'm trying to write a junit test for my first java project using Spring framework. I have searched online how to include the dependency in order to use it but keep encountering this warning:
Cannot resolve symbol 'SpringRunner'
in intelliJ IDEA. So what is missing?
Here is my dependency file for gradle.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle- plugin:1.5.1.RELEASE")
classpath("org.springframework:spring-test:4.0.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
testCompile("org.springframework:spring-test:4.0.3.RELEASE")
compile('com.google.maps:google-maps-services:0.1.18')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('junit:junit:4.12')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("org.springframework.security:spring-security-test")
}
try adding org.springframework.test.context.junit4.SpringRunner;