Spring中的byname,byType及其注解

注解时@autowire(bytype)

com.orient.nms.domain.service.impl.FHalarmInfoServiceImpl这个类定义一个bean,如下
<bean name=“fHalarmInfoServiceImpl”
class="com.orient.nms.domain.service.impl.FHalarmInfoServiceImpl" autowire="byName">
<property name="ibatisBase" ref="ibatisBase" />
</bean>
然后在需要该对象的地方设置一个fHalarmInfoServiceImpl的属性就够了


注解时@resourse(byname)
byName快
因为byName是直接反射
byType需要遍历applicationContext

所以byName方式定位的过程更简单 开销更小

但是 正如LS所言 这些都发生在装载过程中
而装载应该是只发生一次
只要是默认的单例模式 这些东西在运行期对于效率应该是没有影响

猜你喜欢

转载自love398146779.iteye.com/blog/1545733