SSM整理笔记3——配置解析
github:https://github.com/lakeslove/SSM
项目的目录结构如下

首先,配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>SSM</display-name> <!-- session和cookie的配置 -->
<session-config>
<session-timeout>40</session-timeout>
<cookie-config>
<name>SSM</name>
<http-only>true</http-only>
</cookie-config>
</session-config> <!-- 访问的首页的配置 -->
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
</welcome-file-list> <!-- springMVC的拦截器配置,这个是重点 -->
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 防止乱码的配置,这个配置的mapping一定要在loginFilter之前,否则loginFilte里乱码 -->
<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>
<servlet-name>spring-dispatcher</servlet-name>
</filter-mapping> <!-- 自定义的登录过滤器 -->
<filter>
<display-name>LoginFilter</display-name>
<filter-name>LoginFilter</filter-name>
<filter-class>com.lx.filter.LoginFilter</filter-class>
<init-param>
<param-name>indexPath</param-name>
<param-value>index.htm</param-value>
</init-param>
<init-param>
<param-name>ignoreList</param-name>
<param-value></param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>*.htm</url-pattern>
</filter-mapping> <!-- 错误页面,平常多用静态页面,这里用了动态页面,目的是为了对异常进行动态的处理 -->
<error-page>
<error-code>500</error-code>
<location>/testError.htm</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/testError.htm</location>
</error-page> <!-- 测试用的Servlet -->
<servlet>
<description></description>
<display-name>TestServlet</display-name>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.lx.servlets.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet.htm</url-pattern>
</servlet-mapping> <!-- 测试用的监听器 -->
<listener>
<listener-class>com.lx.listeners.TestListenser</listener-class>
</listener>
</web-app>
springMVC和spring的配置文件:spring-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.2.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd"> <context:property-placeholder location="classpath:system.properties" />
<context:annotation-config />
<!-- 使用注解管理事务 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<cache:annotation-driven cache-manager="cacheManager"/>
<task:executor id="taskExecutor" pool-size="1-20" queue-capacity="30" keep-alive="60" />
<task:scheduler id="scheduler" pool-size="1" />
<task:annotation-driven executor="taskExecutor" scheduler="scheduler" />
<!-- 需要扫描的包 start-->
<context:component-scan base-package="com.lx.controllers" />
<context:component-scan base-package="com.lx.services.impl" />
<!-- 需要扫描的包 end --> <mvc:annotation-driven />
<!-- 数据验证 start -->
<!-- 数据验证 end -->
<!-- viewResolver start -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="2" />
<property name="prefix">
<value>/WEB-INF/view/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean> <!-- tiles 配置开始 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="order" value="1" />
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles3.TilesView
</value>
</property>
</bean> <bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/classes/tilesPublic.xml</value>
</list>
</property>
</bean>
<!-- tiles 配置结束 -->
<!-- viewResolver end --> <!-- hibernate start-->
<!-- jndi start -->
<!--
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>${db.jndiname}</value>
</property>
</bean>
-->
<!-- jndi end --> <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
destroy-method="close">
<property name="url" value="${db.url}"></property>
<property name="driverClassName" value="${db.driver}"></property>
<property name="username" value="${db.username}"></property>
<property name="password" value="${db.password}"></property>
<property name="maxTotal" value="30" />
<property name="maxIdle" value="20" />
<property name="minIdle" value="5" />
<property name="initialSize" value="5" />
<property name="maxWaitMillis" value="-1" />
<property name="timeBetweenEvictionRunsMillis" value="120000" />
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="poolPreparedStatements" value="true" />
<property name="removeAbandonedOnBorrow" value="true" />
<property name="validationQuery">
<value>select 1 from dual</value>
</property>
</bean> <!-- 使用MyBatis-spring的sqlSessionFactory来代替MyBatis本身的sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml" />
</bean> <!-- 使用MyBatis-spring的sqlSessionTemplate来包装sqlSessionFactory -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" scope="prototype">
<constructor-arg index="0" ref="sqlSessionFactory" />
<!-- <constructor-arg index="1" value="BATCH" /> -->
</bean> <!-- 事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <!-- 采用自动扫描方式创建mappper bean -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com"/>
<property name="sqlSessionTemplateBeanName" value="sqlSessionTemplate"/>
<property name="annotationClass" value="org.springframework.stereotype.Repository"/>
</bean> <!-- 国际化(多语言对应) 开始 -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>message_error</value>
<value>message_generic</value>
<value>message_validate</value>
</list>
</property>
<property name="useCodeAsDefaultMessage" value="false" />
<property name="defaultEncoding" value="UTF-8" />
<property name="cacheSeconds" value="600" />
</bean>
<!-- 国际化(多语言对应) 结束--> <!-- 异常处理 start -->
<!-- <bean class="com.lx.exceptions.ExceptionHandler" /> -->
<bean id="exceptionResolver"
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>
</props>
</property>
</bean>
<!-- 异常处理 end --> <!-- 缓存支持 start -->
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean
class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="masterCache" />
</set>
</property>
</bean>
<!-- 缓存支持 end --> <!-- 文件上传限制 开始 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSize" value="10485760" />
<property name="maxInMemorySize" value="1048576" />
</bean>
<!-- 文件上传限制 结束 --> <!-- velocityEngine start-->
<bean id="velocityEngine"
class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="resourceLoaderPath">
<value>classpath:velocity</value>
</property>
<property name="velocityProperties">
<props>
<prop key="file.resource.loader.cache">false</prop>
<prop key="file.resource.loader.modificationCheckInterval">3</prop>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
</props>
</property>
</bean>
<!-- velocityEngine end --> <!-- sendEmail start -->
<!-- 解除默认的单例模式,设置scope="prototype" -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" scope="prototype">
<property name="host" value="${mail.host}" />
<property name="username" value="${mail.username}" />
<property name="password" value="${mail.password}" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
<prop key="mail.smtp.timeout">${mail.smtp.timeout}</prop>
<prop key="mail.smtp.port">${mail.smtp.port}</prop>
</props>
</property>
</bean>
<!-- sendEmail end --> <!-- IOC demo start -->
<!-- springFrome initiate check start -->
<!-- <bean class="com.lx.utils.CheckConfigs">
<property name="dbUrl" value="${db.url}" />
<property name="userDao">
<bean class="com.lx.daos.impl.UserDaoImpl" />
</property>
</bean> -->
<!-- initiate check end --> <!-- 在过滤器中注入service start-->
<bean id="userService" class="com.lx.services.impl.UserServiceImpl"></bean>
<!-- 在过滤器中注入service end--> <!-- IOC demo end--> <!-- AOP demo start -->
<!-- 切面类 -->
<bean id="appendLogsByAOP" class="com.lx.utils.AppendLogsByAOP"/>
<!-- 切入点 -->
<aop:config>
<aop:pointcut id="afterMethodPoint" expression="execution(* com.lx.controllers.publics.*Controller.*(..))"/>
<aop:aspect id = "appendLogs" ref="appendLogsByAOP">
<aop:before method="logOutputBeforeMethod" pointcut="execution(* com.lx.controllers.publics.*Controller.*(..))"/>
<aop:after-throwing method="logOutputAfterThrows" pointcut="execution(* com.lx.controllers.publics.*Controller.*(..))"/>
<!-- 可以用 pointcut-ref来指代相同的pointcut-->
<aop:after-returning method="logOutputAfterReturn" pointcut-ref="afterMethodPoint"/>
<aop:after method="logOutputAfterMethod" pointcut-ref="afterMethodPoint"/>
</aop:aspect>
</aop:config>
<!-- AOP demo end --> </beans>
SSM整理笔记3——配置解析的更多相关文章
- SSM整理笔记2——jar包整理
github:https://github.com/lakeslove/SSM 需要的jar包 springMVC和spring: spring.RELEASE.jar spring.RELEASE. ...
- SSM整理笔记1——SSM网站初步功能设计
前言 因为公司里一直用Hibernate,但是现在Mybatis是趋势,所以搭建一个Mybatis的网站框架,目的是:1摸清其功能特点,2为以后的项目增加框架选择(以前只用hibernate或者Spr ...
- 运维开发笔记整理-django日志配置
运维开发笔记整理-django日志配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Django日志 Django使用python内建的logging模块打印日志,Pytho ...
- nsq源码阅读笔记之nsqd(一)——nsqd的配置解析和初始化
配置解析 nsqd的主函数位于apps/nsqd.go中的main函数 首先main函数调用nsqFlagset和Parse进行命令行参数集初始化, 然后判断version参数是否存在,若存在,则打印 ...
- xmpp整理笔记:xmppFramework框架的导入和介绍
一个将要开发xmpp的项目,建议在项目刚创建就导入框架,这样可以避免一些自己操作失误造成不必要的损失. xmpp中最常用的框架就是 xmppFrameWork 往期回顾: xmpp整理笔记:环境的快速 ...
- SSM整合笔记
SSM整合笔记 1,创建maven项目 创建maven项目过程省略 ps:如果创建完maven项目之后项目报错,可能是没有配置Tomcat 2,在pom.xml里面导入相应的jar的依赖 <pr ...
- xmpp整理笔记:发送图片信息和声音信息
图片和音频文件发送的基本思路就是: 先将图片转化成二进制文件,然后将二进制文件进行base64编码,编码后成字符串.在即将发送的message内添加一个子节点,节点的stringValue(节点的值) ...
- xmpp整理笔记:聊天信息的发送与显示
任何一个信息的发送都需要关注两个部分,信息的发出,和信息在界面中的显示 往期回顾: xmpp整理笔记:环境的快速配置(附安装包) http://www.cnblogs.com/dsxniubilit ...
- xmpp整理笔记:用户网络连接及好友的管理
xmpp中的用户连接模块包括用户的上线与下线信息展现,用户登录,用户的注册: 好友模块包括好友的添加,好友的删除,好友列表的展示. 在xmpp中 负责数据传输的类是xmppStream,开发的过程中, ...
随机推荐
- WPF Custom Command And Binding
using System; using System.Collections.Generic; using System.Windows.Input; namespace WPF.Commands { ...
- 防火墙iptables介绍
防火墙: netfilter/iptables是集成在Linux2.4.X版本内核中的包过滤防火墙系统.该架构可以实现数据包过滤,网络地址转换以及数据包管理功能.linux中防火墙分为两部分:netf ...
- shit layui & bugs
shit layui & bugs use is not useful at all! http://www.layui.com/demo/form.html layui.use([" ...
- RSA工作原理
摘自:http://www.ruanyifeng.com/blog/2013/07/rsa_algorithm_part_two.html 一.基础数论 1.互质关系 如果两个正整数,除了1以外,没有 ...
- 刷题总结——选课(ssoj树形dp+记忆化搜索+多叉树转二叉树)
题目: 题目描述 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了 N(N<300)门的选修课程,每个学生可选课程的数量 M 是给定的.学生选修了这M门课 ...
- 【霍夫曼树】 poj 1521 Entropy
poj.org/problem?id=1521 注意只有特殊情况:只有一种字母 #include<iostream> #include<cstdio> #include< ...
- poj1426 - Find The Multiple [bfs 记录路径]
传送门 转:http://blog.csdn.net/wangjian8006/article/details/7460523 (比较好的记录路径方案) #include<iostream> ...
- Java 并发编程中的 CountDownLatch 锁用于多个线程同时开始运行或主线程等待子线程结束
Java 5 开始引入的 Concurrent 并发软件包里面的 CountDownLatch 其实可以把它看作一个计数器,只不过这个计数器的操作是原子操作,同时只能有一个线程去操作这个计数器,也就是 ...
- T3054 高精度练习-文件操作 codevs
http://codevs.cn/problem/3054/ 题目描述 Description 输入一组数据,将每个数据加1后输出 输入描述 Input Description 输入数据:两行,第 ...
- Codeforces 12 D Ball
Discription N ladies attend the ball in the King's palace. Every lady can be described with three va ...