RequestMappingHandlerMapping:219 - Did not find handler method for [/regist.do]

2017/03/15 16:37:39,083 DEBUG DispatcherServlet:823 - DispatcherServlet with name 'springDispatcherServlet' processing GET request for [/SSMproject/regist.do]
2017/03/15 16:37:39,085 DEBUG RequestMappingHandlerMapping:209 - Looking up handler method for path /regist.do
2017/03/15 16:37:39,085 DEBUG RequestMappingHandlerMapping:219 - Did not find handler method for [/regist.do]
2017/03/15 16:37:39,086  WARN PageNotFound:1108 - No mapping found for HTTP request with URI [/SSMproject/regist.do] in DispatcherServlet with name 'springDispatcherServlet'
2017/03/15 16:37:39,086 DEBUG DispatcherServlet:946 - Successfully completed request
2017/03/15 16:37:39,087 DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'sqlSessionFactory'

这个是RequestMappingHandlerMapping正在通过请求名匹配查找controller没有找到。
经过我一番查找
原先的配置着这样的(文章最后是我的解决方法

package com.hs.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hs.domain.common.User;
import com.hs.service.UserService;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("regist")
    public String regist(Model model,User user){
        User findUser = userService.findByUsername(user.getUsername());
        if(findUser==null){
            userService.save(user);
            model.addAttribute("message", "注册成功");
        }else{
            model.addAttribute("message", "用户名已经存在");
        }
        return "hello";
    }

    @RequestMapping("toregist")
    public String toRegist(){
        return "regist";
    }

}

web.xml文件是这样的


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>SSMprojectdisplay-name>

  
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
    listener>
    <context-param>
        <param-name>contextConfigLocationparam-name>
        <param-value>classpath:spring/applicationContext.xmlparam-value>
    context-param>

  
  <filter>
    <filter-name>characterEncodingFilterfilter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
    <init-param>
        <param-name>encodingparam-name>
        <param-value>utf-8param-value>
    init-param>
    <init-param>
        <param-name>forceEncodingparam-name>
        <param-value>trueparam-value>
    init-param>
  filter>
  <filter-mapping>
    <filter-name>characterEncodingFilterfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>
  
    <servlet>
        <servlet-name>springDispatcherServletservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        <load-on-startup>1load-on-startup>
        <init-param>
            <param-name>contextConfigLocationparam-name>
            <param-value>classpath:spring/springmvc.xmlparam-value>
        init-param>
    servlet>
    <servlet-mapping>
        <servlet-name>springDispatcherServletservlet-name>
        <url-pattern>*.dourl-pattern>
    servlet-mapping>

  <welcome-file-list>
    <welcome-file>welcome.jspwelcome-file>
  welcome-file-list>
web-app>

springmvc.xml文件是这样的


<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc.xsd
        ">


    <mvc:annotation-driven />
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/jsps/user/"/>
        <property name="suffix" value=".jsp"/>
    bean>
beans>

spring.xml文件中内容这样写的


<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    <context:component-scan base-package="com.hs"/>
    
    <context:property-placeholder location="classpath:db.properties"/>
    
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driverClass}"/>
        <property name="url" value="${jdbc.jdbcUrl}"/>
        <property name="username" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>
    bean>
     
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"/>
    bean>

    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    bean>

    
    <tx:advice id="txAdvicer" transaction-manager="transactionManager">
        <tx:attributes>
        <tx:method name="find*" propagation="REQUIRED"/>
        <tx:method name="get*" propagation="REQUIRED"/>
        <tx:method name="save*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="insert*" propagation="REQUIRED"/>
        <tx:method name="delete*" propagation="REQUIRED"/>
        <tx:method name="*" propagation="REQUIRED"/>
        tx:attributes>
    tx:advice>
    <aop:config>
        <aop:advisor advice-ref="txAdvicer" pointcut="execution(* com.hs.service.*.*(..))"/>
    aop:config>
    

    
    <bean  class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.hs.dao"/>
    
    bean>


beans>

bug改正之后的修改

其实就是一个扫描的配置写错了位置

<context:component-scan base-package="com.hs"/>

这行配置时必须要写在springmvc.xml文件中,因为加载该文件时,会扫描所有的加注解的controller,这样RequestMappingHandlerMapping才会找到这个对象

你可能感兴趣的:(bug)