应用程序无法启动:Spring Boot setEnableLoggingRequestDetails() 不存在



我正在尝试设置 SpringBoot Web 应用程序。修复了一些问题后,我有一个新的问题。应用程序启动,但引发异常,加载失败。

控制器是临时的,稍后将添加实现。

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

添加了父部分以修复依赖项问题

我的聚甲醛:


    <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 引导提供的库版本,从pom.xml中删除spring-webmvcspring-orm <dependency>

相关内容

  • 没有找到相关文章

最新更新