gpt4 book ai didi

java - Spring Boot Jersey 自动配置

转载 作者:行者123 更新时间:2023-12-02 01:27:21 26 4
gpt4 key购买 nike

我想使用 Spring Boot 和 Jersey 启动一个新项目。我已经阅读了大量有关如何执行此操作的教程,但有一件事仍然让我困惑。为什么我必须注册我的所有 Jersey 资源?

例如,Lokesh Gupta 在 https://howtodoinjava.com/spring-boot/spring-boot-jersey-example/#jersey-config 上编写了一个教程他有以下代码:

import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.stereotype.Component;

@Component
public class JerseyConfig extends ResourceConfig
{
public JerseyConfig()
{
register(UserResource.class);
}
}

我不想以这种方式注册我的所有资源。有没有办法让 Jersey 的资源扫描仪拾取资源?使用上面的方法,Jersey的@Provider注解会被遵守吗?是否可以在某处设置 jersey.config.server.provider.packages servlet 参数?

总而言之:“如何使用 Spring Boot 自动配置 Jersey?”

最佳答案

如果您阅读了 Spring boot 文档 JAX-RS and Jersey

Jersey’s support for scanning executable archives is rather limited. For example, it cannot scan for endpoints in a package found in a fully executable jar file or in WEB-INF/classes when running an executable war file. To avoid this limitation, the packages method should not be used, and endpoints should be registered individually by using the register method, as shown in the preceding example.

因此,如果您想要一个可执行的 jar/war 文件,那么答案是否定的。

关于java - Spring Boot Jersey 自动配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56705996/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com