找不到带URI的HTTP请求的映射[/ webstore]

时间:2016-05-09 10:47:01

标签: java spring tomcat8

当我尝试在tomcat服务器上运行我的spring应用程序时,我遇到了问题。我在浏览器中收到错误404,这在控制台中:

2016-05-09 12:26:03,188 INFO org.hibernate.tool.hbm2ddl.SchemaExport -  HHH000230: Schema export complete
2016-05-09 12:26:05,082 INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'DispatcherServlet': initialization completed in 5685 ms
2016-05-09 12:26:05,121 WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/webstore/] in DispatcherServlet with name 'DispatcherServlet'

这是我的web.xml文件:

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<filter>
    <filter-name>encoding-filter</filter-name>
    <filter-class>
        org.springframework.web.filter.CharacterEncodingFilter
    </filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encoding-filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/webcontext/DispatcherServlet-context.xml
        </param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
/WEB-INF/spring/webcontext/security-context.xml 

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener 
    </listener-class>
</listener>

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
        org.springframework.web.filter.DelegatingFilterProxy
</filter-class>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>



</web-app>
你能告诉我这是什么问题吗?这很奇怪,因为我不是唯一使用此代码的人,只有我有这个问题...

喔。我的DispatcherServlet.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


<import resource="classpath:spring/database-context.xml" />

<mvc:annotation-driven enable-matrix-variables="true">
    <mvc:message-converters>
        <bean
            class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="jsonObjectMapper" />
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

<context:component-scan base-package="pl.spring.demo" />

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages" />
</bean>

<bean id="jsonObjectMapper"
    class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean">
    <property name="objectMapper">
        <bean class="com.fasterxml.jackson.databind.ObjectMapper" />
    </property>
</bean>

1 个答案:

答案 0 :(得分:1)

您需要在应用服务器中检查以下几点:

  • 是否有部署错误消息?
  • 该应用程序已部署但具有不同的上下文? (例如/代替/webstore
  • 您是否拥有应用程序服务器的多个副本,但是您正在运行一个并尝试在另一个应用程序中部署应用程序?