我将spring-springMVC-mybatis的配置文件分开,该文件只做了注解开启,控制层扫描,和视图解析器
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-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/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<!--开启这个一会,springmvc会判断请求是静态还是动态.如果是动态就接着执行,静态的话就交给web服务器默认servlet执行 -->
<mvc:default-servlet-handler/>
<!-- 注册了俩个bean,DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter,@controllers注解必须用到的,默认开启 -->
<mvc:annotation-driven/>
<!-- 开启springmvc注解(@Autowired,@Resource,@Required等),但是当使用<context:component-scan>时,则不在需要开启它拉 -->
<context:annotation-config>
<!-- springMVC开启扫描器 -->
<context:component-scan base-package="org.cslc.platform.extinterface.service.impl" />
<!-- *****************freemarker充当视图解析器,放在InternalResourceViewResolver的前面,优先找freemarker start***************** -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="false" />
<property name="prefix" value="/index/"/>
<property name="suffix" value=".htm"/>
<property name="contentType" value="text/html; charset=UTF-8"/>
</bean>
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="" />
<property name="freemarkerSettings">
<props>
<prop key="template_update_delay">0</prop>
<prop key="default_encoding">UTF-8</prop>
<prop key="locale">zh_CN</prop>
</props>
</property>
</bean>
<!-- *****************放在InternalResourceViewResolver的前面,优先找freemarker end***************** -->
<!-- 视图解析器:逻辑视图 物理视图逻辑视图转化为物理视图时所需的前缀和后缀通过这个解析器可以定位到一个物理视图-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>