我的spring学习日记 - bean-1

Bean definition

Property:

Class

Name

Scope

Constructor arguments

Properties

Autowiring mode

Lazy-initialization mode

Initialization method

Destruction method

 

Inner class names

If you want to configure a bean definitionfor a static nested class, you need to use the binary name of the inner class.

For example, if you have a class called Fooin the com.example package, and this Foo class has a static inner class calledBar, the value of the CLASS attribute on a bean definition would be

com.example.Foo$Bar

 

IOC: inversion of control, the bean itself controlling theinstantiation or location of its dependencies on its own by using directconstruction of classes, or the Service Locator pattern.

Code is cleaner with the dependencyinjection principle and decoupling is more effective when objects are providedwith their dependencies. The object does not look up its dependencies, and doesnot know the location or class of the dependencies. As such, your classesbecome easier to test, in particular when the dependencies are on interfaces orabstract base classes, which allow for stub or mock implementations to be usedin unit tests.

 

Constructor-baseddependency injection:

Constructor argument resolution

<beans>

  <bean id="foo" class="x.y.Foo">

      <constructor-arg ref="bar"/>

      <constructor-arg ref="baz"/>

  </bean>

 

  <bean id="bar" class="x.y.Bar"/>

  <bean id="baz" class="x.y.Baz"/>

 

</beans>

 

Constructor argument type matchingresolution

<bean id="exampleBean" class="examples.ExampleBean">
<constructor-arg type="int" value="7500000"/>
<constructor-arg type="java.lang.String" value="42"/>
</bean>

 

Constructor argument index

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值