The type javax.servlet.ServletContext and javax.servlet.ServletException cannot be resolved

前端 未结 5 2108
情书的邮戳
情书的邮戳 2020-12-14 01:06

I\'m trying to include Spring Security to my web project, i\'m following this tutorial http://docs.spring.io/spring-security/site/docs/current/guides/html5//helloworld.html<

5条回答
  •  执笔经年
    2020-12-14 01:30

    Just add the javax.servlet API to the compile time dependencies. You don't need to include it in the build, it's already provided by the target servlet container.

    Your current pom suggests that you're deploying to a barebones servlet container (Tomcat, Jetty, etc) instead of a full fledged Java EE application server (WildFly, TomEE, GlassFish, Liberty, etc), otherwise you'd have run into classloading-related trouble by providing JSF along with the webapp instead of using the container-provided one.

    In that case, adding the below dependency should do for a Servlet 3.1 container like Tomcat 8:

    
        javax.servlet
        javax.servlet-api
        3.1.0
        provided
    
    

    Or if you're actually targeting an older Servlet 3.0 container like Tomcat 7, change the to 3.0.1 (note: there's no 3.0 due to a mistake on their side).

    If you happen to actually deploy to a Java EE 7 application server like WildFly 8, use the below dependency instead. It covers the entire Java EE API, including javax.servlet (and javax.faces, so you'd then remove those individual JSF API/impl dependencies):

    
        javax
        javaee-api
        7.0
        provided
    
    

    Also here, if you're targeting an older Java EE 6 application server like JBoss AS 7, change the to 6.0.

提交回复
热议问题