[英]JerseyConfig overrides @RestController in spring boot application
I am trying to use JerseyConfig
class in existing sping boot application but for some reason when I add this configuration: 我试图在现有的JerseyConfig
引导应用程序中使用JerseyConfig
类,但是由于某种原因,当我添加此配置时:
@Component
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(Users.class);
register(Groups.class);
property("SCIM_IMPLEMENTATION_INSTANCE", new JerseyApplication());
}
}
The @RestController endpoints do not work as expexted anymore. @RestController端点不再像扩展那样工作。 All of them return 404 after applying this JerseyConfig
class. 在应用此JerseyConfig
类之后,它们全部返回404。 All of the Jersey endpoints work fine. 所有Jersey端点均正常运行。
Can I use JAX rs endpoints (in my case I use Jersey) and @RestCotroller in the same application? 我可以在同一应用程序中使用JAX rs终结点(在我的情况下使用Jersey)和@RestCotroller吗? I need some configuration for separating my existing REST servcices from the new JAX rs endpoints. 我需要一些配置,以将现有的REST服务与新的JAX rs端点分离。 If anybody can help I will really appreciate it. 如果有人可以提供帮助,我将非常感激。 Thank you! 谢谢!
There is a workaround for combining Jersey resources and Spring controllers. 有一个解决方案,可以将Jersey资源和Spring控制器组合在一起。 There are a couple of changes that you will need to do to your setup. 您需要对设置进行几处更改。
Change annotation of JerseyConfig from @Component
to @Configuration
and add package of your controllers to scan 将JerseyConfig的注释从@Component
更改为@Configuration
并添加要扫描的控制器程序包
// scan the resources package for your resources / restControler public JerseyConfig() { // other code packages(package_of_your_rest_controller); }
Change annotation of your rest controller from @ReuestMapping
to @Path
Eg if your controller is like this: 如果您的控制器是这样的,请将rest控制器的注释从@ReuestMapping
为@Path
例如:
@RestController @Component public class MyRestController { @RestController @Component公共类MyRestController {
@RequestMapping("/foo") public String foo() { return "foo"; }
} }
It becomes this: 变成这样:
@Path("/") @Component public class MyRestController { @Path(“ /”)@Component公共类MyRestController {
@Path("/foo") public String foo() { return "foo"; }
} }
Give this a try once if you can. 如果可以,请尝试一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.