Spring integration uncompatibility with Spring boot - spring

I have this pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
</parent>
<groupId>com.example</groupId>
<artifactId>example-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<paho.version>1.2.5</paho.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jmx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mqtt</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.mqttv5.client</artifactId>
<version>${paho.version}</version>
</dependency>
</dependencies>
</project>
I'm getting this error:
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor.registerErrorChannel(DefaultConfiguringBeanFactoryPostProcessor.java:210)
The following method did not exist:
'org.springframework.beans.factory.support.BeanDefinitionBuilder org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition(java.lang.Class, java.util.function.Supplier)'
The method's class, org.springframework.beans.factory.support.BeanDefinitionBuilder, is available from the following locations:
jar:file:/Users/user/.m2/repository/org/springframework/spring-beans/5.2.15.RELEASE/spring-beans-5.2.15.RELEASE.jar!/org/springframework/beans/factory/support/BeanDefinitionBuilder.class
The class hierarchy was loaded from the following locations:
org.springframework.beans.factory.support.BeanDefinitionBuilder: file:/Users/user/.m2/repository/org/springframework/spring-beans/5.2.15.RELEASE/spring-beans-5.2.15.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.beans.factory.support.BeanDefinitionBuilder
I really couldn't figure out which combination of versions of spring boot parent and spring boot integration will make this work.
Thanks!
EDITED:
I change pom.xml to use version 2.3.12.RELEASE of spring boot parent and I removed the version tag of spring-integration-mqtt, but I'm still having the same error.
I have the following dependency tree when I execute mvn dependency:tree -Dincludes="org.springframework:spring-beans":
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) # example-app ---
[INFO] com.example:example-app:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:2.3.12.RELEASE:compile
[INFO] \- org.springframework:spring-web:jar:5.2.15.RELEASE:compile
[INFO] \- org.springframework:spring-beans:jar:5.2.15.RELEASE:compile

The Spring Boot version 2.3.x is out of support for a while: https://spring.io/projects/spring-boot#support.
Consider to choose the latest and rely on dependency management from Spring Boot by itself: don't use explicit versions for those dependencies which can borrow it from Spring Boot.
The org.eclipse.paho.mqttv5.client will not work with that old Spring Integration version anyway. You have to use at least Spring Boot 2.6.8 to pull Spring Integration 5.5.12.

Related

Compilation Failure : cannot access LoggingEventAware [ERROR] class file for org.slf4j.spi.LoggingEventAware not found on mvn clean install -U

I have upgraded the spring boot version from 2.3.5 to 2.7.5 , resolved most of the dependency versions. But when i do the maven clean install , i received the compilation failure error : cannot access LoggingEventAware
[ERROR] class file for org.slf4j.spi.LoggingEventAware not found
But i do not see any error in the java file - LoggingConfiguration.java.
When i just do reload of project to resolve all the dependencies - it gives error for maven plugin : Cannot resolve plugin org.apache.maven.plugins:maven-release-plugin:3.1.1
I am not sure what is the issue. I have tried to restart IntelliJ after invalidate cache and also cleared the .m2 repository .Nothing helps. Please suggest your inputs how to resolve the same.
Here is the sample pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-release-plugin.version>3.1.1</maven-release-plugin.version>
<maven-scm-provider-gitexe.version>1.9.5</maven-scm-provider-gitexe.version>
<junit.platform.version>4.13.0</junit.platform.version>
<logback-json-classic>0.1.5</logback-json-classic>
<logback-jackson.version>0.1.5</logback-jackson.version>
</properties>
</project> ```
While updating a project to Spring Boot 3.0.1, I came across the same issue.
Here is what worked for me:
Exclude logback-classic sub-dependency of spring-boot-starter-web.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
Add an earlier dependency of logback with version 1.2.11
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>

How to attach Spring source for java 11

I am having a difficult time attaching Spring 5.3.x source code in eclipse.
I tried multiple ways one of them was to add a source to Java build path. However, I am not able to find the spring 5.3.x source code itself.
I have searched the official spring site - https://spring.io/blog/2018/10/30/spring-boot-2-1-0
on git too https://github.com/spring-projects
none of them has source code.
Another was to Right-click on the project -> maven -> Download Sources. It started updating the project however I still don't see the source code.
Can anyone help me solve this?
Your current java runtime in eclipse seems to be jdk8.
Go to Eclipse -> Preferences -> Java -> Installed JREs and switch to JDK11.
Then delete the project and reimport it again.
There might be some other issues in your project, after you switch to JDK11, but in this case I would need more information, including your pom.xml.
Also, check your project outside the eclipse, with command-line: "mvn clean install". Make sure that it compiles successfully, before importing it to eclipse. Make sure your JAVA_HOME points to JDK11
Here is the example of pom.xml for JDK11 Spring Boot 2.4.2 project. Compare it with your own pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>skyglass</groupId>
<artifactId>notepad</artifactId>
<version>1.1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>notepad</name>
<description>Notepad demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
.....
If nothing else helps, try to clean your local maven repository.
Deleting folder m2/repository/org/springframework should be enough

SpringBoot app shows Whitelabel Error Page while serving JSP from JAR

I am exploring how JSPs can be served from JAR file. I'm using SpringBoot 1.5.10.RELEASE
I referred this & this examples and was able to create spring boot app which
includes JSPs at location src/main/resources/META-INF/resources/WEB-INF/jsp/
view resolver has prefix as /WEB-INF/jsp/ and suffix as .jsp
Strange thing is when I ran project as springboot app or Java App, I was able to hit the controller and got desired JSP file as response. After that I thought of packaging the app and then running it from JAR.
$ mvn package
$ java -jar target/springboot-web-jar-demo-0.0.1-SNAPSHOT.jar
Spring boot app comes up, when I hit the same URL pattern, control comes in the mapped method but after that...
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Feb 28 21:01:09 IST 2018
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/index.jsp
My problem/question...
Is there any major difference between the springboot app runs in IDE and when it runs as JARs, which can even cause 404?
Does spring boot 1.5.10.RELEASE support serving JSPs from JAR? (if yes then what I'm missing here, if no then where it is mentioned) - stackoverflow-link
I have tried searching proper solution or answer to my problem but didn't get any. Hence posting the question here please help.
Note:
Please don't provide solution for WAR packaging
I know JSP are not best choice nowadays, I'm just learning
I'm aware that I can look for alternatives like thymeleaf, freemarker and velocity
I don't want to downgrade the SpringBoot version
I've also tried specifying <scope> of jasper & JSTL to provided and compile but no luck
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atuldwivedi.learn.springboot</groupId>
<artifactId>springboot-web-jar-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>springboot-web-jar-demo</name>
<description>Learn how to serve JSP from JAR</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
For you spring boot recognize their jsps, you debt create a webapp directory in src.main like this:
src/main/webapp/WEB-INF/jsp
and not like:
src/main/resources/META-INF/resources/WEB-INF/jsp
for dispatcherServelet recognize their jsps, you create a webapp directory in src.main like this:
src/main/webapp/WEB-INF/jsp
and also autoconfigure your application in application.properties
spring.mvc.view.prefix:/WEB-INF/jsp
spring.mvc.view.suffix:.jsp`
JSPs are not supported when using an executable jar.

