这是我开发常用的spring基本配置模板,备忘。 <?xml version="1.0" encoding="UTF-8"?> <!-- Bean头部 --> <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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <!-- 加载权限设置 --> <bean id="security" class="com.boaotech.util.Security" p:contextConfigLocation="WEB-INF/security.xml" /> <!-- 加载菜单项 --> <bean id="menus" class="com.boaotech.util.Menus" p:contextConfigLocation="WEB-INF/menus.xml" p:security-ref="security" /> <!-- Json返回格式化转换 --> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /> <!-- 设置全局日期参数的字符串表示格式 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="webBindingInitializer"> <bean class="com.boaotech.util.CommonBindingInitializer"/> </property> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter"/> </list> </property> </bean> <!-- 激活@Controller模式 --> <mvc:annotation-driven /> <!-- 对包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 需要更改--> <context:component-scan base-package="com.boaotech.zhaotaoerp" /> <context:annotation-config/> <!-- 激活计划任务注解 --> <task:annotation-driven executor="myExecutor" scheduler="myScheduler"/> <task:scheduler id="myScheduler" pool-size="1"/> <task:executor id="myExecutor" pool-size="1"/> <!-- 配置拦截器 --> <mvc:interceptors> <bean id="authorizeInterceptor" class="com.boaotech.util.AuthorizeInterceptor" /> </mvc:interceptors> <!-- 类名到视图名的自动映射 --> <!-- bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/ --> <!-- FreeMarker配置文件 --> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/ftl/"/> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">5</prop> <prop key="default_encoding">UTF-8</prop> <prop key="locale">zh_CN</prop> </props> </property> </bean> <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver" p:cache="true" p:prefix="" p:suffix=".ftl" p:contentType="text/html;charset=UTF-8" p:exposeRequestAttributes="true" p:exposeSessionAttributes="true" /> <!-- bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:viewClass="org.springframework.web.servlet.view.JstlView" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" / --> </beans>