错误:找不到带URI的HTTP请求的映射。如何解决?

时间:2016-03-21 22:50:35

标签: spring jetty

我的项目有问题。当我浏览http://localhost:8080/user/form以显示UserForm时,会出现以下错误:

  

警告:找不到带有URI [/ user / form]的HTTP请求的映射   DispatcherSe rvlet,名称为'userservice'

此处归档UserRestServiceController.java

package edu.java.spring.service.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;

import edu.java.spring.service.user.dao.UserDao;
import edu.java.spring.service.user.model.User;

@Controller
public class UserRestServiceController {
    @Autowired
    private UserDao userDao;
    @Autowired
    private View jsonView;
    @RequestMapping(value="/user/form,",method = RequestMethod.GET)
    public ModelAndView user(){
//      System.out.println("anh yeu em ");
        return new ModelAndView("UserForm","User",new User());
    }
    @RequestMapping(value="/user/json/{username}")
    public ModelAndView loadUser(@PathVariable("username")String name){
        return new ModelAndView(jsonView,"data",userDao.loadUser(name));
    }


}

此处归档userservice-servlet.xml

<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd ">
    <context:component-scan base-package="edu.java.spring.service.user.controller"></context:component-scan>
    <context:component-scan base-package="edu.java.spring.service.user.dao"></context:component-scan>
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="order" value="1" />
        <property name="suffix" value=".jsp" />
        <property name="prefix" value="/user/" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>

        </property>
        <property name="mappingLocations">
            <list>
                <value>classpath:User.hbm.xml</value>
            </list>
        </property>

        <property name="packagesToScan" value="edu.java.spring.service.user.model" />
    </bean>
    <bean id="transactionManager"  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
        <property name="url"
            value="jdbc:derby:D:\PROJECTSPRING\userdb;create=true" />
        <property name="username" value="" />
        <property name="password" value="" />
    </bean>
    <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
        <property name="contentType" value="text/plain"/>
    </bean>
</beans>

1 个答案:

答案 0 :(得分:0)

在您的班级添加@RequestMapping(value="/user"),并在方法级别

删除该部分路径