Spring-in-action

  • 2016-09-22
  • 2,369
  • 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

●非常感谢您的阅读,欢迎订阅微信公众号(右边扫一扫)以表达对我的认可与支持,我会在第一时间同步文章到公众号上。当然也可点击下方打赏按钮为我打赏。

●另外也可以支持一下我的副业,扫描右方代购二维码加我好友,不买看看也行。朋友在荷兰读医学博士,我和他合作经营的代购,欧洲正规商店采购,正品保证。

免费分享,随意打赏

感谢打赏!
微信
支付宝

评论

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

发表评论