Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the error 'java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver' in a spring-boot application?

I am trying to upgrade my demo application with Java 11 and Spring-boot 2. But the application fails due to java.lang.NoClassDefFoundError:org/springframework/boot/bind/RelaxedPropertyResolver. I am using the latest release of spring-boot-starter-parent.

Spring-boot Version:

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/>
    </parent>

I have googled this issue and found that RelaxedPropertyResolver is removed from spring-boot. I tried to give every version of spring-boot to make my application compatible with java 11. It works with spring-boot version 1.5.19-RELEASE.

Error:

[INFO ] [2019-05-29T12:24:25,567] | [main][DemoApplication] --- Starting DemoApplication on JARVIS with PID 71600 (C:\viveknaskar\springbootapp\demo-verifier\target\classes started by Vivek in C:\viveknaskar\springbootapp)
[INFO ] [2019-05-29T12:24:25,575] | [main][DemoApplication] --- No active profile set, falling back to default profiles: default
[ERROR] [2019-05-29T12:24:26,712] | [main][SpringApplication] --- Application run failed
java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getExcludeAutoConfigurationsProperty(AutoConfigurationImportSelector.java:215)
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getExclusions(AutoConfigurationImportSelector.java:209)
    at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:99)
    at org.springframework.context.annotation.ConfigurationClassParser$DefaultDeferredImportSelectorGroup.process(ConfigurationClassParser.java:892)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:878)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:804)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:774)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at com.iws.DemoApplication.main(DemoApplication.java:39)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 21 more
[INFO ] [2019-05-29T12:24:26,924] | [background-preinit][Version] --- HV000001: Hibernate Validator 6.0.16.Final

Process finished with exit code 1

Main Class:

import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAutoConfiguration
@EnableEncryptableProperties
public class DemoApplication {
    private static final Logger logger = LogManager.getLogger(DemoApplication.class);

    public static void main(String[] args) {
        try {
            logger.info("RESTFul Application Starting.");
            SpringApplication.run(DemoApplication.class, args);
            logger.info("RESTFul Application Started.");
        }
        catch(Exception e) {
            logger.error("RESTFul Application Failed to Start.",e);
        }
    }
}

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>


    <groupId>com.viveknaskar</groupId>
    <artifactId>verifier</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/>
    </parent>

     <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>11</java.version>

        <!-- Spring Dependencies -->
        <spring.boot.version>2.1.5.RELEASE</spring.boot.version>
        <spring.version>5.1.5.RELEASE</spring.version>
        <spring.security.version>5.1.5.RELEASE</spring.security.version>
        <spring.data.version>2.0.7.RELEASE</spring.data.version>

        <!-- Other Dependencies -->   
        <jackson.version>2.9.8</jackson.version>
        <apache.commons.version>3.0</apache.commons.version>
        <apache.httpclient.version>4.5.3</apache.httpclient.version>
        <jacoco.version>0.7.5.201505241946</jacoco.version>
        <jodatime.version>2.9.7</jodatime.version>
        <squareup.okhttp3.verison>3.6.0</squareup.okhttp3.verison>
        <jasypt.springboot.version>2.0.0</jasypt.springboot.version>
        <git.commit.id.version>2.2.5</git.commit.id.version>
        <lombok.version>1.18.0</lombok.version>
        <mongo-java-driver.version>3.8.2</mongo-java-driver.version>
        <json.version>20180813</json.version>

        <!-- Maven Plugins -->
        <maven-clean-plugin.version>3.0.0</maven-clean-plugin.version>
        <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
        <maven-failsafe-plugin.version>2.22.1</maven-failsafe-plugin.version>
        <maven-idea-plugin.version>2.2.1</maven-idea-plugin.version>
        <maven-install-plugin.version>3.0.0-M1</maven-install-plugin.version>
        <maven-jar-plugin.version>2.6</maven-jar-plugin.version>
        <maven-surefire-plugin.version>2.9</maven-surefire-plugin.version>

        <!-- Logging -->
        <log4j-api.version>2.11.1</log4j-api.version>
        <log4j-core.version>2.11.1</log4j-core.version>
        <log4j-slf4j-impl.version>2.11.1</log4j-slf4j-impl.version>
        <jcl-over-slf4j.version>1.7.25</jcl-over-slf4j.version>
        <jul-to-slf4j.version>1.7.25</jul-to-slf4j.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.1.5.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.5.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.1.5.RELEASE</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>1.5.19.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.iws.verifier</groupId>
            <artifactId>domain</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.iws.verifier</groupId>
            <artifactId>data</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>${spring.boot.version}</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>${jsonwebtoken.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${jodatime.version}</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>${json.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${apache.httpclient.version}</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>${squareup.okhttp3.verison}</version>
        </dependency>
        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>${jasypt.springboot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${apache.commons.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>1.10.18.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>1.13.18.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>

</project>

like image 723
viveknaskar Avatar asked May 29 '19 10:05

viveknaskar


1 Answers

This is because of using the spring-boot-starter-parent version as 2.x but trying to use the older versision 1.5.x for a related dependency, say spring-boot-autoconfigure.

The code below will cause this error because the dependency version is not matching from that of the parent.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.2.RELEASE</version>
    <relativePath />
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
        <version>1.5.13.RELEASE</version>
    </dependency>
</dependencies>
like image 157
benitta.ruphus Avatar answered Oct 13 '22 13:10

benitta.ruphus