簡體   English   中英

應用程序啟動失敗:Spring Boot setEnableLoggingRequestDetails() 不存在

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

我正在嘗試設置 SpringBoot Web 應用程序。 解決了一些問題后,我有了一個新的。 應用程序啟動,但拋出異常,加載失敗。

控制器是臨時的,稍后會添加實現。

試圖刪除覆蓋的依賴項,但沒有結果。

添加了父部分以解決依賴項問題

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

我的控制器:

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-webmvcspring-orm 5.0.0.RELEASE 來混合 Spring JAR 版本。 Spring Boot 2.1.2.RELEASE 根據文檔使用 Spring Framework 5.1.3.RELEASE:

Spring Boot 2.1.1.RELEASE 需要 Java 8,並且兼容 Java 11(包括在內)。 還需要 Spring Framework 5.1.3.RELEASE 或更高版本。

使用 Spring Boot 提供的庫版本,從pom.xml刪除spring-webmvcspring-orm <dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM