Application failed to start: Spring Boot setEnableLoggingRequestDetails() not exist

Ihor Dovhoshliubnyi :

I'm trying to setup SpringBoot web application. After fixing some issues, i've got a new one. Application starts, but an exception thrown, and load failed.

Controller is temporary, implementation will be added later.

Tried to delete overrided dependencies, but have no result.

Parent section was added to fix issue with dependencies

My POM:


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

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

    <!--Logging dependencies-->
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>2.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.6.1</version>
        </dependency>

        <!--Spring dependencies-->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.0.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>5.0.0.RELEASE</version>
        </dependency>

        <!--Marshalling dependencies-->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.9.8</version>
            </dependency>
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.3.1</version>
                <scope>runtime</scope>
            </dependency>

        <!-- Hibernate dependencies; -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.12.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>5.2.12.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
            <version>9.0.1</version>
        </dependency>

        <!-- JAXB requested by Hibernate-->
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

        <!-- PostgreSQL dependency-->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.5</version>
        </dependency>


    </dependencies>

My Controller:

public class AuthController {

    private Logger logger = LogManager.getLogger(AuthController.class);

    @GetMapping
    public List<AbstractUser> findAll() {
            return null;
    }

    @GetMapping(value = "/{id}")
    public AbstractUser findById(@PathVariable("id") Long idUser) {
        return null;
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public Long create(@RequestBody AbstractUser userToCreate) {
        return null;
    }

    @PutMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.OK)
    public void update(@PathVariable("id") Long id, @RequestBody AbstractUser userToUpdate) {
    }

    @DeleteMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.OK)
    public void delete(@PathVariable("id") Long id) {
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public class BadRequestException extends RuntimeException {
    }

    @ResponseStatus(HttpStatus.NOT_FOUND)
    public class NotFoundException extends RuntimeException {
    }

My error message:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method org.springframework.web.servlet.DispatcherServlet.setEnableLoggingRequestDetails(Z)V but it does not exist. Its class, org.springframework.web.servlet.DispatcherServlet, is available from the following locations:

    jar:file:/C:/Users/Admin/.m2/repository/org/springframework/spring-webmvc/5.0.0.RELEASE/spring-webmvc-5.0.0.RELEASE.jar!/org/springframework/web/servlet/DispatcherServlet.class

It was loaded from the following location:

    file:/C:/Users/Admin/.m2/repository/org/springframework/spring-webmvc/5.0.0.RELEASE/spring-webmvc-5.0.0.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.web.servlet.DispatcherServlet

Removing forced dependencies make these imports inaccessible

import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
Karol Dowbecki :

DispatcherServlet.setEnableLoggingRequestDetails() method was introduced in Spring 5.1. You are mixing up Spring JAR versions by manually forcing spring-webmvc and spring-orm 5.0.0.RELEASE. Spring Boot 2.1.2.RELEASE uses Spring Framework 5.1.3.RELEASE as per docs:

Spring Boot 2.1.1.RELEASE requires Java 8 and is compatible up to Java 11 (included). Spring Framework 5.1.3.RELEASE or above is also required.

Use the library versions provided by the Spring Boot, remove the spring-webmvc and spring-orm <dependency> from your pom.xml.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=150797&siteId=1