0

I have a bean definition like spring xml context file

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

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?

Vishal
  • 666
  • 1
  • 8
  • 30
  • No. It will be resolved as soon as the bean is needed. So if you inject this bean into something else (a singleton) the `lazy-init` has no effect. – M. Deinum Sep 07 '20 at 13:16
  • @M.Deinum if the bean `idFilter` is not getting injected into any other singleton bean, the property place holder `${id.start}` should not be resolved at all right? I am seeing a contrary behaviour where the context creation process is trying to resolve value for `${id.start}` while creating bean definitions. Since `idFilter` is lazy loaded, I see that it is not instantiated during context creation which is correct behaviour – Vishal Sep 07 '20 at 15:12
  • The property resolution might still be eager as the bean definition is being fully prepared. – M. Deinum Sep 08 '20 at 05:59

1 Answers1

4

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

Vishal
  • 666
  • 1
  • 8
  • 30