java - Spring 应用程序在 eclipse 中工作,但在 tomcat 8 上部署时同样不工作

标签 java eclipse spring tomcat spring-security

我正在使用 maven,eclipse。从 Eclipse 运行时一切正常。 但同样,如果我在 tomcat 上部署,它会返回 http 状态 404。 日志显示在类路径上未检测到 Spring WebApplicationInitializer 类型,但我正在使用 web.xml

我无法弄清楚这里的问题,如果有人可以帮忙的话。 过滤器和 servlet 映射没有问题。

网络.xml

上下文类 org.springframework.web.context.support.AnnotationConfigWebApplicationContext

<!-- Location of Java @Configuration classes that configure the components 
    that makeup this application -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.asuare.temapp</param-value>
</context-param>

<context-param>
    <param-name>org.atmosphere.cpr.sessionSupport</param-name>
    <param-value>true</param-value>
</context-param>

<!-- Specifies the default mode of this application, to be activated if 
    no other profile (or mode) is specified -->
<context-param>
    <param-name>spring.profiles.default</param-name>
    <param-value>mysql</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Secures the application -->

安全过滤器 org.springframework.web.filter.DelegatingFilterProxy 目标Bean名称 springSecurityFilterChain 真的

<filter-mapping>
    <filter-name>securityFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <async-supported>true</async-supported>
</filter-mapping>

<!-- Handles requests into the application -->
<servlet>

    <servlet-name>temapp</servlet-name>
    <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
    <async-supported>true</async-supported>
    <init-param>
        <param-name>org.atmosphere.servlet</param-name>
        <param-value>org.springframework.web.servlet.DispatcherServlet</param-value>
    </init-param>
    <!-- No explicit configuration file reference here: everything is configured 
            in the root container for simplicity -->
    <init-param>
        <param-name>contextClass</param-name>
        <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </init-param>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>
    <servlet-name>temapp</servlet-name>
    <url-pattern>/</url-pattern>
    <async-supported>true</async-supported>
</servlet-mapping>

<filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>
        com.opensymphony.module.sitemesh.filter.PageFilter
    </filter-class>
    <async-supported>true</async-supported>
</filter>

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <async-supported>true</async-supported>    
</filter-mapping>

<error-page>
    <error-code>403</error-code>
    <location>/denied</location>
</error-page>

<error-page>
    <error-code>401</error-code>
    <location>/restapi/denied</location>
</error-page>

服务器日志:

24-Jul-2016 13:20:57.816 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath 24-Jul-2016 13:20:58.331 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext 24-Jul-2016 13:21:25.913 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'sportingEasy' 24-Jul-2016 13:21:42.699 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath 24-Jul-2016 13:22:02.971 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath 24-Jul-2016 13:22:03.034 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized() 24-Jul-2016 13:22:03.034 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized() 24-Jul-2016 13:22:48.611 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath

最佳答案

我也遇到了同样的问题。我的 maven 有 tomcat7 插件,但 JRE 环境是 1.6。我将我的 tomcat7 更改为 tomcat6,错误消失了。你能检查一下你的 JRE 环境并尝试吗? 另外请在您的 pom.xml 中添加“maven-war-plugin”版本 2.6

关于java - Spring 应用程序在 eclipse 中工作,但在 tomcat 8 上部署时同样不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38549346/

相关文章:

java - Crystal 报表在查看器中工作,在日期范围的应用程序中不起作用

java - 通过 Java SDK 和 AWS 控制台上传时列出不同的 S3 对象

c++ - Eclipse--如何查找已定义函数的使用位置

android - Eclipse Android 插件中的 "Debug certificate expired"错误

java - 如何在不使用 Matlab 编译器的情况下从 JAVA 使用 Matlab

Java Swing JTextArea 镜像

java - Eclipse LogCat 不保留文本

java - Jasypt加密-加密时删除斜杠

java - 我应该如何通过 Struts 操作连接和使用我的核心类?

java - 从 Spring MVC 中的 Controller 操作重定向到外部 URL