springMVC 不扫描 controller 中的方法

来源:互联网 发布:linux tar命令出错 编辑:程序博客网 时间:2024/05/20 03:47

最近把之前的一个Maven项目在一个新的电脑环境上导入Eclipse,启动时却发现不扫描 controller 中的方法

下面是正确的 spring-mvc.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: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-3.1.xsd                          http://www.springframework.org/schema/context                          http://www.springframework.org/schema/context/spring-context-3.1.xsd                          http://www.springframework.org/schema/mvc                          http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"><mvc:annotation-driven /><mvc:resources location="/image/" mapping="/image/**" /><mvc:resources location="/Content/" mapping="/Content/**" /><mvc:resources location="/js/" mapping="/js/**" /><!-- 自动扫描该包,使SpringMVC认为包下用了@controller注解的类是控制器 --><context:component-scan base-package="com.aven.weixiao.controller" /><!--避免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><!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 --><beanclass="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><property name="messageConverters"><list><ref bean="mappingJacksonHttpMessageConverter" /><!-- JSON转换器 --></list></property></bean><!-- 定义跳转的文件的前后缀 ,视图模式配置 --><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 --><property name="prefix" value="/" /><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></beans>
那我遇到这个问题的原因是什么呢?

是因为新配置的环境,缺少很多 jar 包,所以项目导入Eclipse之后,  这个文件就报 “<mvc:annotation-driven />” 这一句有错了,

有错,我也没多想就先把它给删除了。

好吧,问题就这样产生了。

小结

在导入一个项目之后,可能会提示有很多错误,但针对一些配置文件,解决的方式不应该是删除或修改文件中的内容,

而应该先解决依赖等问题,不然像我这种之前没有问题的项目,就因为换了环境就产生怪问题。

======================文档信息===========================

版权声明:非商用自由转载-保持署名-注明出处

署名(BY) :testcs_dn(微wx笑)

文章出处:[无知人生,记录点滴](http://blog.csdn.net/testcs_dn)

1 0