java - 应用程序启动失败 : Spring Boot setEnableLoggingRequestDetails() not exist

标签 java spring hibernate spring-boot spring-mvc

我正在尝试设置 SpringBoot Web 应用程序。解决了一些问题后,我有了一个新问题。应用程序启动,但抛出异常,加载失败。

Controller 是临时的,稍后会添加实现。

试图删除覆盖的依赖项,但没有结果。

添加父部分以解决依赖性问题

我的 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>

我的 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 {
    }

我的错误信息:

***************************
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

删除强制依赖项使这些导入无法访问

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

最佳答案

DispatcherServlet.setEnableLoggingRequestDetails() 方法是在 Spring 5.1 中引入的。您正在通过手动强制混淆 Spring JAR 版本 spring-webmvcspring-orm 5.0.0.发布。 Spring Boot 2.1.2.RELEASE 根据 docs 使用 Spring Framework 5.1.3.RELEASE :

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.

使用Spring Boot提供的库版本,去掉spring-webmvcspring-orm <dependency>来自你的 pom.xml .

关于java - 应用程序启动失败 : Spring Boot setEnableLoggingRequestDetails() not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55406438/

相关文章:

java - Caused by : org. hibernate.boot.registry.selector.spi.StrategySelectionException: 无法解析名称

java - Spring MVC IntelliJ Idea

java - 子表上的 Hibernate Criteria API

java - 在数据库中使用 Hibernate 和 H2 时出错

java - 如何使用 JPA/Hibernate 选择 DDL 主键约束名称

java - 使用其他列表中的值减少列表

java - 创建/写入/读取 Jar 存档外部的文本文件

java - 一组重名的集合?

java - 坚持 org.springframework.security.core.userdetails.User 或 UserDetails

json - kotlin 数据类 HttpMessageNotReadableException