在学习ssm框架整合的过程中,发现如果在springmvc.xml配置文件中,使用<mvc:annotation-driven/>来进行 controller适配器和管理器的配置时,
虽然会自动 配置RequestMappingHandlerMapping和RequestMappingHandlerAdapter,不用使用 bean配置,
但是也会自动引入 .../schema/cache 的命名空间,这个约束会将 <tx:...>约束给替换掉,在启动时出现 cacheManager找不到或是未定义的异常;
解决方案:1:抛弃<mvc:annotation-driven/>,只使用:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean>
来进行配置,但是会失去 <mvc:annotation-driven/>带来的许多参数绑定的益处;
2:将自动引入的 xml约束和命名空间进行修改(在不需要mvc的cache,缓存的条件下,将schema/cache进行修改),修改为:
xmlns:mvc="http://www.springframework.org/schema/mvc"
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
则可以使用,不冲突
截图如下: