春季在上下文创建期间解析延迟Bean的属性占位符吗?

huangapple go评论55阅读模式
英文:

Does spring resolve property placeholders for lazy beans during context creation?

问题

我有一个像Spring XML上下文文件中的Bean定义:

<bean id="idFilter" class="some.package.app.filter.IdFilter" lazy-init="true">
    <constructor-arg type="java.lang.String" value="${id.start}"/>
</bean>

Spring在构建上下文时尝试解析属性${id.start}吗?

我认为,由于idFilter是懒加载的,直到使用该Bean之前,属性id.start不会被尝试解析。

这样对吗?

英文:

I have a bean definition like spring xml context file

&lt;bean id=&quot;idFilter&quot; class=&quot;some.package.app.filter.IdFilter&quot; lazy-init=&quot;true&quot;&gt;
    &lt;constructor-arg type=&quot;java.lang.String&quot; value=&quot;${id.start}&quot;/&gt;
&lt;/bean&gt;

Does spring try to resolve the property ${id.start} while building context?

I would assume since idFilter is lazily loaded, the property id.start will not be tried for resolution till the bean is being used.

Is it right?

答案1

得分: 4

经过仔细调试代码后,我发现即使在创建Bean定义时也会解析懒惰加载的Bean的占位符。

请注意,Bean定义与Bean实例化不同。

因此,如果找不到占位符,无论Bean是懒惰加载还是急切加载,都会为所有Bean抛出错误。

英文:

After carefully debugging the code, I found that placeholders are resolved even for the lazy beans while creating bean definitions.

Please note, bean definitions are not bean instantiation.

So, if the placeholder is not found, an error is thrown for all beans regardless of bean being lazy or eager

huangapple
  • 本文由 发表于 2020年9月7日 19:03:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63776333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定