Can I add a spring mvc filter using jetty with a jar file?
- by Juan Manuel
I have a simple web application disguised as a java application (as in, it's a .jar instead of a .war), and I'd like to use a filter for my requests.
If it was a .war, I could initialize it with a WebAppContext and specify a web.xml file where I'd have my filter declaration like this
<filter>
<filter-name>myFilter</filter-name>
<filter-class>MyFilterClass</filter-class>
</filter>
<filter-mapping>
<filter-name>myFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
However, I'm using a simple Context to initialize my application with Spring.
Server server = new Server(8082);
Context root = new Context(server, "/", Context.SESSIONS);
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextConfigLocation("classpath:application-context.xml");
root.addServlet(new ServletHolder(dispatcherServlet), "/*");
server.start();
Is there a way to programmatically specify filters for the spring servlet, without using a web.xml file?