0

I have a legacy code which is initialising spring beans using xml configuration. I have defined a lazy bean with id "filter" as mentioned below

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

I had conditional logic which is when the bean is initialised using

IdFilter filterObj = context.getBean(IdFilter.class);

I assume that when I am not initialising the "filter" bean, the param ${id.start} may not be provided since it is only being used to initialise "filter" bean.

However, I am seeing the opposite, while loading the spring context file, the container is trying to find ${id.start} and fails eventually. This defeats the objective of lazy bean

Am I doing something wrong?

Edit

Adding stack trace

DEBUG 16:38:13     2597 o.s.c.e.PropertySourcesPropertyResolver [main]- Could not find key 'id.start' in any property source. Returning [null]
WARN 16:38:13     2600 o.s.c.s.AbstractApplicationContext [main]- Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'filter' defined in class path resource [contextFile.xml]: Could not resolve placeholder 'id.start' in string value "${id.start}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'id.start' in string value "${id.start}"
        at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:211)
        at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:180)
        at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:155)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
        at some.package.util.SpringUtil.buildApplicationContext(springUtil.java:60)
        at some.package.ImporterApp.execute(ImporterApp.java:50)
        at some.package.Main.main(Main.java:38)
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'id.start' in string value "${id.start}"
        at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
        at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
        at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204)
        at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178)
        at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175)
        at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282)
        at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:204)
        at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitGenericArgumentValues(BeanDefinitionVisitor.java:159)
        at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:85)
        at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:208)
Vishal
  • 666
  • 1
  • 8
  • 30

0 Answers0