spring 3.0 spring-servlet.xml配置【转】

本文详细介绍了Spring MVC框架的配置方法,包括如何通过XML配置文件来定义Bean、使用注解驱动、配置拦截器及视图解析器等内容,并展示了如何整合FreeMarker作为模板引擎。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spring-util-2.0.xsd 在spring源码的
spring-framework-2.5.6\dist\resources目录下可找到


<?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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值