首先是bean.xml,配置所有的bean,一般也叫applicationContext.xml,应用程序上下文。示例:

<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"> <context:component-scan base-package="com.guangshan" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan> <bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${c3p0.driverClass}"></property>
<property name="jdbcUrl" value="${c3p0.url}"></property>
<property name="user" value="${c3p0.user}"></property>
<property name="password" value="${c3p0.password}"></property>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"></property>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"></property>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
<property name="minPoolSize" value="${c3p0.minPoolSize}"></property>
<property name="acquireRetryDelay" value="1000"></property>
<property name="acquireRetryAttempts" value="60"></property>
<property name="breakAfterAcquireFailure" value="false"></property>
</bean> <bean id="propertyConfigurer"
class="com.guangshan.framework.core.SpringPropertiesUtil" lazy-init="false">
<property name="locations">
<list>
<value>classpath:config/sys.properties</value>
</list>
</property>
</bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean> <bean id="jdbcTxManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> <tx:annotation-driven transaction-manager="jdbcTxManager"></tx:annotation-driven> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="2097152"/>
</bean>

  若只用Spring做View层时,还有一个mvc-dispatcher-servlet.xml调度文件,示例

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
</list>
</property>
<property name="synchronizeOnSession" value="true"/>
</bean> <mvc:annotation-driven/> <!-- 静态资源访问 --> <mvc:resources location="/assets/**" mapping="/assets/**"/>
<mvc:resources location="/public/**" mapping="/public/**"/>
<mvc:resources location="/aui/**" mapping="/aui/**"/>
<mvc:resources location="/docs/**" mapping="/docs/**"/> <context:component-scan base-package="com.guangshan" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <!-- freemarker-->
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"
p:exposeSpringMacroHelpers="true">
<property name="prefix" value=""/>
<property name="suffix" value=".ftl"/>
<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="/WEB-INF/views/"/>
<property name="freemarkerSettings">
<props>
<prop key="defaultEncoding">UTF-8</prop>
<prop key="auto_import">common.ftl as c</prop>
<prop key="number_format">0.##</prop>
</props>
</property>
</bean> <!---jade -->
<bean id="templateLoader" class="de.neuland.jade4j.spring.template.SpringTemplateLoader">
<property name="basePath" value="/WEB-INF/view/"/>
</bean> <bean id="jadeConfiguration" class="de.neuland.jade4j.JadeConfiguration">
<property name="prettyPrint" value="false"/>
<property name="caching" value="false"/>
<property name="templateLoader" ref="templateLoader"/>
</bean> <bean id="viewResolver" class="de.neuland.jade4j.spring.view.JadeViewResolver">
<property name="configuration" ref="jadeConfiguration"/>
<property name="renderExceptions" value="true"/>
</bean> <!--jsp-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean> <mvc:interceptors>
<bean class="com.guangshan.framework.core.MvcInterceptor"></bean>
</mvc:interceptors> </beans>

3、在web.xml中,可以定义上一个文件的位置


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- log4j 配置 --> <context-param>
<param-name>webAppRootKey</param-name>
<param-value>rs.root</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>3000</param-value>
</context-param> <listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener> <!-- Spring注册容器所需要的配置 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 自定义启动 -->
<listener>
<listener-class>
com.ruishengtech.rscc.crm.ui.SysInitListener
</listener-class>
</listener> <!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/applicationContext.xml
</param-value>
</context-param> <servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<init-param>
<param-name>dispatchOptionsRequest</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet> <servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> <session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>

最新文章

  1. C#基础篇 - 理解委托和事件
  2. jQuery css3仿游戏网站右键环形菜单
  3. IOS开发之TabBarItem&amp;NavigationBarItem
  4. C# Unicode编码
  5. semantic-ui使用gulp执行build-css报错
  6. LightOJ 1220 Mysterious Bacteria 水题
  7. 解决Flash挡住层用z-index无效的问题
  8. java遍历map方法
  9. 解决子元素用css float浮动后父级元素高度自适应高度
  10. Spring的&lt;context:property-placeholder.../&gt;在junit中不起作用,失效,解决方法
  11. 总结JS中string、math、array的常用的方法
  12. ABP文档笔记 - 数据过滤
  13. xss攻击与防御
  14. Hadoop-HA机制工作原理
  15. weblogic Patch
  16. VS2019预览版发布了
  17. 使用 git log、git diff 命令时出现 ESC[33 和 ESC[m 乱码的解决办法
  18. shiro中SSL
  19. Next.js v4.1.4 文档中文翻译【转载】
  20. SRVE0255E: 尚未定义要处理 ***的 Web 组/虚拟主机。

热门文章

  1. week-02 线性表
  2. 嵌入式媒体处理(EMP)中的编码和解码
  3. java中split的用法即回顾
  4. 初学者手册-IDEA常用快捷键
  5. Java中的阻塞和非阻塞IO包各自的优劣思考(经典)
  6. C#根据字体名通过注册表获取该字体文件路径(win10)两种方法推荐第二种
  7. cocos2d-x v3.3开发环境配置
  8. AJAX的流程是什么?
  9. js(react.js) button click 事件无法触发
  10. 第一次接触python:学习最简单的print及变量