Guice Servlet config doesn't work without Servlet API
The fol开发者_运维技巧lowing Guice Servlet configuration doesn't work when I remove the Maven dependency to the Servlet API:
filter("/*").through(TransactionFilter.class);
The compiler tells me:
cannot access javax.servlet.Filter
class file for javax.servlet.Filter not found
filter("/*").through(TransactionFilter.class);
Any idea?
What do you expect to happen when you remove the Servlet API dependency? Guice Servlet depends on the Servlet API.
Clarification edit: Guice Servlet has a provided
scope dependency on the Servlet API so that the jar for it isn't pulled in to the final artifact when building an application... the API classes are provided by the application server at runtime. Thus, you must declare a dependency on the Servlet API in your application's POM yourself (preferably in provided
scope as well) in order to use it. This really makes the most sense, though, since you have to declare Servlet
s and Filter
s for your application regardless of whether you're using Guice Servlet or not.
精彩评论