0

I have xml definitions of beans like this

<bean id="testingProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:myTests.properties"/>
    </bean>

    <bean id="MyBean" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
        <property name="serviceUrl" value="${config.http.server.url}/testing/"/>
        <property name="serviceInterface" value="com....ClassName"/>
        <property name="httpInvokerRequestExecutor" ref="requestExecutor"/>
    </bean>

  <bean id="requestExecutor" class="com.CustomHttpComponentsHttpInvokerRequestExecutor"></bean>

How can I put there some if statement, for example I am checking property and depends on its value deciding whether I need to inject property httpInvokerRequestExecutor no?

This CustomHttpComponentsHttpInvokerRequestExecutor class is kind of interceptor in case I work over https, it is adding trust store etc to the context, etc. And I want decide if this class needs to be injected as an property of MyBean or not.

Is there any way to do it?

liotur
  • 809
  • 2
  • 17
  • 36

1 Answers1

0

Yes,

You can use a conditional statement in bean.xml like below example

<bean id="flag" class="java.lang.Boolean">
    <constructor-arg value="#{ systemProperties['system.propery.flag'] ?: false }" />
</bean>

<bean id="bean" class="com.my.MyBean">
    <property name="property" value="#{ flag ? 'yes' : 'no' }"/>
</bean>
Sushant
  • 30
  • 9
  • I think you didn't understand the question. I don't have a boolean there. I need to inject other bean as an property to myBean in certain case. – liotur Dec 05 '18 at 11:31