我正在尝试设置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;
答案 0 :(得分:1)
DispatcherServlet.setEnableLoggingRequestDetails()
方法是在Spring 5.1中引入的。您正在通过手动强制spring-webmvc
和spring-orm
5.0.0.RELEASE来混合Spring JAR版本。 Spring Boot 2.1.2.RELEASE按照docs使用Spring Framework 5.1.3.RELEASE:
Spring Boot 2.1.1.RELEASE需要Java 8,并且与Java 11(包括)兼容。还需要Spring Framework 5.1.3.RELEASE或更高版本。
使用Spring Boot提供的库版本,从spring-webmvc
中删除spring-orm
和<dependency>
pom.xml
。