1.spring aop讲解
Spring AOP (上) - yanbin_new - 博客园
2.使用xmlBeanFactory需要使用Resource提供资源。
Interface Resource API说明描述
Interface for a resource descriptor that abstracts from the actual type ofunderlying resource, such as a file or class path resource.
3.BeanFactory API说明描述
The root interface for accessing a Spring beancontainer. This is the basic client view of a bean container;
Depending on the bean definition, the factory willreturn either an independent instance of a contained object (the Prototypedesign pattern), or a single shared instance (a superior alternative to theSingleton design pattern, in which the instance is a singleton in thescope of the factory
4.ApplicationContext API说明描述
Central(核心的) interface toprovide configuration for an application. This is read-only while theapplication is running, but may be reloaded if the implementation supportsthis.
An ApplicationContext provides:
5.ApplicationContext 的父接口是BeanFactory
6.在使用构造方法注入或set方法注入时,xml中的配置需要与bean的实例对象中相对应,及若使用构造方法注入,xml中使用<constructor-arg/>且类中提供构造方法,若使用set注入,类中需要提供set方法。不然会出现异常如:(1)No defaultconstructor found; nested exception is java.lang.NoSuchMethodException: (2)Error setting property values; nested exception isorg.springframework.beans.NotWritablePropertyException:
7.构造方法注入:若需注入多个参数,使用多个<constructor-arg/>,但需要注入参数匹配,不然会出现类型转换异常。
8.<constructor-arg> 中的type指定构造函数的参数类型,可选择,一个类中有多个构造方法,每次实例bean时,只能使用其中一个构造函数,不能一次使用多个构造函数。
9.set注入:<property name=""/> name属性是必须的,ref,value属性是可选的
10.装配list时,<list>的merge属性(值为"default","true","false")
11.自动装配(只是针对当前的bean,为当前bean注入值)
setter方式注入时:
byName : 在spring容器中查找与当前bean的属性具有相同的名称的bean,若找到,则将找到的bean注入到当前的属性中.
byType : 在spring容器中查找与当前bean的属性具有相同的类型的bean,若找到,则将找到的bean注入到当前的属性中.
constructor方式注入:
constructor:在spring容器中查找与当前bean的构造函数中的参数,具有相同的名称的bean,若找到,则将找到的bean注入到当前的属性中.
autodetect:首先尝试constructor来装配,然后再使用byType装配。
12.bean中需要提供一个默认的构造函数。
13.自动装配缺乏透明度,使用起来要小心。比如:当前bean的属性名为a,修改为b,那么需要xml中对应修改,不然找不到对应的值,又或者spring容器中正好有一个b的bean,那么就会出现错误的装配。
14.
// 一个构造参数,就是一个<constructor-arg>节点,而此处一个参数却对应两个值,所以不正确,
<constructor-arg>
<value>ss</value>
<valuetype="beancreate.java.Song"/>
</constructor-arg>
应该为
<constructor-arg>
<value>ss</value>
</constructor-arg>
<constructor-arg>
<valuetype="beancreate.java.Song"/>
</constructor-arg>
15.bean范围化
singleton – Return asingle bean instance per Spring IoC container这个范围也是默认的
prototype – Return a newbean instance each time when requested
request – Return asingle bean instance per HTTP request. *
session – Return asingle bean instance per HTTP session. *
globalSession – Return asingle bean instance per global HTTP session. *
单例时,不管多少次getBean(),能到的都是同一个实例。
16.初始化和销毁bean共有3种方式:
(1)通过实现InitializingBean/DisposableBean接口来定制初始化之后/销毁之前的操作方法;
(2)通过<bean>元素的 init-method/destroy-method属性指定初始化之后 /销毁之前调用的操作方法;
(3)在指定方法上加上@PostConstruct或@PreDestroy注解来制定该方法是在初始化之后还是销毁之前调用
使用注解时,应该在xml中加上<context:annotation-config/>并对标签进行声明
17.如果bean的属性abstract设置为true,bean就不能被实例化。
bean的属性parent,指明bean的父bean,但这样的依赖关系只是针对bean的,并不能改变具体对象的依赖关系,
比如:<bean id="saxophone"class="springIdol.java.Saxophone"parent="baseSaxophonist"/>
<bean id="baseSaxophonist" class="springIdol.java.Instrumentalist" abstract="true"/>
前者bean对应的对象并不会因为加了parent属性,与后者的对象的关系发生改变。
18.抽象bean不能实例化,由它的子bean实例化。
19.子bean不仅继承父bean的属性,也继承它的类。
20.基本方法替代,实现spring提供的MethodReplacer接口即可reimplement(Object target, Method method,Object[] args)可以替代所有方法。API:Interface to be implemented by classes that can reimplement any method onan IoC-managed object: the Method Injection form of DependencyInjection.
21.spring 获取器注入(<lookup-method>)
22.注入非spring bean,也就是手动创建的实例也可以用spring来配置,使用<aop:spring-configured/>与@confugurable即可,并启用AspectJ功能。
23.
24.注册自定义属性编辑器,spring提供了几个属性编辑器,如:CustomDateEditor,在<property name=""value="时间的字符串"/>,spring会自动将字符串转换为Date对象,也可以自己实现如:继承CustomEditorConfigurer类,并在xml中相应声明即可。
25.1.bean后处理器
这种处理器会对容器中的bean进行后处理,对bean的功能进行额外加强
bean的后处理器必须实现接口BeanPostProcessor,该接口包含两个方法
public Object postProcessBeforeInitialization(Object bean, StringbeanName)
public Object postProcessAfterInitialization(Object bean, String beanName)
2.容器后处理器
容器必须实现接口BeanFactoryPostProcessor,该接口有方法:
public void postProcessBeanFactory(ConfigurableListableBeanFactorybeanFactory) throws BeansException
26.配置属性的外在化:将数据放在属性文件中,然后读取属性文件中相应的值。可以使用PropertyPlaceholderConfigurer读取属性文件。
27.事件、监听器:创建事件,创建监听器,在满足指定条件时,创建事件,由容器发布事件,然后由监听器捕获事件进行相应处理。
(1)创建事件:spring事件监听_过天的博客-CSDN博客
(2)ApplicationContextAware:org.springframework.context.ApplicationContextAware使用理解_Kaiwii的博客-CSDN博客
28.BeanNameAware:Interface to beimplemented by beans that want to be aware of their bean name in a beanfactory{具体方法:setBeanName(String name)}
BeanFactoryFactoryAware:Interface to be implemented by beans that wish tobe aware of their owning BeanFactory.
{具体方法:setBeanFactory(BeanFactory beanFactory)}
通过BeanNameAware可以了解到bean的名称,通过BeanFactoryFactoryAware可以了解到工厂中bean的情况。
29. Spring中的Advisor,Advice,Point概述
(1)、 Advisor: 充当Advice和Pointcut的 适配器 , 类似使用Aspect的 @Aspet 注解的类 。一般有advice和pointcut属性。
祖先接口为org.springframework.aop.Advisor,应用中可直接使用org.springframework.aop.support.DefaultPointcutAdvisor
(2)、Advice:用于定义拦截行为,祖先接口为org.aopalliance.aop.Advice,该接口只是标识接口,应用中可直接实现BeforeAdvice ,ThrowsAdvice,MethodInterceptor ,AfterReturningAdvice ,IntroductionInterceptor 等子接口
(3)、Pointcut:用于定义拦截目标集合,祖先接口为org.springframework.aop.Pointcut
30.1)“。*spea.*”表示所有名字以spea开头的方法,例程中是指speak方法;
2)“。*ing” 表示所有名字以ing结束的方法,例程中是指Running和Loving方法;
31. AspectJ的Execution表达式
blog.csdn.net/yakoo5/article/details/17001381
32.Spring AOP环境
要在项目中使用Spring AOP 则需要在项目中导入除了springjar包之外,还有aspectjweaver.jar,aspectjrt.jar和cglib.jar 。
33.使用@AspectJ,在xml中需要启动AspectJ支持 <aop:aspectj-autoproxy/>,并且需要配置切面的bean
xml头部加上xmlns:aop="Index of /schema/aop"
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
32.spring 的数据访问:使用spring提供的templete,然后注入到dao,或直接使用daosupport类
33.数据源、连接池、jdbc、template(模板)、daoSupport的理解以及它们之间的关联关系:
34.spring中的ibatis访问,可以将SqlMapClientTemplate直接装配到DAO,也可以使用DAO继承SqlMapClientSuppot类
(1)<beanid="sqlMapClient"class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<propertyname="dataSource" ref="dataSource"/>
<propertyname="configLocation" value="/sql-map-config.xml"/>
</bean>
<beanid="sqlMapCilentTemplate"class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<propertyname="sqlMapClient" ref="sqlMapClient"/>
</bean>
<bean id="ibatisDao"
class="ibatisconnet.java.dao.IbatisDao">
<propertyname="sqlMapClientTemplate" ref="sqlMapCilentTemplate"/>
</bean>
(2)-------同前
<beanid="ibatisDao"
class="ibatisconnet.java.dao.IbatisDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
public classIbatisDao extends SqlMapClientDaoSupport{
......
}
34.数据源、连接池:
数据源指的是数据来源,一般指数据库。
数据源有两种连接方式,一种是直接连接方式,这种方式每次都要进行开关;
一种是池化连接方式,这种方式,可以一次建立多个连接,用完了可以分配其它使用,资源可以重复利用。
(1)新浪博客
(2)http://blog.163.com/freestyle_le/blog/static/1832794482011542245698/
35.spring配置ibatis的十种方法:
http://my.oschina.net/u/565871/blog/195484
36. Spring事务配置的五种方式
www.blogjava.net/robbie/archive/2009/04/05/264003.html
37. spring小结:spring事务处理
blog.163.com/langfei520@yeah/blog/static/172710222201302543340979/
38.spring security
Spring Security 3.x 完整入门教程_王姐的博客-CSDN博客
39.安全框架讲解。
《spring安全框架系列springSecurity之我见》其一[认识springSecurity]_spring-security-acl_yaerfeng的博客-CSDN博客
40. <context:component-scan>使用说明
blog.csdn.net/chunqiuwei/article/details/16115135
41. SpingMVCModelAndView, Model,Control以及参数传递
www.cnblogs.com/CBDoctor/p/3672861.html
42.springmvc 工作原理 http://blog.sina.c0om.cn/s/blog_7ef0a3fb0101po57.html
SpringMVC工作原理_springmvc的工作原理_cswhale的博客-CSDN博客
43.spring control 讲解的很好
Spring controller - 思悟修 - OSCHINA - 中文开源技术交流社区
44. Spring—DispatcherServlet的详解
blog.csdn.net/jbjwpzyl3611421/article/details/18728227
45.使用spring的@Async异步执行方法
应用场景:
1、某些耗时较长的而用户不需要等待该方法的处理结果
2、某些耗时较长的方法,后面的程序不需要用到这个方法的处理结果时
使用spring的@Async异步执行方法 - 自行车上的程序员 - 博客园
45.spring+aop注解 用户操作日志记录
spring mvc +spring aop结合注解的 用户操作日志记录 - 天浩 - ITeye博客
46.spring mvc文件上传
spring mvc(注解)上传文件的简单例子_Ethan6666的博客-CSDN博客
47.ioc(控制反转)与di(依赖注入)
控制反转:本来需要程序中new 来创建的,通过spring,只需要配置好spring中的bean,便可以实例化了,操作被反转了
di与ioc实际都是一样的,只是更能表达spring的功能。di表示spring中配置的bean相互之间是可以依赖的,而bean的属性是可以注入的
48.spring中的配置文件
49.可以通过dom4j+java反射机制模拟实现spring中的bean创建过程。
50.spring 中的BeanFactory与ApplicationContext的区别
都可以生成某个类的实例。如果读入的Bean配置正确,则其他的配置中有错误也不会影响程序的运行。而ApplicationContext 在初始化时就把 xml 的配置信息读入内存,对 XML 文件进行检验,如果配置文件没有错误,就创建所有的Bean ,直接为应用程序服务。相对于基本的BeanFactory,ApplicationContext 唯一的不足是占用内存空间。当应用程序配置Bean较多时,程序启动较慢。ApplicationContext能提供更多的附加功能。