Spring MVC configuration throws weird exception

2019-06-04 02:34发布

I am trying to deploy a new spring MVC app, I've done it a dozen times, but now I run on a really weird error, can't even figure out what's happening:

  1. My javaee-api is conflicting with the servlet-api. In the console it writes:

       INFO: validateJarFile(E:\development\workspace\conference\src\main\webapp\WEB-    INF\lib\javaee-api-6.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2.
       Offending class: javax/servlet/Servlet.class
    

Well, yes, it is a warning, but this jar is not loaded and I need it. Also, I have no servlet-api jars in my application libs, etc.

  1. Also, the console throws such an exception:

     SEVERE: Error configuring application listener of class com.sun.faces.config.ConfigureListener
     java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
    

I mean, this jar is refered to the JSF and all of that stuff. I'm not using it at all, where should it try to get such a class? O_o

I am running the app on tomcat 7

Any ideas what is going on?

2条回答
一夜七次
2楼-- · 2019-06-04 03:08

The problem with jar file is that Tomcat's classloader validates all clases, that it loads to JVM. In your case it faced a class from servlets API - javax.servlet.Servlet. You application code must not contain such classes inside WEB-INF/lib. These classes are shipped with servlet container itself. If you use maven, just change the scope of javax.servlet:servlet-api to provided.

After you fix this, try to reload the whole app, because it may occur that classloader just blocked javaee-api-6.0.jar entirely, not allowing any other classes be loaded from it.

查看更多
贪生不怕死
3楼-- · 2019-06-04 03:15

You can remove the javaee-api-6.0.jar file from your webapps' WEB-INF/lib directory, by setting the scope provided in its dependency.

The Spec refers that the Servlet Container (Here, Tomcat) will supply the implementation classes of the Java EE spec. Having application specific implementations is a stability and security problem that is disallowed by the spec/Tomcat.

Thanks!

查看更多
登录 后发表回答