Spring4.0.9+SpringMVC4.0.9+SpringSecurity3.2.5+MyBatis3.2.5+Activiti5.21即:SSM框架的企业级搭建
前言大纲:
经过两年多的实际开发,感觉现在到了一个瓶颈。没有什么头绪,所以就打算录一套视频教程给自己梳理一下这两年来的经验与技术,并与大家分享一下。 希望对我自己以后的职业道路能有个清晰的认知,并对刚刚入行的同学们以及和我一样现在有瓶颈又有些技术道路迷惑的人一点帮助,仅此而已。谢谢! 每一期视频教程不超过30分钟。这样既不太长又不太短。本套视频主要讲解:Spring4.0.9+SpringMVC4.0.9+SpringSecurity3.2.5+MyBatis3.2.5+Activiti5.21即:SSM框架的企业级搭建(可二次开发)(如果有可能还会加入消息中间件ActiveMQ) 本套视频致力于为广大程序员提供一个快捷的学习途径和供有想法的人进行项目的二次开发 注:在本套视频讲解如果因本人的水平不够亦或者讲的不对请大家指正(本人QQ:1728709667) 视频和博客尽可能每周一更新或者间距更短,最近因项目时间紧任务重所以总在加班,希望看博客或是的童鞋们见谅啦!
视频第一讲:(配套博客CSDN)
1、第一讲主要告诉大家spring、springSecurity、mybatis的下载途径; spring4.0.9相关jar包下载网址:http://repo.spring.io/release/org/springframework/spring/ springSecurity3.2.5相关jar包下载网址:http://repo.spring.io/release/org/springframework/spring/ mybatis3.2.5相关jar包下载网址:https://github.com/mybatis/mybatis-3/releases2、在下载好相关jar的基础上,开始创建项目引入相关jar包; 2.1/创建项目 (在创建项目之前先要确定编码规则,以及这个包(文件夹)的功能及其作用) 创建一个名为ssm的项目名称 在项目下分别有两个文件夹:src(存放项目源码)、config(存放项目配置文件) src下创建包名为:com.xxx.ssm(公司+项目名称或再加上项目组名称) 在其下分别为:action:存放mvc视图方法跳转类 annotation:存放自定义注解 constant:存放自定义常量
dao:存放数据持久化相关类
interceptor:存放自定义拦截器 listener:存放自定义监听器 model:存放实体对象 security:存放安全验证相关类 service:存放服务层接口 utils:存放相关工具类 WebContent下:建立resources文件夹(用于存放相关资源文件) resources下分别为: common:存放公用资源文件
WEB-INF下:分为lib文件夹(存放相关依赖jar包) view文件夹(存放jsp页面) 2.2/引入jar包: spring及其SpirngMVC相关jar,这里截图:css:存放css样式表images:存放图片js:存放系统前台框架jsuserdefinejs:存放自定义js文件resources.jsp:引入相关css、js文件
3、配置好相关project的配置文件(properties文件); 3.1/ beans-datasource.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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" 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.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd "> <!-- 注入方式可以用annotation --> <context:annotation-config /> <!-- 自动检测需要注册对象的包 --> <context:component-scan base-package="com.xxx"> <!--制定扫包规则,不扫描@Controller注解的JAVA类,其他的还是要扫描 --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 允许注解方式的AOP --> <aop:aspectj-autoproxy/> <!-- 引入外部properties文件 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <!-- 这里支持多种寻址方式:classpath和file推荐使用file的方式引入,这样可以将配置和代码分离 --> <value>classpath:jdbc.properties</value> <value>classpath:sysconfig.properties</value> </list> </property> </bean> <!-- 注入数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- 池启动时创建的连接数量 --> <property name="initialSize" value="${jdbc.initialSize}" /> <!-- 最大连接数据库连接数,设 0 为没有限制 --> <property name="maxActive" value="${jdbc.maxActive}" /> <!-- 最大等待连接中的数量,设 0 为没有限制 --> <property name="maxIdle" value="${jdbc.maxIdle}" /> <!-- 最大等待毫秒数, 单位为 ms, 超过时间会出错误信息 --> <property name="maxWait" value="${jdbc.maxWait}" /> </bean> <!-- 配置ehcache的二级缓存策略 --> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcache"/> <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" p:shared="true"/> <!-- 创建SqlSessionFactory,同时指定数据源 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="configLocation" value="classpath:mybatis.xml"/> <!-- 自动扫描需要定义类别名的包,将包内的JAVA类的类名作为类别名 --> <property name="typeAliasesPackage" value="com.xxx.ssm.model"></property> </bean> <!-- 注解方式配置事物 使用声明式事务 transaction-manager:引用上面定义的事务管理器 --> <!-- <tx:annotation-driven transaction-manager="transactionManager" /> --> <!-- 配置事务管理器 DataSourceTransactionManager dataSource:引用上面定义的数据源 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 定义个通知,指定事务管理器 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes > <tx:method name="*" propagation="REQUIRED" read-only="false" rollback-for="Throwable" /> <tx:method name="load*" propagation="SUPPORTS" read-only="true"/> <tx:method name="find*" propagation="SUPPORTS" read-only="true"/> <tx:method name="search*" propagation="SUPPORTS" read-only="true"/> <tx:method name="query*" propagation="SUPPORTS" read-only="true"/> <tx:method name="select*" propagation="SUPPORTS" read-only="true"/> <tx:method name="get*" propagation="SUPPORTS" read-only="true"/> </tx:attributes> </tx:advice> <aop:config expose-proxy="true"> <aop:pointcut id="transactionPointCut" expression="execution(* com.xxx.*.service..*.*(..))" /> <aop:advisor pointcut-ref="transactionPointCut" advice-ref="txAdvice" order="1" /> </aop:config> <bean id="sessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" scope=""> <!-- <constructor-arg index="0" ref="sqlSessionFactory"/> --> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <!-- Mapper接口所在包名,Spring会自动查找其下的类 自动扫描所有的Mapper接口与文件 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.xxx.ssm.dao.*" /> <property name="sqlSessionTemplateBeanName" value="sessionTemplate"></property> </bean> </beans>------------------------------------------------------------------------------------------------ 3.2/ beans-mapper.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"xmlns:cache="http://www.springframework.org/schema/cache" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-4.0.xsdhttp://www.springframework.org/schema/cachehttp://www.springframework.org/schema/cache/spring-cache.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd"></beans>
-------------------------------------------------------------------------------------------------- 3.3/ beans-security.xml -------------------------------------------------------------------------------------------------- 暂时不做这块 -------------------------------------------------------------------------------------------------- 3.4/ ehcache.xml -------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"><!--设置缓存文件 .data 的创建路径。如果该路径是 Java 系统参数,当前虚拟机会重新赋值。下面的参数这样解释:user.home – 用户主目录user.dir – 用户当前工作目录java.io.tmpdir – 默认临时文件路径,就是在tomcat的temp目录--><diskStore path="java.io.tmpdir"/><!-- 缓存位置可以是自定义的硬盘地址也可以是JVM默认使用的缓存地址 --><!--<diskStore path="d:cache"/> --><!-- 配置自定义缓存name:Cache的唯一标识maxElementsInMemory:缓存中允许创建的最大对象数maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大eternal:Element是否永久有效,一但设置了,timeout将不起作用,对象永不过期。timeToIdleSeconds:缓存数据的钝化时间,也就是在一个元素消亡之前,两次访问时间的最大时间间隔值,这只能在元素不是永久驻留时有效,如果该值是 0 就意味着元素可以停顿无穷长的时间。timeToLiveSeconds:缓存数据的生存时间,也就是一个元素从构建到消亡的最大时间间隔值, 这只能在元素不是永久驻留时有效,如果该值是0就意味着元素可以停顿无穷长的时间。overflowToDisk:内存不足时,是否启用磁盘缓存。diskPersistent:是否缓存虚拟机重启期数据diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区memoryStoreEvictionPolicy:缓存满了之后的淘汰算法。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)<cache name="SimplePageCachingFilter"maxElementsInMemory="10000"eternal="false"overflowToDisk="false"timeToIdleSeconds="900"timeToLiveSeconds="1800"memoryStoreEvictionPolicy="LFU" /> --><defaultCache name="org.taha.cache.METHOD_CACHE"eternal="false"maxElementsInMemory="10000"overflowToDisk="false"diskPersistent="false"timeToIdleSeconds="0"timeToLiveSeconds="600"memoryStoreEvictionPolicy="LRU" /></ehcache>
----------------------------------------------------------------------------------------------------------------------------------------- 3.5/ jdbc.properties -------------------------------------------------------------------------------------------------------------------------------------- #jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@localhost:1521:ORCL#jdbc.username=cms#jdbc.password=123456#jdbc.Driver=oracle.jdbc.driver.OracleDriver#connection pool Max count#dbc.maxActive=10#Waiting for the connection Max count#jdbc.maxIdle=0#jdbc.initialSize=5#jdbc.maxWait=1000jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriverjdbc.url=jdbc:sqlserver://localhost:1433;DatabaseName=ssmjdbc.username=sajdbc.password=123456jdbc.Driver=com.microsoft.sqlserver.jdbc.SQLServerDriver#connection pool Max countjdbc.maxActive=10#Waiting for the connection Max countjdbc.maxIdle=0jdbc.initialSize=5jdbc.maxWait=1000jdbc.type=orcale
-------------------------------------------------------------------------------------------------- 3.6/ log4j.properties
-------------------------------------------------------------------------------------------------
#
# Log4J Settings for log4j 1.2.x (via jakarta-commons-logging)## The five logging levels used by Log are (in order):## 1. DEBUG (the least serious)# 2. INFO# 3. WARN# 4. ERROR# 5. FATAL (the most serious)# Set root logger level to ERROR and append to stdoutlog4j.rootLogger=all, stdout, Platform, db, FILElog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayout# Pattern to output the caller"s file name and line number.log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p [%t](%c:%L) %x- %m%n# Print only messages of level ERROR or above in the package noModule.log4j.logger.noModule=ERRORlog4j.logger.org.apache.log4j=ERROR# OpenSymphony Stufflog4j.logger.com.opensymphony=ERROR# Spring Stufflog4j.logger.org.springframework=INFOlog4j.logger.org.hibernate=WARNlog4j.appender.FILE=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.FILE.File=${catalina.home}/logs/ALESP/ALESP_sys_runtime_log.loglog4j.appender.FILE.DatePattern="."yyyy-MM-ddlog4j.appender.FILE.layout=org.apache.log4j.PatternLayoutlog4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p [%t](%c:%L) %x- %m%n
-------------------------------------------------------------------------------------------------
4、运行项目没问题,开始准备下一讲; 给大家先看一下教程结束最终的项目界面:(基于rabc的权限控制(细粒度控制到按钮级别的))
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了