假设我有一个带有嵌入式码头的简单球衣应用程序github上的演示项目 https://github.com/varren/jersey2-gradle-embedded-jetty-demo-repo和下面的基本代码。
回到 jersey1 的日子里,我收到了日志消息:
мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
ru.varren
мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class ru.varren.MyResource
мая 07, 2016 5:05:50 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Provider classes found:
class ru.varren.JsonProvider
мая 07, 2016 5:05:50 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19.1 03/11/2016 02:08 PM'
但现在我正在尝试使用球衣 2,但没有更多日志信息。所以,我的问题是如何列出所有注册的 JAX-RS 实体提供者。我不太关心在哪里列出它们。在main
函数或在某些@GET
MyResource
方法。也许我应该更改我的设置中的某些内容或将记录器布尔值设置为布尔值,但找不到它。
这纯粹是为了测试目的。简单打印所有提供者类对我来说就足够了。冷却器选项是打印提供商和附属机构@Produces
and @Consumes
媒体类型。
我的资源.java
@Path("test")
public class MyResource {
@GET
@Produces({ MediaType.APPLICATION_JSON })
public Response getPersons() {
return Response.ok("[some data here]").build();
}
}
我的应用程序.java
public class MyApplication {
public static void main(String[] args) throws Exception {
URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
ResourceConfig config = new ResourceConfig(MyResource.class);
config.packages("ru.varren");
Server server = JettyHttpContainerFactory.createServer(baseUri, config, true);
server.join();
}
}
And gradle.build
dependencies {
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.2'
compile 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.22.2'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.22.2'
compile 'org.glassfish.jersey.containers:jersey-container-jetty-http:2.22.2'
compile 'org.eclipse.jetty:jetty-server:9.1.0.M0'
compile 'org.eclipse.jetty:jetty-servlet:9.1.0.M0'
}