I am trying to convert one of our existing maven projects to spring boot. I dont have any compile errors in my project but when I try to run it I get the following error:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.MultiValueMap.addAll(Ljava/lang/Object;Ljava/util/List;)V
at org.springframework.core.io.support.SpringFactoriesLoader.loadSpringFactories(SpringFactoriesLoader.java:140)
at org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(SpringFactoriesLoader.java:119)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:418)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:266)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:247)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
at com.myorg.MyMainClass ...
My POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>couple of our other internal projects</groupId>
**One of these projects is using spring-context and spring-orm** dependencies.
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Since the spring dependencies in my own project are declared before the other projects I would have thought it would override any of those transitive dependencies.
I have wasted an entire day on this. Can some one please help?
Since the spring dependencies in my own project are declared before the other projects I would have thought it would override any of those transitive dependencies.
That is in fact the issue. Your project is dictating what is included, but some of the dependencies require a different version. They are still trying to call the method that exists in their version, but not in yours, and can't find it because you've forcibly excluded their version. That should not be done unless you're confident that the two versions are compatible!
Solutions:
Align on a single version, and use that
Use more compatible versions
Include both versions via shading (see this post) or a similar mechanism
Related
I am currently working on a Spring Project, which I am new to, and have no idea why this dependency I got from the maven repository will now resolve itself. I have tried to use both the separated dependency (jjwt-api, etc..) and the one pasted in my pom.xml below but it will not resolve. If anyone can help me figure this out that would great appreciated.
Spring v2.6.4
Java JDK 17
Error message: Dependency 'com.auth0:java-jwt:3.18.3' not found
l 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.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.legacy-banking</groupId>
<artifactId>legacyBankingAPI</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>legacyBankingAPI</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
---------THIS IS THE DEPENDENCY IN QUESTION BELOW---------------------------
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.18.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The MvnRepository page says, it's in the central repo, and the central repo link to the pom.xml of the dependency also works: https://repo1.maven.org/maven2/com/auth0/java-jwt/3.18.3/java-jwt-3.18.3.pom
So did you maybe try to resolve it once when you were offline? Failed resolving also is cached in your local maven repo, so you might have to clean that up. You can try to use
mvn dependency:get -Dartifact=com.auth0:java-jwt:3.18.3
or you clean the cached "missing" dependency manually: go to your local maven repo (usually in ~/.m2/repository), descend to com/auth0/java-jwt and remove the folder 3.18.3 inside, then run your maven build again.
I just reloaded the pom.xml file and it the works.
I am trying to inject the spring-boot-starter-security dependency in a simple spring boot application (Maven). I tried to copy this dependency from the "Securing a Web Application" tutorial from the actual Spring website, I also tried to implement it together with the spring security test dependency and thymeleaf spring security dependency.
So here are the dependencies that get the error "not found":
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
And here it is the full pom file:
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.3.1.RELEASE
com.homehero
homehero
0.0.1
war
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I feel the need to thank y'all in advance and sorry if I'm missing something really stupid, I really hope I'm not!
I solved the problem.
Long story short, a friend of mine suggested doing a new project with Spring Initializer and this time add from the beginning the "Spring Boot Security" dependency. After that, I just needed to compare the pom files. The only difference was that the new project had a:
<scope>test</scope>
line. I added that to my initial project and the first dependency did not get the error anymore. The second dependency was the Thymeleaf spring security one, in order to fix this one I added:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
To my pom file.
So this is how the dependencies look together now:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
That's it, thank you for all the answers you guys also provided.
Take a look in the version of parent POM.xml file. When I've changed the version to 2.0.0 my project founds the dependency.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I had the same problem. follow these steps:
1- Delete the dependencies that are not found.
2- Sync your project.
3- Add the dependencies.
4- sync the project again.
it worked for me hope works for everyone else:)
Not sure how you are creating project.I can tell you simple solution,which is to go to Spring Initializer ,link for which is https://start.spring.io/
There you can add all your required dependencies and then just click on Generate,which will download your project.You can just import the project in your IDE and run maven build.I tried with Spring boot version 2.3.1 only as you mentioned and it worked for me and should work for you.
Also,I would suggest you to user Intellij IDE,which comes with maven support by default,so it will make things easy for you.You can download Intellij free edition from here:
https://www.jetbrains.com/idea/download/#section=windows
Hope it will help you.
I have errors when building spring-boot application with IntelliJ. When I click 'Build' on IntelliJ it gives me a list of errors, but if I mvn clean install, then it builds perfectly. Maybe anyone knows if this could be a bug or wrong configurations?
Main.class
package com.manvydas.bachelor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Main {
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
}
}
main class has has only run method
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.manvydas</groupId>
<artifactId>bachelor</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>manvydas-bachelor-project</name>
<description>Manvydas bachelor project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>com.nulab-inc</groupId>
<artifactId>zxcvbn</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.21</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Maybe something is wrong with your IntelliJ configuration. However, you can run your application typing in IntelliJ's terminal the command mvn spring-boot:run.
The issue is that your IntelliJ artifact build is not creating the same package that your Maven pom does.
You should look at your project artifact to make sure that you end up with precisely the same package, regardless of whether you use IntelliJ or Maven to create it.
Please have in mind that after several (mis-)configuration steps IntelliJ might get in a state where it is not able to recognize Spring anymore. I had this situation sometimes. Then just delete Caches (File->Invalidate Caches...), just the index option worked for me. In our team, we saw this working several times on different machines (IntelliJ 2021.1, Windows 10).
I am having the exact same error.
I created a new project by-the-book of spring boot (with only web-starter). I did not add any code and invoked it as it is, right after its creation. I was successful with mvn clean install (jar runs and is operative), but intellij invocation (that involves the own intellij build step) fails due to missing org.springframework.boot package. (you can see in the image that the package is recognizable by intellij. it's only a problem of the build step)
I am after all the attempts of invalidate cache; restarted intellij; I have re-installed intellij completely and upgraded to latest 2022.3 ultimate version. running on java 17 on windows 11 (as much as it matters); I have sent my project to other team mates and it works flawlessly on their machine (as expected).
It seems that something got hanged and ruined on my intellij configuration, and the step of 'build' cannot get aligned with maven's artifacts
I have a maven project with jdk: 1.8, spring-boot: 1.5.4.RELEASE, spring: 4.3.9.RELEASE, and some vendor dependencies. The project builds and runs but when I access resources used by vendor packages, I get following exception:
java.lang.NoSuchMethodError: org.apache.log4j.ConsoleAppender.<init>(Lorg/apache/log4j/Layout;)V
at bkLogPkg.SingletonLog.<init>(SingletonLog.java:19) ~[VendorComLib.jar:na]
at Vendor.ConnectionBasket.<init>(ConnectionBasket.java:31) ~[VendorServices.jar:na]
at Vendor.ConnectionBasketInterface.Loader(ConnectionBasketInterface.java:450) ~[VendorServices.jar:na]
at Vendor.ConnectionBasketInterface.<init>(ConnectionBasketInterface.java:251) ~[VendorServices.jar:na]
...
It's trying to call method from Vendor jar file to log4j 1.2.14.jar file, but it's unable to do it. I have added vendor dependencies in pom.xml file.
pom.xml:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.sample</groupId>
<artifactId>angular2-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>angular2-spring</name>
<description>Angular 2 application with Spring 4</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</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>1.8</java.version>
<org.slf4j-version>1.2.14</org.slf4j-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-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- Vendor dependencies from Local Repository -->
<dependency>
<groupId>Vendor</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorServiceAuth</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorServices</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorComLib</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>Vendor</groupId>
<artifactId>VendorHeaderClass</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I have the same issue today. It cost me several hours to find the reason.
You just have a conflict with your log4j jar.
The quick fix for this is :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
If you really need log4j, then add the dependency:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
You can check log4j-over-slf4j to know the detail.
I have encountered similar issues and all of mine were solved by making sure the version I was using was the most updated and that is is compatible with the rest of the code. With your problem, it looks as if the .jar is specifically built to be compatible so I doubt that's the issue. Only things I can think of given the information at hand is:
1.) Try making sure all .jar's being used are newest version. (Sometimes if your other .jar's are not completely updated, they can throw errors/exceptions when trying to access a method from a .jar that is a version ahead.)
2.) If "1" doesn't do it, try using a dependency import function in an IDE. I have had many occurrences where Maven was just causing odd errors from IDE compatibility. Importing all .jar's from a "Dependency" menu could also help.
I have a project that has 2 modules, the first two work without version, but when I added a new one is asking me for the version.
Why is letting me use the first two without version and is asking for a version in the third one?
Maven project to create ear
....
<parent>
<groupId>es.imas.gestresi</groupId>
<artifactId>gestresi</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
...
<dependencies>
<dependency>
<groupId>es.imas.gestresi</groupId>
<artifactId>gestresi-web</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>es.imas.gestresi</groupId>
<artifactId>gestresi-ejb</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>es.imas.gestresi</groupId>
<artifactId>test-dialog</artifactId>
<version>0.0.1-SNAPSHOT</version> <!--Ask for version-->
<type>war</type>
</dependency>
</dependencies>