-
Notifications
You must be signed in to change notification settings - Fork 212
Configuring Servlets
These Servlets will be available on all Microservices sharing a core Spring context.
In order to automagically add a Servlet to your Microservice, implement the interface ServletConfiguration on a Spring bean. If the bean implementing ServletConfiguration is also a Servle only the method getMapping() need be implemented. This will be the context URL of your Servlet.
public Class<? extends Servlet> getServlet()
Override the above method to configure a specified Servlet class. Typically used for Servlets in external jar files.
public String getName()
To change the Servlet name to something other than the Class name.
public Map<String,String> getInitParameters()
To configure the init parameters for the Servlet public Map<String,String> getInitParameters(){ return ImmutableMap.of(); }
@Component
public class AutodiscoveredServlet extends HttpServlet
implements ServletConfiguration {
@Override
public String[] getMapping() {
return new String[] { "/servlet" };
}
@Override
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
resp.getWriter().write("hello world");
}
}
#Configuring Local Servlets
These Servlets will only be available on the Microservice modules they are configured against.
In your Module object override
public Map<String,Servelt> getServlets()
To configure module local servlets and their contexts Urls .
public Class<? extends ServletConfiguration>[] getServletConfigurationClass()