JEESpring基础.ppt

  1. 1、本文档共39页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JEESpring基础.ppt

通过构造函数注入依赖 通过Set方式注入,有一些情况解决不了。每次创建的对象,通过set注入,需要有一些属性设置初始值才能使用;或者有一些属性只要设置一次值,以后就不变了,这个时候就可以采用构造函数方式来注入 bean id=“studentService” class=“com…StudentServiceImpl” constructor-arg ref bean=“studentDao”/ /constructor-arg /bean bean id=“courseService” class=“com…CourseServiceImpl” constructor-arg ref bean=“courseDao”/ /constructor-arg /bean 解决构造函数参数的不确定性 public Foo(String arg1,.URL arg2) bean id=“foo” class=“com…Foo” constructor-arg valuehttp://dddd/fff/value /constructor-arg constructor-arg valuehttp://dddd/value /constructor-arg /bean 如何将上面的配置来对应构造函数? 两种方式来解决不确定性 bean id=“foo” class=“com…Foo” constructor-arg index=“0” valuehttp://dddd/value /constructor-arg constructor-arg index=“1” valuehttp://dddd/value /constructor-arg /bean bean id=“foo” class=“com…Foo” constructor-arg type=“java.lang.String” valuehttp://dddd/value /constructor-arg constructor-arg type=“.URL” valuehttp://dddd/value /constructor-arg /bean InitializingBean/init-method org.springframework.beans.factory.InitializingBean接口允许在它的属性都设置完以后,来执行初始化工作 这个接口规定了一个方法:void afterPropertiesSet() bean id=“exampleInitBean” class=“examples.Example” init-method=“init”/ public class Example{ public void init() bean id=“exampleInitBean” class=“Example”/ public class Example implements InitializingBean{ public void afterPropertiesSet() DisposableBean/destroy-method org.springframework.beans.factory.DisposableBean接口允许在对象销毁的时候来做一些善后处理工作 这个接口规定了一个方法:void destroy() bean id=“exampleInitBean” class=“examples.Example” destroy-method=“teardown”/ public class Example{ public void teardown() bean id=“exampleInitBean” class=“Example”/ public class Example implements DisposableBean{ public void destroy() PropertyPlaceholderConfigurer 它是一个BeanPostProcessor的常用实现之一 使用方法如下: 利用这个工具就可以读取src下的资源文件。 bean id=propertyConfigurer“ class=org.springframework.beans.factory.config.PropertyPlaceholderConfigurer property name=location value/perties/value /property /bean bean id=dataSour

文档评论(0)

rewfdgd + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档