严重: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter] for bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0' defined in class path resource [springmvc-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter] for bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0' defined in class path resource [springmvc-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
原因是Spring 3.x 和4.X处理JSON的一个类不一样,而这个东西又配置在xml文件中,所以编译时又无法发现
spring3.x是org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
spring4.x是org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
https://www.iteye.com/topic/1136145
1. <context:annotation-config/>隐式的向Spring 容器注册
AutowiredAnnotationBeanPostProcessor,CommonAnnotationBeanPostProcessor,
PersistenceAnnotationBeanPostProcessor以及RequiredAnnotationBeanPostProcessor这4 个BeanPostProcessor,解决了@Controller标识的类的bean的注入和使用。
2. <mvc:annotation-driven/>隐式注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter,解决了@Controller注解的使用前提配置。
第一条中的配置一般在配置包扫描路径扫描之后将其移除,为什么呢:
<context:component-scan base-package="***.***"/> 该配置项其实也包含了自动注入上述"1"中四个bean processor的功能,因此当使用 <context:component-scan/> 后,就可以将 <context:annotation-config/>移除了。
你最后的疑问:不配置<mvc:annotation-driven/>,基本的访问应该是没问题,比如servlet mapping的配置是"*.do", ".do"这种请求可以被正确捕捉和处理,但是如果添加静态资源访问,你可能要将拦截改为"/",此时你再次访问就会发现已经不能被正常拦截了,除非你加上<mvc:annotation-driven/>。<mvc:annotation- driven/>在初始化的时候会自动创建两个对 象,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter 和 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter