Spring 带球衣的引导 2.1.0
Spring Boot 2.1.0 with Jersey
今天我启动了一个简单的应用程序spring 启动应用程序。因为我是从零开始的,所以我使用的是最新版本的 SpringBoot: 2.1.0.RELEASE
我想用 Jersey 来使用 JAX-RS。我有这个适用于 1.3.6 Spring 引导版本,但我收到以下错误:
***************************
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>
Spring引导应用程序class
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
** 球衣配置**
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";
}
}
有人可以发现我遗漏了什么或者我的 code/config 可能有什么问题吗?
非常感谢
这是 Spring Boot 中的错误。感谢您提请我们注意。我已经打开 this issue 来跟踪问题。
如果您打算只使用 Jersey 和 JAX-RS,则不需要使用 spring-boot-starter-web
。它本质上是 Spring 基于 MVC 的 spring-boot-starter-jersey
等价物。因此,您可以通过从应用程序中删除 spring-boot-starter-web
依赖项来避免您遇到的问题。
如果您确实想同时使用 Spring MVC 和 JAX-RS,您可以通过将 spring.main.allow-bean-definition-overriding=true
添加到 src/main/resources
中的 application.properties
文件来启用 bean 定义覆盖.
今天我启动了一个简单的应用程序spring 启动应用程序。因为我是从零开始的,所以我使用的是最新版本的 SpringBoot: 2.1.0.RELEASE
我想用 Jersey 来使用 JAX-RS。我有这个适用于 1.3.6 Spring 引导版本,但我收到以下错误:
***************************
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>
Spring引导应用程序class
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
** 球衣配置**
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";
}
}
有人可以发现我遗漏了什么或者我的 code/config 可能有什么问题吗?
非常感谢
这是 Spring Boot 中的错误。感谢您提请我们注意。我已经打开 this issue 来跟踪问题。
如果您打算只使用 Jersey 和 JAX-RS,则不需要使用 spring-boot-starter-web
。它本质上是 Spring 基于 MVC 的 spring-boot-starter-jersey
等价物。因此,您可以通过从应用程序中删除 spring-boot-starter-web
依赖项来避免您遇到的问题。
如果您确实想同时使用 Spring MVC 和 JAX-RS,您可以通过将 spring.main.allow-bean-definition-overriding=true
添加到 src/main/resources
中的 application.properties
文件来启用 bean 定义覆盖.