Can I add a spring mvc filter using jetty with a jar file?

Posted by Juan Manuel on Stack Overflow See other posts from Stack Overflow or by Juan Manuel
Published on 2012-05-30T22:28:43Z Indexed on 2012/05/30 22:40 UTC
Read the original article Hit count: 159

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about spring-mvc