Spring-in-action

  • 2016-09-22
  • 3,391
  • 0

Spring:


Ioc(控制反转 Inversion of Control):依赖注入(DI)。
Aop(面向切面编程 Aspect Oriented Programming): 动态代理。

应用上下文:

ClassPathXmlApplicationContext:从类路径下的xml配置文件中加载。
FileSystemXmlapplicationcontext:读取文件系统下的xml配置文件并加载上下文定义。
XmlWebApplicationContext:读取Web应用下的xml配置文件并装载上下文定义。

XmlWebApplicationContext使用的BeanFactory:DefaultListableBeanFactory

Bean的生命周期:

  1. Spring对bean初始化
  2. 将值或者bean的引用注入到bean的属性中
  3. BeanNameAware.setBeanName()
  4. BeanFactoryAware.setBeanFactory()
  5. ApplicationContextAware.setApplicationContext()
  6. BeanPostProcessor.postProcessBeforeInitialization()
  7. InitializingBean.afterPropertiesSet(),init-method
  8. BeanPostProcessor.postPoressAfterInitialization()
  9. 此时可以使用,bean会一直驻留在ApplicationContext中
  10. 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

评论

还没有任何评论,你来说两句吧

发表评论