Custom spring boot starter for specifying distribution management

We have a spring boot application which has its parent defined as spring-boot-starter-parent. But in our project, we have a parent pom with distribution management defined in it, and all the submodules in the project inherit from it. Now, since the spring boot application already inherits from spring-boot-starter-parent, and I do not want to duplicate the distribution management, I thought of having a custom spring boot starter module just to be able to define the distribution management in there and then include this custom spring boot starter as a dependency in the spring boot application. But when I do a mvn clean install deploy of the spring boot application it fails with the error shown below:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.
2:deploy (default-deploy) on project crs-acc-eve-gridgain-load-app: Deployment f
ailed: repository element was not specified in the POM inside distributionManage
ment element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help
1]
Is it the right way to achieve this? or there any other recommended ways of doing it?
Given below are the poms of custom spring boot starter parent module:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>crs-micro-services</artifactId>
<groupId>com.ing.crs</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>crs-spring-boot-starter-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>1.3.5.RELEASE</spring-boot.version>
</properties>
<modules>
<module>crs-spring-boot-starter</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
<repository>
<id>XXXX</id>
<name>XXXX</name>
<url>XXXX</url>
</repository>
<snapshotRepository>
<id>XXXX</id>
<name>XXXX</name>
<url>XXXX</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
</project>
And this..for the starter module
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>crs-spring-boot-starter-parent</artifactId>
<groupId>com.ing.crs</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>1.0-SNAPSHOT</version>
<artifactId>crs-spring-boot-starter</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
</project>
And the sprng boot application has this dependency
<dependency>
<groupId>com.ing.crs</groupId>
<artifactId>crs-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
</dependency>
Thanks and regards,
Priya
There is no requirement that your build should be configured with the spring-boot-starter-parent. If you already have a parent with some distribution management, feel free to keep it. You'll need to adapt the parent a bit. Here are couple of options:
If the whole project is spring boot based, maybe your parent could inherit from the Spring Boot starter parent? This may not work if you have a parent that is used within the entire organization
You can keep your parent as it is and use the spring-boot-dependencies BOM instead. See the documentation for more details. You'll have to copy the bits of the parent that you use (such as the plugin definition) but it's not a ton of work.
Your proposal will never work. BOM only imports <dependencyManagement>. What you're looking for is mixin and it's not supported by Maven yet.

Overrriding spring version in Spring boot/ spring cloud

I note that with spring cloud Angel.SR3 which uses Spring Boot 1.2.4, the spring version loaded is 4.1.6.RELEASE.
There is a memory leak issue in the yaml processor that I read was fixed in spring 4.1.7.RELEASE.
Specifically addressed in this https://jira.spring.io/jira/secure/ReleaseNote.jspa?projectId=10000&version=14936 ([SPR-13173] - YAML Processor leaves StreamDecoder open)
I tracked through and saw that the starters use ${spring.version} to specify the spring version to be used.
I tried overriding by adding 4.1.7.RELEASE to my properties, but it still loads the 4.1.6 version
Anyway I can do this? I understand that these are curated but this particular memory leak is causing us a lot of issues.
As requested I have attached the front part of the pom. All base dependencies are pulled in through the spring cloud parent. I noticed that they use ${spring.version} to define the correct value of spring. I attempted to override it via a property setting. At no time in the rest of the my pom do I explicitly bring in any of the spring framework libs. The parent pom does that.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.libertas.vipaas</groupId>
<artifactId>vipaas-starter</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>Vipaas Starter</name>
<description>Vipaas Starter</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Angel.SR3</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.javadoc.skip>true</maven.javadoc.skip>
<spring.version>4.1.7.RELEASE</spring.version>
..... other stuff ...
</properties>
... other stuff as not relevant ....
Using dependencyManagement it should work:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
You can check it with:
mvn help:effective-pom | grep -A1 "artifactId>spring-context"

Resources