Spring boot 带球衣的弹簧靴2.1.0
今天我启动了一个简单的应用程序spring boot应用程序。因为我是从头开始的,所以我使用的是最新版本的SpringBoot:2.1.0.RELEASE 我想使用Jersey来使用JAX-RS。我在1.3.6 Spring Boot版本中使用了它,但是我得到了以下错误:Spring boot 带球衣的弹簧靴2.1.0,spring-boot,jersey,Spring Boot,Jersey,今天我启动了一个简单的应用程序spring boot应用程序。因为我是从头开始的,所以我使用的是最新版本的SpringBoot:2.1.0.RELEASE 我想使用Jersey来使用JAX-RS。我在1.3.6 Spring Boot版本中使用了它,但是我得到了以下错误: *************************** APPLICATION FAILED TO START *************************** Description: The bean 'requ
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'requestContextFilter', defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
我不明白问题出在哪里,因为我现在的应用程序是极简主义的
显然,bean'requestContextFilter'被配置了两次,但我不知道它是在哪里配置的
以下是我的配置:
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>pt.msoftware.userauthservice.App</start-class>
<java.version>1.8</java.version>
<docker.image.prefix>${user.name}</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
**泽西配置**
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;
import pt.msoftware.userauthservice.rest.UserEndpoint;
import javax.ws.rs.ApplicationPath;
/**
* Created by marco on 31/10/2018.
*/
@Component
@ApplicationPath("/rest")
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(UserEndpoint.class);
}
}
**端点**
import org.springframework.stereotype.Component;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
/**
* Created by marco on 31/10/2018.
*/
@Component
@Path("/user")
public class UserEndpoint {
@GET
public String message() {
return "Hello";
}
}
有人能发现我缺少什么或者我的代码/配置有什么问题吗
非常感谢这是Spring Boot中的一个bug。谢谢你提醒我们。我已经开始跟踪这个问题 如果只打算使用Jersey和JAX-RS,则不需要使用
SpringBootStarterWeb
。本质上,它是基于SpringMVC的等价物,相当于SpringBootStarter球衣。因此,您可以通过从应用程序中删除springbootstarterweb
依赖项来避免所看到的问题
如果您确实想同时使用Spring MVC和JAX-RS,可以通过向
src/main/resources
中的应用程序.properties
文件添加Spring.main.allow bean definition overriding=true
来启用bean定义覆盖,谢谢Andy。你的建议非常有效。我的目的只是创建一个服务,所以删除SpringBootStarterWeb是完美的。我能问问你的意见吗。在SpringREST上使用JAX-RS有充分的理由吗?这只是一种不同的味道?顺致敬意,
import org.springframework.stereotype.Component;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
/**
* Created by marco on 31/10/2018.
*/
@Component
@Path("/user")
public class UserEndpoint {
@GET
public String message() {
return "Hello";
}
}