Json webtoken dependency will not resolve in pom.xml - java

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.

Related

Spring Maven: Correct the classpath of you application

I am getting the following error when trying to run my spring project:
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:1236)
The following method did not exist:
'javax.persistence.Index[] javax.persistence.Table.indexes()'
The calling method's class, org.hibernate.cfg.annotations.EntityBinder, was loaded from the following location:
jar:file:/C:/Users/bobal/.m2/repository/org/hibernate/hibernate-core/5.4.14.Final/hibernate-core-5.4.14.Final.jar!/org/hibernate/cfg/annotations/EntityBinder.class
The called method's class, javax.persistence.Table, is available from the following locations:
jar:file:/C:/Users/bobal/Documents/Java%20Projects/restService/lib/javax.persistence.jar!/javax/persistence/Table.class
jar:file:/C:/Users/bobal/.m2/repository/jakarta/persistence/jakarta.persistence-api/2.2.3/jakarta.persistence-api-2.2.3.jar!/javax/persistence/Table.class
jar:file:/C:/Users/bobal/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar!/javax/persistence/Table.class
The called method's class hierarchy was loaded from the following locations:
javax.persistence.Table: file:/C:/Users/bobal/Documents/Java%20Projects/restService/lib/javax.persistence.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.hibernate.cfg.annotations.EntityBinder and javax.persistence.Table
Process finished with exit code 1
I think that this error may be due to having conflicting versions of some dependencies, but I'm not very sure. This is my first ever Spring project.
Here is my UPDATED pom.xml file
<?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.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>restService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>restService</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<jdbc.version>8.2.2.jre11</jdbc.version>
<hibernate.version>5.4.14.Final</hibernate.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.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>17.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
If you find anything wrong please feel free to point it out and explain why. Trying to learn as much as I can.
You have multiple version of JPA libraries, that's why you are getting this error.
jakarta.persistence-api-2.2.3.jar and
hibernate-jpa-2.1-api-1.0.0.Final.jar
You can remove hibernate-jpa-2.1-api-1.0.0.Final.jar dependency because it is also present in jakarta.persistence-api-2.2.3.jar.

Dependency 'org.springframework.boot:spring-boot-starter-validation:2.5.1' not found

How can I solve the issue of "Dependency 'org.springframework.boot:spring-boot-starter-validation:2.5.1' not found" ?
My pom.xml file loks like this:
<?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.5.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>JavaDeveloperTask</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${project.parent.version}</version>
</plugin>
</plugins>
</build>
</project>
I have added
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
But it still gives me the error. What could be th cause of this?
#ekm0d. I had the same problem using the Intellij IDEA. Here what I did and worked for me after inserting this on pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
Right-click on the project file.
Click on Maven
Click on Reload Project
Wait the poem.xml archive reload
I hope it works for you too :)
Works for me.
Central repo have this dependency: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-validation/2.5.1/
So i don't see why it should not work. Maybe there was some kind of network issue.
Try to remove it from local maven repo and download again.
You can find maven repo in your user home dir .m2, delete .m2/repository/org/springframework/boot/spring-boot-starter-validation/2.5.1 folder
You should try to close the project and re-open it, the dependency will get downloaded by itself.
Worked in my case.

Cannot resolve commons-collections:commons-collections:2.1

I have an issue when i try to fix my code. I keep getting issue when I reload maven/reimport maven
Cannot resolve commons-collections:commons-collections:2.1
When I open Maven I see in the folder in Dependencies an error starts in commons-validator:commons-validator:1.3.1
Here my 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.0.RELEASE</version>
<relativePath />
<!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demoSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demoSpring</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation -->
<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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.16.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>demoSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
take a look and see how I can fix this.
Cannot resolve commons-collections:commons-collections:2.1
Cannot resolve org.apache.commons:commons-collections4:4.4
Cannot resolve commons-digester:commons-digester:1.6
Cannot resolve xml-apis:xml-apis:1.0.b2
Cannot resolve commons-logging:commons-logging:1.0.4
The error is "Cannot resolve commons-collections:commons-collections:2.1"
It has nothing to do with "commons-validator" dependency.
The commons collection artifact has moved to a different location in maven artifactory.
Please check this out
https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
try to change version of your package, but better find dependency in https://mvnrepository.com/ which you need, copy this text and try to reimport.

Maven not picking up the classes from dependency modules

