Spring-in-action
Spring:
Ioc(控制反转 Inversion of Control):依赖注入(DI)。
Aop(面向切面编程 Aspect Oriented Programming): 动态代理。
应用上下文:
ClassPathXmlApplicationContext:从类路径下的xml配置文件中加载。
FileSystemXmlapplicationcontext:读取文件系统下的xml配置文件并加载上下文定义。
XmlWebApplicationContext:读取Web应用下的xml配置文件并装载上下文定义。
XmlWebApplicationContext使用的BeanFactory:DefaultListableBeanFactory
Bean的生命周期:
- Spring对bean初始化
- 将值或者bean的引用注入到bean的属性中
- BeanNameAware.setBeanName()
- BeanFactoryAware.setBeanFactory()
- ApplicationContextAware.setApplicationContext()
- BeanPostProcessor.postProcessBeforeInitialization()
- InitializingBean.afterPropertiesSet(),init-method
- BeanPostProcessor.postPoressAfterInitialization()
- 此时可以使用,bean会一直驻留在ApplicationContext中
- DisposableBean.destroy(),destroy-method
通过工厂方法创建bean
factory-method
Bean的作用域:
scope:singleton,prototype(每次调用都创建一个实例),request,session,global-session。
Spring命名空间p装配属性。
aop:
通知(advice):before、after、after-around、after-throwing、around
切点(pointcut)、切面(aspect)
Spring 占位符:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:conf/system.ini</value>
</list>
</property>
</bean>
上传文件的功能定制
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSize" value="10240000" />
</bean>
Spring MVC 拦截器
mvc:interceptors>
<ref bean="authorizeInterceptor" />
</mvc:interceptors>
>> 转载请注明来源:Spring-in-action 赏
免费分享,随意打赏
发表评论