Hello Jetty Users,
I added a jersey2-jaxrs servlet into Jetty 10 server and trying to execute the code. But I am getting
error as -
No injection source found for a parameter of type public void com.example.hfs.handlers.RecordsHandler.putRecord(java.lang.String,redis.clients.jedis.Jedis,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,redis.clients.jedis.exceptions.JedisException,org.json.JSONException at index 2.
My server code where I add Jersey servlet is as follows:
// Setup Jetty Servlet
ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
servletContextHandler.setContextPath("/");
contexts.addHandler(servletContextHandler);
// Now that we have added all the handlers, Set handlers for the server
server.setHandler(contexts);
// Setup API resources
ServletHolder jersey = servletContextHandler.addServlet(ServletContainer.class, "/api/*");
jersey.setInitOrder(1);
jersey.setInitParameter("jersey.config.server.provider.packages", "com.cloudian.hfs.handlers;io.swagger.v3.jaxrs2.integration.resources");
The jersey servlet scans for the API resources and then tries to execute. But it's failing with an error caused by: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
My API resource typically looks like this -
@GET
@Path("/featuregroups/")
public void listFeatureGroups(@RequestBody Request jettyRequest, @RequestBody HttpServletRequest request, HttpServletResponse response) throws IOException, ParseException, JedisException, JSONException {}
And build.gradle have dependencies:
dependencies {
// Basic Gradle dependencies
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
// Logging dependencies
runtimeOnly 'org.slf4j:slf4j-api:1.7.7'
runtimeOnly 'org.slf4j:slf4j-log4j12:1.7.7'
// Jetty dependencies
implementation 'org.eclipse.jetty:jetty-server:10.0.2'
implementation 'org.eclipse.jetty:jetty-servlet:10.0.2'
implementation 'org.eclipse.jetty:jetty-util:10.0.2'
// Jersey dependencies
implementation 'org.glassfish.jersey.containers:jersey-container-jetty-http:2.34'
implementation 'org.glassfish.jersey.containers:jersey-container-servlet-core:2.34'
implementation 'org.glassfish.jersey.core:jersey-server:2.34'
implementation 'org.glassfish.jersey.inject:jersey-hk2:2.34'
implementation 'org.glassfish.jersey.media:jersey-media-multipart:2.34'
implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.4'
// Redis & Json dependencies
implementation 'org.springframework.data:spring-data-redis:2.4.3'
implementation 'redis.clients:jedis:3.3.0'
implementation group: 'org.json', name: 'json', version: '20201115'
// Jakarta JAX-RS dependency for HTTP Methods
implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1'
}
Can someone help me in fixing this or understanding what I am doing wrong?