In my spring-boot project there are two microservices, one config-server, and one naming server. It also has two modules which I am adding as a dependency in the microservices.
Below is the pom of the commons-new module which should be a dependency in my microservices.
<?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.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.highpeak.tlp</groupId>
<artifactId>commons-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>commons-new</name>
<description>Contains common modules needed by all the microservices</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And I am adding it as a dependency in my microservice.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.highpeak.tlp</groupId>
<artifactId>ybanq-auth-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ybanq-auth-manager</name>
<description>Manages the authentication process with ybanq</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.testSource>1.8</maven.compiler.testSource>
<maven.compiler.testTarget>1.8</maven.compiler.testTarget>
</properties>
<dependencies>
<dependency>
<groupId>com.highpeak.tlp</groupId>
<artifactId>commons-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.highpeak.tlp</groupId>
<artifactId>redis-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I try to build the microservice using the command mvn clean install, it is throwing compiler-error message.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ybanq-auth-manager: Compilation failure: Compilation failure:
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/controller/AuthController.java:[3,42] package com.highpeak.tlp.commons.exception does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/controller/AuthController.java:[4,37] package com.highpeak.tlp.commons.util does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerService.java:[3,42] package com.highpeak.tlp.commons.exception does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerService.java:[11,51] cannot find symbol
[ERROR] symbol: class DataException
[ERROR] location: interface com.highpeak.tlp.ybanqauthmanager.service.AuthManagerService
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerServiceImpl.java:[19,42] package com.highpeak.tlp.commons.exception does not exist
However, in IntelliJ editor those classes are accessible and Intellij is not showing the compiler error. But when I run the app in IntelliJ, it shows the same errors.
What is the mistake I am making? Since I added the module as dependency their classes should be available, right?
My system maven version is 3.5.4.
The Spring Boot plugin package up all dependency jars and pulls them into the jar your module builds. The structure of this jar is specifically for Spring Boot runnable applications and is not compatible with the normal jar structures, so you can't use a Spring Boot Application jar as maven dependency jar.
Remove spring boot plugin from submodule (common-new).
I had similar issue, but with gradle and found this Unresolved Dependency on package in subproject
Unfortunately, I don't know what is exact issue in "using" spring boot plugin in submodules/subprojects.

java.lang.NoClassDefFoundError: org/springframework/core/env/ConfigurableEnvironment

I am trying to write a simple RESTful service using Spring Boot. However, there is an error message I am not able to solve. I have been researching and it looks like it is a conflict between SpringBoot versions, however I am not sure about how can I get rid of it.
I have this SpringBootApp:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* REST Service application
*/
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Associated with this pom.xml:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.websystique.springmvc</groupId>
<artifactId>Spring4MVCHelloWorldRestServiceDemo</artifactId>
<packaging>war</packaging>
<version>1.0.0</version>
<name>Spring4MVCHelloWorldRestServiceDemo Maven Webapp</name>
<properties>
<springframework.version>4.3.0.RELEASE</springframework.version>
<jackson.library>2.7.5</jackson.library>
<spring.batch.version>2.1.9.RELEASE</spring.batch.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version> <!-- Or whatever JUnit you're using. -->
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.library}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.library}</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>${spring.batch.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>Spring4MVCHelloWorldRestServiceDemo</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>Spring4MVCHelloWorldRestServiceDemo</finalName>
</build>
</project>
Looks fine for me, but I am getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/env/ConfigurableEnvironment
at com.application.Application.main(Application.java:13)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.ConfigurableEnvironment
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Recommended Approach
Go to Spring boot Initialzr site and select web stack as a dependency as shown in below .
As Spring Boot uses the concept of Opinionated dependencies and Bill of Materials, It will automatically pull the other dependencies and resolve your classNotFoundException issue. And in your case it misses out the Spring-core-4.2.4.RELEASE.jar dependency.
Execute the Maven Goal as clean install spring-boot:run -e and you can find your maven dependencies in your IDE and below given is a sample POM file.
<?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.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.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>
</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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
< /dependency>
</dependencies>
<build>
<finalName>demo</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Spring boot is running -
<spring.version>4.3.2.RELEASE</spring.version>
For -
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
While you are importing -
<springframework.version>4.3.0.RELEASE</springframework.version>
You can confirm on the master pom -
https://github.com/spring-projects/spring-boot/blob/v1.4.0.RELEASE/spring-boot-dependencies/pom.xml
Can you update the spring version in your pom? Or deal with managing maven dependencies
Delete the springframework folder in repository, then press Alt + F5 and update the project (force update snapshot).
C:\Users\xxxx\.m2\repository\org\springframework
changed the boot-starter-parent version from 1.5.1.RELEASE to 1.4.0.RELEASE.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
Please Try this one for your parent
I had same problem with Spring boot 2.1.9.RELEASE
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Added pom dependency eliminated this exception:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
EDIT - better approach.
Also clean up of maven repository with spring dependencies resolved problem for me, there were not need to add spring-core 5.2.0.RELEASE in pom. Seems that when I had many versions of spring in repo some problem occurs. Also before again resolve dependencies dont forget clean project.
rm -rf ~/.m2/repository/org/springframework/
For me changing all
<version>2.4.10</version>
to
<version>2.4.3</version>
in pom.xml file worked.
I changed the boot-starter-parent configuration which was runnig version 2.0.0 to 1.4.0 and I was able to run the java application and got rid of this error
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version> <!-- changed it to version 1.4.0 from 2.0.0-->
<relativePath/> <!-- lookup parent from repository -->
</parent>

Categories