Issue
I am getting an error even though there is a single servlet in my code.
WARN 2021-04-06 21:52:42,874 [main] org.eclipse.jetty.util.component.AbstractLifeCycle: FAILED ServletHandler@93501be{FAILED}: java.lang.IllegalStateException: Multiple servlets map to path /*: git.service.http.MyServlet68360fb9[mapped:EMBEDDED:null],io.dropwizard.jersey.setup.JerseyServletContainer-713e49c3[mapped:EMBEDDED:null]
java.lang.IllegalStateException: Multiple servlets map to path /*: git.service.http.MyServlet68360fb9[mapped:EMBEDDED:null],io.dropwizard.jersey.setup.JerseyServletContainer-713e49c3[mapped:EMBEDDED:null]
Below is my code:
environment
.getApplicationContext()
.addServlet(
new ServletHolder(
new MyServlet(
injector.getInstance(HttpRepositoryResolver.class))),
“/*“);
Can anyone help me figure it out?
Solution
Both git.service.http.MyServlet
and io.dropwizard.jersey.setup.JerseyServletContainer
are registered to the url-pattern /*
.
Keep in mind that with Servlets, there's no such thing as optional handling of a request.
If the requested resource matches the url-pattern, it's sent to that Servlet, it MUST handle that request, it cannot go "oh, nah, not for me, let someone else handle this request".
I would suggest putting Jersey on something specific like /api/*
or /rest/*
as a url-pattern.
Answered By - Joakim Erdfelt