qq_35649402
你们让我起个名啊
采纳率42.3%
2017-07-31 01:09 阅读 3.6k

springMVC无法进入controller的问题

springmvc一直无法进入controller导入404的问题
下帖配置文件:

springmvc

 <?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:p="http://www.springframework.org/schema/p"
    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-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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd  ">

<mvc:annotation-driven/>

                         <!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 -->
    <context:component-scan base-package="com.controller" />
    <context:component-scan base-package="com.impl" /> invengo.warehouse.service.impl" /> 

     <!--避免IE执行AJAX时,返回JSON出现下载文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
        class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>


    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter" />   <!-- JSON转换器 -->
            </list>
        </property>
    </bean>

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

    <bean id="multipartResolver"  
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="utf-8" />  
        <!-- 文件大小最大值 -->
        <property name="maxUploadSize" value="10485760000" />  
        <!-- 内存中的最大值 -->
        <property name="maxInMemorySize" value="40960" />  
    </bean> 




    <context:annotation-config/>

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


 <!--    <mvc:resources location="" mapping=""/> -->
      <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
        <property name="basename"> 
            <value>message</value> 
        </property> 
        <property name="defaultEncoding"> 
            <value>UTF-8</value> 
        </property> 
    </bean> 

      <!-- 日期全局转换配置 -->
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">    
         <property name="converters">    
             <list>    
                 <bean class="com.lava.springmvc.DateConverter" />    
             </list>    
         </property>    
     </bean>  
                        </beans>

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns="http://java.sun.com/xml/ns/javaee" 
            xmlns:web="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_3_0.xsd" 
            version="3.0">
  <!-- Spring和mybatis的配置文件 -->


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext-*.xml</param-value>
    </context-param>
    <!-- 使用ContextLoaderListener保证启动时加载Spring -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
        <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>
         <!-- 编码过滤器 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


      <!-- 防止Spring内存溢出监听器 -->
    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
      <!-- Spring MVC servlet -->
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:/WEB-INF/applicationContext-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
       <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>

        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file>
    </welcome-file-list>
        <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

</web-app>

部分代码

 @Service("userService")
public class UserServiceImpl implements IUserService{
.....
}
@RestController
public class LoginController {

    @RequestMapping("captcha.jpg")
    public void captcha(HttpServletResponse response)throws ServletException,IOException{
    ......
    }
}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • q975583865 一点寒芒先至 2017-07-31 01:13

    @RequestMapping("captcha.jpg")把这一部分换一下试试,没见过这个,获取验证码用原生的servlet就好了

    点赞 评论 复制链接分享
  • qq_35498454 xhl_2017 2017-07-31 01:21

    web.xml 里面启动spring MVC 换成下面的试一下

    service
    org.springframework.web.servlet.DispatcherServlet
    1


    service
    *.do

    点赞 评论 复制链接分享
  • lizongbao1234567890 lionsarmstrong 2017-07-31 01:33

    配置文件里没有特殊配置的话,@RequestMapping("captcha.jpg")应该换成@RequestMapping("/captcha.jpg"),加上“/”之后才会查到。
    或者把
    SpringMVC

        <url-pattern>/</url-pattern>
    </servlet-mapping>里面“/”换成"/*"试试
    
    点赞 评论 复制链接分享
  • qq_16259463 疯雪 2017-07-31 01:41

    检查web.xml中如何配置的DispatcherServlet的配置,检查tomcat中给当前项目配置的访问路径

    点赞 评论 复制链接分享
  • qq_34309305 75闪光雷 2017-07-31 02:10
  • sxlfzhangjie sxlfzhangjie 2017-07-31 02:35

    图片说明
    图片说明

    点赞 评论 复制链接分享
  • Hendiaome 很叼么 2017-07-31 05:47

    已经被这个拦截器拦截了

    点赞 评论 复制链接分享
  • qq_26991807 逸然健在 2017-07-31 06:09

    检查一下url是不是输入错了

    点赞 评论 复制链接分享

相关推荐