Announcement Announcement Module
Collapse
No announcement yet.
Using SpEL to controll bean wiring in XML Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using SpEL to controll bean wiring in XML

    I was wondering if it was possible to mix property placeholders and SpEL to control wiring bean dependencies.

    I need to use XML for political reasons, i.e. Java Config is not really an option nor is autowiring.

    My bean def looks like this:

    Code:
    <bean id="privateMessagesService" class="x.y.z.service.PrivateMessagesServiceImpl" >
      <!--  The services can be wired with stubbed or real version of the gateway. -->
      <!--  The choice is controlled by the 'private.messages.gateway.stubbed' property. -->
      <constructor-arg ref="#{${private.messages.gateway.stubbed} ? privateMessageGatewayStubbed :    privateMessageGateway}" />
    </bean>
    Code:
    <bean id="privateMessageGateway" class="x.y.z.integration.privatemessages.PrivateMessageGatewayImpl" />
    Code:
    <bean id="privateMessageGatewayStubbed" class="x.y.z.integration.privatemessages.PrivateMessageGatewayStubbedImpl" />
    With a property defined as:
    Code:
    private.messages.gateway.stubbed = true

    When starting the application the following bean creation exception gets thrown:

    Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'x.y.z.integration.privatemessages.PrivateMessageG atewayStubbedImpl@7e31c78a' is defined

    I'm I expecting to much from XML based config?

    Many thanks in advance.

  • #2
    For below XML Configuration has some syntax error:
    <constructor-arg ref="#{${private.messages.gateway.stubbed} ? privateMessageGatewayStubbed : privateMessageGateway}" />
    You should put your beans ids in single quotes (') - 'privateMessageGatewayStubbed'

    <constructor-arg ref="#{${private.messages.gateway.stubbed} ? 'privateMessageGatewayStubbed' : 'privateMessageGateway' }" />

    Comment


    • #3
      Many thanks.

      That worked just as needed

      Comment

      Working...
      X