在DispatcherServlet中找不到带有URI [/]的HTTP请求的映射,其名称为' mvc-dispatcher'

时间:2015-05-10 21:22:57

标签: spring-mvc

这是我的Web.xml

<display-name>Spring MVC Application</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/application-context.xml</param-value>
</context-param>

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

<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

以下是代码:application-context.xml:

<context:property-placeholder location="classpath:jdbc.properties" system-properties-mode="ENVIRONMENT"/>
<context:component-scan base-package="com.springapp.mvc.repository"/>

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory">

    </property>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value = "${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.databaseurl}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</bean>

<bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref = "dataSource"/>
    <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.dialect">${jdbc.dialect}</prop>
            <prop key="hibernate.connection.charSet">UTF-8</prop>
        </props>
    </property>
</bean>

MVC-调度-servlet.xml中:

<context:component-scan base-package="com.springapp.mvc.controller"/>

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



<mvc:resources mapping="/res/**" location="/res/"/>

当我尝试运行项目服务器时会发出警告: 警告org.springframework.web.servlet.PageNotFound.noHandlerFound在DispatcherServlet中找不到带有URI [/]的HTTP请求的映射,名称为&#39; mvc-dispatcher&#39;

请告诉我出了什么问题。

2 个答案:

答案 0 :(得分:0)

尝试删除连字符&#34; - &#34;在&#34; mvc-dispatcher&#34;到&#34; mvcdispatcher&#34;。

答案 1 :(得分:0)

更新url-pattern标签,如下所示。请注意斜杠(/)

后面的星号(*)
<url-pattern>/*</url-pattern>