`
dreamoftch
  • 浏览: 485258 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

马士兵spring视频笔记

阅读更多

课程内容

<!--[if !supportLists]-->1.     <!--[endif]-->面向接口(抽象)编程的概念与好处

<!--[if !supportLists]-->2.     <!--[endif]-->IOC/DI的概念与好处

<!--[if !supportLists]-->a)     <!--[endif]-->inversion of control

<!--[if !supportLists]-->b)     <!--[endif]-->dependency injection

<!--[if !supportLists]-->3.     <!--[endif]-->AOP的概念与好处

<!--[if !supportLists]-->4.     <!--[endif]-->Spring简介

<!--[if !supportLists]-->5.     <!--[endif]-->Spring应用IOC/DI(重要)

<!--[if !supportLists]-->a)     <!--[endif]-->xml

<!--[if !supportLists]-->b)     <!--[endif]-->annotation

<!--[if !supportLists]-->6.     <!--[endif]-->Spring应用AOP(重要)

<!--[if !supportLists]-->a)     <!--[endif]-->xml

<!--[if !supportLists]-->b)     <!--[endif]-->annotation

<!--[if !supportLists]-->7.     <!--[endif]-->Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2整合(重要)

<!--[if !supportLists]-->a)     <!--[endif]-->opensessionInviewfilter(记住,解决什么问题,怎么解决)

<!--[if !supportLists]-->8.     <!--[endif]-->Spring JDBC

面向接口编程(面向抽象编程)

<!--[if !supportLists]-->1.     <!--[endif]-->场景:用户添加

<!--[if !supportLists]-->2.     <!--[endif]-->Spring_0100_AbstractOrientedProgramming

<!--[if !supportLists]-->a)     <!--[endif]-->不是AOP:Aspect Oriented Programming

<!--[if !supportLists]-->3.     <!--[endif]-->好处:灵活

什么是IOCDI),有什么好处

<!--[if !supportLists]-->1.     <!--[endif]-->把自己new的东西改为由容器提供

<!--[if !supportLists]-->a)     <!--[endif]-->初始化具体值

<!--[if !supportLists]-->b)     <!--[endif]-->装配

<!--[if !supportLists]-->2.     <!--[endif]-->好处:灵活装配

Spring简介

<!--[if !supportLists]-->1.     <!--[endif]-->项目名称:Spring_0200_IOC_Introduction

<!--[if !supportLists]-->2.     <!--[endif]-->环境搭建

<!--[if !supportLists]-->a)     <!--[endif]-->只用IOC

<!--[if !supportLists]-->                i.          <!--[endif]-->spring.jar , jarkata-commons/commons-loggin.jar

<!--[if !supportLists]-->3.     <!--[endif]-->IOC容器

<!--[if !supportLists]-->a)     <!--[endif]-->实例化具体bean

<!--[if !supportLists]-->b)     <!--[endif]-->动态装配

<!--[if !supportLists]-->4.     <!--[endif]-->AOP支持

<!--[if !supportLists]-->a)     <!--[endif]-->安全检查

<!--[if !supportLists]-->b)     <!--[endif]-->管理transaction

Spring IOC配置与应用

<!--[if !supportLists]-->1.     <!--[endif]-->FAQ:不给提示:

<!--[if !supportLists]-->a)     <!--[endif]-->window – preferences – myeclipse – xml – xml catalog

<!--[if !supportLists]-->b)     <!--[endif]-->User Specified Entries – add

<!--[if !supportLists]-->                 i.          <!--[endif]-->Location:       D:\share\0900_Spring\soft\spring-framework-2.5.6\dist\resources\spring-beans-2.5.xsd

<!--[if !supportLists]-->                ii.          <!--[endif]-->URI:             file:///D:/share/0900_Spring/soft/spring-framework-2.5.6/dist/resources/spring-beans-2.5.xsd

<!--[if !supportLists]-->               iii.          <!--[endif]-->Key Type:      Schema Location

<!--[if !supportLists]-->              iv.          <!--[endif]-->Key:              http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

<!--[if !supportLists]-->2.     <!--[endif]-->注入类型

<!--[if !supportLists]-->a)     <!--[endif]-->Spring_0300_IOC_Injection_Type

<!--[if !supportLists]-->b)     <!--[endif]-->setter(重要)

<!--[if !supportLists]-->c)     <!--[endif]-->构造方法(可以忘记)

<!--[if !supportLists]-->d)     <!--[endif]-->接口注入(可以忘记)

<!--[if !supportLists]-->3.     <!--[endif]-->id vs. name

<!--[if !supportLists]-->a)     <!--[endif]-->Spring_0400_IOC_Id_Name

<!--[if !supportLists]-->b)     <!--[endif]-->name可以用特殊字符

<!--[if !supportLists]-->4.     <!--[endif]-->简单属性的注入

<!--[if !supportLists]-->a)     <!--[endif]-->Spring_0500_IOC_SimpleProperty

<!--[if !supportLists]-->b)     <!--[endif]--><property name=… value=….>

<!--[if !supportLists]-->5.     <!--[endif]--><bean 中的scope属性

<!--[if !supportLists]-->a)     <!--[endif]-->Spring_0600_IOC_Bean_Scope

<!--[if !supportLists]-->b)     <!--[endif]-->singleton 单例

<!--[if !supportLists]-->c)     <!--[endif]-->proptotype 每次创建新的对象

<!--[if !supportLists]-->6.     <!--[endif]-->集合注入

<!--[if !supportLists]-->a)     <!--[endif]-->Spring_0700_IOC_Collections

<!--[if !supportLists]-->b)     <!--[endif]-->很少用,不重要!参考程序

<!--[if !supportLists]-->7.     <!--[endif]-->自动装配

<!--[if !supportLists]-->a)     <!--[endif]-->Spring_0800_IOC_AutoWire

<!--[if !supportLists]-->b)     <!--[endif]-->byName

<!--[if !supportLists]-->c)     <!--[endif]-->byType

<!--[if !supportLists]-->d)     <!--[endif]-->如果所有的bean都用同一种,可以使用beans的属性:default-autowire

<!--[if !supportLists]-->8.     <!--[endif]-->生命周期

<!--[if !supportLists]-->a)     <!--[endif]-->Spring_0900_IOC_Life_Cycle

<!--[if !supportLists]-->b)     <!--[endif]-->lazy-init (不重要)

<!--[if !supportLists]-->c)     <!--[endif]-->init-method destroy-methd 不要和prototype一起用(了解)

<!--[if !supportLists]-->9.     <!--[endif]-->Annotation第一步:

<!--[if !supportLists]-->a)     <!--[endif]-->修改xml文件,参考文档<context:annotation-config />

<!--[if !supportLists]-->10.  <!--[endif]-->@Autowired

<!--[if !supportLists]-->a)     <!--[endif]-->默认按类型by type

<!--[if !supportLists]-->b)     <!--[endif]-->如果想用byName,使用@Qulifier

<!--[if !supportLists]-->c)     <!--[endif]-->写在private field(第三种注入形式)(不建议,破坏封装)

<!--[if !supportLists]-->d)     <!--[endif]-->如果写在set上,@qualifier需要写在参数上

<!--[if !supportLists]-->11.  <!--[endif]-->@Resource(重要)

<!--[if !supportLists]-->a)     <!--[endif]-->加入:j2ee/common-annotations.jar

<!--[if !supportLists]-->b)     <!--[endif]-->默认按名称,名称找不到,按类型

<!--[if !supportLists]-->c)     <!--[endif]-->可以指定特定名称

<!--[if !supportLists]-->d)     <!--[endif]-->推荐使用

<!--[if !supportLists]-->e)     <!--[endif]-->不足:如果没有源码,就无法运用annotation,只能使用xml

<!--[if !supportLists]-->12.  <!--[endif]-->@Component @Service @Controller @Repository

<!--[if !supportLists]-->a)     <!--[endif]-->初始化的名字默认为类名首字母小写

<!--[if !supportLists]-->b)     <!--[endif]-->可以指定初始化bean的名字

<!--[if !supportLists]-->13.  <!--[endif]-->@Scope

<!--[if !supportLists]-->14.  <!--[endif]-->@PostConstruct = init-method; @PreDestroy = destroy-method;

 

什么是AOP

<!--[if !supportLists]-->1.     <!--[endif]-->面向切面编程Aspect-Oriented-Programming

<!--[if !supportLists]-->a)     <!--[endif]-->是对面向对象的思维方式的有力补充

<!--[if !supportLists]-->2.     <!--[endif]-->Spring_1400_AOP_Introduction

<!--[if !supportLists]-->3.     <!--[endif]-->好处:可以动态的添加和删除在切面上的逻辑而不影响原来的执行代码

<!--[if !supportLists]-->a)     <!--[endif]-->Filter

<!--[if !supportLists]-->b)     <!--[endif]-->Struts2interceptor

<!--[if !supportLists]-->4.     <!--[endif]-->概念:

<!--[if !supportLists]-->a)     <!--[endif]-->JoinPoint

<!--[if !supportLists]-->b)     <!--[endif]-->PointCut

<!--[if !supportLists]-->c)     <!--[endif]-->Aspect(切面)

<!--[if !supportLists]-->d)     <!--[endif]-->Advice

<!--[if !supportLists]-->e)     <!--[endif]-->Target

<!--[if !supportLists]-->f)      <!--[endif]-->Weave

Spring AOP配置与应用

<!--[if !supportLists]-->1.     <!--[endif]-->两种方式:

<!--[if !supportLists]-->a)     <!--[endif]-->使用Annotation

<!--[if !supportLists]-->b)     <!--[endif]-->使用xml

<!--[if !supportLists]-->2.     <!--[endif]-->Annotation

<!--[if !supportLists]-->a)     <!--[endif]-->加上对应的xsd文件spring-aop.xsd

<!--[if !supportLists]-->b)     <!--[endif]-->beans.xml <aop:aspectj-autoproxy />

<!--[if !supportLists]-->c)     <!--[endif]-->此时就可以解析对应的Annotation

<!--[if !supportLists]-->d)     <!--[endif]-->建立我们的拦截类

<!--[if !supportLists]-->e)     <!--[endif]-->@Aspect注解这个类

<!--[if !supportLists]-->f)      <!--[endif]-->建立处理方法

<!--[if !supportLists]-->g)     <!--[endif]-->@Before来注解方法

<!--[if !supportLists]-->h)     <!--[endif]-->写明白切入点(execution …….

<!--[if !supportLists]-->i)      <!--[endif]-->spring对我们的拦截器类进行管理@Component

<!--[if !supportLists]-->3.     <!--[endif]-->常见的Annotation:

<!--[if !supportLists]-->a)     <!--[endif]-->@Pointcut

<!--[if !supportLists]-->b)     <!--[endif]-->@Before

<!--[if !supportLists]-->c)     <!--[endif]-->@AfterReturning

<!--[if !supportLists]-->d)     <!--[endif]-->@AfterThrowing

<!--[if !supportLists]-->e)     <!--[endif]-->@After

<!--[if !supportLists]-->f)      <!--[endif]-->@Around

<!--[if !supportLists]-->4.     <!--[endif]-->织入点语法

<!--[if !supportLists]-->a)     <!--[endif]-->void !void

<!--[if !supportLists]-->b)     <!--[endif]-->参考文档(* ..

<!--[if !supportLists]-->5.     <!--[endif]-->xml配置AOP

<!--[if !supportLists]-->a)     <!--[endif]-->interceptor对象初始化

<!--[if !supportLists]-->b)     <!--[endif]--><aop:config

<!--[if !supportLists]-->                i.          <!--[endif]--><aop:aspect …..

<!--[if !supportLists]-->1.     <!--[endif]--><aop:pointcut

<!--[if !supportLists]-->2.     <!--[endif]--><aop:before

Spring整合Hibernate

<!--[if !supportLists]-->1.     <!--[endif]-->Spring 指定datasource

<!--[if !supportLists]-->a)     <!--[endif]-->参考文档,找dbcp.BasicDataSource

<!--[if !supportLists]-->                i.          <!--[endif]-->c3p0

<!--[if !supportLists]-->               ii.          <!--[endif]-->dbcp

<!--[if !supportLists]-->             iii.          <!--[endif]-->proxool

<!--[if !supportLists]-->b)     <!--[endif]-->DAO或者Service中注入dataSource

<!--[if !supportLists]-->c)     <!--[endif]-->Spring中可以使用PropertyPlaceHolderConfigure来读取Properties文件的内容

<!--[if !supportLists]-->2.     <!--[endif]-->Spring整合Hibernate

<!--[if !supportLists]-->a)     <!--[endif]--><bean .. AnnotationSessionFactoryBean>

<!--[if !supportLists]-->                i.          <!--[endif]--><property dataSource

<!--[if !supportLists]-->               ii.          <!--[endif]--><annotatedClasses

<!--[if !supportLists]-->b)     <!--[endif]-->引入hibernate 系列jar

<!--[if !supportLists]-->c)     <!--[endif]-->User上加Annotation

<!--[if !supportLists]-->d)     <!--[endif]-->UserDAO或者UserServie 注入SessionFactory

<!--[if !supportLists]-->e)     <!--[endif]-->jar包问题一个一个解决

<!--[if !supportLists]-->3.     <!--[endif]-->声明式的事务管理

<!--[if !supportLists]-->a)     <!--[endif]-->事务加在DAO层还是Service层?

<!--[if !supportLists]-->b)     <!--[endif]-->annotation

<!--[if !supportLists]-->                i.          <!--[endif]-->加入annotation.xsd

<!--[if !supportLists]-->               ii.          <!--[endif]-->加入txManager bean

<!--[if !supportLists]-->             iii.          <!--[endif]--><tx:annotation-driven

<!--[if !supportLists]-->             iv.          <!--[endif]-->在需要事务的方法上加:@Transactional

<!--[if !supportLists]-->               v.          <!--[endif]-->需要注意,使用SessionFactory.getCurrentSession 不要使用OpenSession

<!--[if !supportLists]-->c)     <!--[endif]-->@Transactional详解

<!--[if !supportLists]-->                i.          <!--[endif]-->什么时候rollback

<!--[if !supportLists]-->1.     <!--[endif]-->运行期异常,非运行期异常不会触发rollback

<!--[if !supportLists]-->2.     <!--[endif]-->必须uncheck (没有catch)

<!--[if !supportLists]-->3.     <!--[endif]-->不管什么异常,只要你catch了,spring就会放弃管理

<!--[if !supportLists]-->4.     <!--[endif]-->事务传播特性:propagation_required

<!--[if !supportLists]-->5.     <!--[endif]-->read_only

<!--[if !supportLists]-->d)     <!--[endif]-->xml(推荐,可以同时配置好多方法)

<!--[if !supportLists]-->                i.          <!--[endif]--><bean txmanager

<!--[if !supportLists]-->               ii.          <!--[endif]--><aop:config

<!--[if !supportLists]-->1.     <!--[endif]--><aop:pointcut

<!--[if !supportLists]-->2.     <!--[endif]--><aop:advisor pointcut-ref advice-ref

<!--[if !supportLists]-->             iii.          <!--[endif]--><tx:advice: id transaction-manager =

<!--[if !supportLists]-->e)     <!--[endif]-->HibernateTemplateHibernateCallbackHibernateDaoSupport(不重要)介绍

<!--[if !supportLists]-->                i.          <!--[endif]-->设计模式:Template Method

<!--[if !supportLists]-->               ii.          <!--[endif]-->Callback:回调/钩子函数

<!--[if !supportLists]-->             iii.          <!--[endif]-->第一种:(建议)

<!--[if !supportLists]-->1.     <!--[endif]-->spring中初始化HibernateTemplate,注入sessionFactory

<!--[if !supportLists]-->2.     <!--[endif]-->DAO里注入HibernateTemplate

<!--[if !supportLists]-->3.     <!--[endif]-->savegetHibernateTemplate.save();

<!--[if !supportLists]-->             iv.          <!--[endif]-->第二种:

<!--[if !supportLists]-->1.     <!--[endif]-->HibernateDaoSupport继承

<!--[if !supportLists]-->2.     <!--[endif]-->必须写在xml文件中,无法使用Annotation,因为set方法在父类中,而且是final

<!--[if !supportLists]-->f)      <!--[endif]-->spring整合hibernate的时候使用packagesToScan属性,可以让spring自动扫描对应包下面的实体类

Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2

<!--[if !supportLists]-->1.     <!--[endif]-->需要的jar包列表

jar包名称

所在位置

说明

antlr-2.7.6.jar

hibernate/lib/required

解析HQL

aspectjrt

spring/lib/aspectj

AOP

aspectjweaver

..

AOP

cglib-nodep-2.1_3.jar

spring/lib/cglib

代理,二进制增强

common-annotations.jar

spring/lib/j2ee

@Resource

commons-collections-3.1.jar

hibernate/lib/required

集合框架

commons-fileupload-1.2.1.jar

struts/lib

struts

commons-io-1.3.2

struts/lib

struts

commons-logging-1.1.1

单独下载,删除1.0.4(struts/lib)

struts

spring

dom4j-1.6.1.jar

hibernate/required

解析xml

ejb3-persistence

hibernate-annotation/lib

@Entity

freemarker-2.3.13

struts/lib

struts

hibernate3.jar

hibernate

 

hibernate-annotations

hibernate-annotation/

 

hibernate-common-annotations

hibernate-annotation/lib

 

javassist-3.9.0.GA.jar

hiberante/lib/required

hibernate

jta-1.1.jar

..

hibernate transaction

junit4.5

 

 

mysql-

 

 

ognl-2.6.11.jar

struts/lib

 

slf4j-api-1.5.8.jar

hibernate/lib/required

hibernate-log

slf4j-nop-1.5.8.jar

hibernate/lib/required

 

spring.jar

spring/dist

 

struts2-core-2.1.6.jar

struts/lib

 

xwork-2.1.2.jar

struts/lib

struts2

commons-dbcp

spring/lib/jarkata-commons

 

commons-pool.jar

..

 

struts2-spring-plugin-2.1.6.jar

struts/lib

 

<!--[if !supportLists]-->2.     <!--[endif]-->BestPractice

<!--[if !supportLists]-->a)     <!--[endif]-->将这些所有的jar包保存到一个位置,使用的时候直接copy

<!--[if !supportLists]-->3.     <!--[endif]-->步骤

<!--[if !supportLists]-->a)     <!--[endif]-->加入jar

<!--[if !supportLists]-->b)     <!--[endif]-->首先整合Spring + Hibernate

<!--[if !supportLists]-->                i.          <!--[endif]-->建立对应的package

<!--[if !supportLists]-->1.     <!--[endif]-->dao / dao.impl / model / service / service.impl/ test

<!--[if !supportLists]-->               ii.          <!--[endif]-->建立对应的接口与类框架

<!--[if !supportLists]-->1.     <!--[endif]-->S2SH_01

<!--[if !supportLists]-->             iii.          <!--[endif]-->建立spring的配置文件(建议自己保留一份经常使用的配置文件,以后用到的时候直接copy改)

<!--[if !supportLists]-->             iv.          <!--[endif]-->建立数据库

<!--[if !supportLists]-->               v.          <!--[endif]-->加入Hibernate注解

<!--[if !supportLists]-->1.     <!--[endif]-->在实体类上加相应注解@Entity @Id

<!--[if !supportLists]-->2.     <!--[endif]-->beans配置文件配置对应的实体类,使之受管

<!--[if !supportLists]-->             vi.          <!--[endif]-->dao service的实现

<!--[if !supportLists]-->            vii.          <!--[endif]-->加入Spring注解

<!--[if !supportLists]-->1.     <!--[endif]-->在对应ServiceDAO实现中加入@Component,让spring对其初始化

<!--[if !supportLists]-->2.     <!--[endif]-->Service上加入@Transactional或者使用xml方式(此处建议后者,因为更简单)

<!--[if !supportLists]-->3.     <!--[endif]-->DAO中注入sessionFactory

<!--[if !supportLists]-->4.     <!--[endif]-->Service中注入DAO

<!--[if !supportLists]-->5.     <!--[endif]-->DAOService的实现

<!--[if !supportLists]-->           viii.          <!--[endif]-->写测试

<!--[if !supportLists]-->c)     <!--[endif]-->整合Struts2

<!--[if !supportLists]-->                i.          <!--[endif]-->结合点:Struts2ActionSpring产生

<!--[if !supportLists]-->               ii.          <!--[endif]-->步骤:

<!--[if !supportLists]-->1.     <!--[endif]-->修改web.xml加入 strutsfilter

<!--[if !supportLists]-->2.     <!--[endif]-->再加入springlistener,这样的话,webapp一旦启动,spring容器就初始化了

<!--[if !supportLists]-->3.     <!--[endif]-->规划strutsactionjsp展现

<!--[if !supportLists]-->4.     <!--[endif]-->加入struts.xml

<!--[if !supportLists]-->a)     <!--[endif]-->修改配置,由spring替代struts产生Action对象

<!--[if !supportLists]-->5.     <!--[endif]-->修改action配置

<!--[if !supportLists]-->a)     <!--[endif]-->把类名改为bean对象的名称,这个时候就可以使用首字母小写了

<!--[if !supportLists]-->b)     <!--[endif]-->@Scope(“prototype”)不要忘记

<!--[if !supportLists]-->             iii.          <!--[endif]-->struts的读常量:

<!--[if !supportLists]-->1.     <!--[endif]-->struts-default.xml

<!--[if !supportLists]-->2.     <!--[endif]-->struts-plugin.xml

<!--[if !supportLists]-->3.     <!--[endif]-->struts.xml

<!--[if !supportLists]-->4.     <!--[endif]-->struts.properties

<!--[if !supportLists]-->5.     <!--[endif]-->web.xml

<!--[if !supportLists]-->             iv.          <!--[endif]-->中文问题:

<!--[if !supportLists]-->1.     <!--[endif]-->Struts2.1.8已经修正,只需要改i18n.encoding = gbk

<!--[if !supportLists]-->2.     <!--[endif]-->使用springcharacterencoding

<!--[if !supportLists]-->3.     <!--[endif]-->需要严格注意filter的顺序

<!--[if !supportLists]-->4.     <!--[endif]-->需要加到Struts2filter前面

<!--[if !supportLists]-->               v.          <!--[endif]-->LazyInitializationException

<!--[if !supportLists]-->1.     <!--[endif]-->OpenSessionInViewFilter

<!--[if !supportLists]-->2.     <!--[endif]-->需要严格顺序问题

 

<!--[if !supportLists]-->3.     <!--[endif]-->需要加到struts2filter前面

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics