GeoGriffin
GeoGriffin

Reputation: 1095

Configuring Spring Integration XML in resources.xml from Config.groovy

I have a Grails app that has some small UI components and domain access, but mostly it is running a Spring Integration process to poll and read emails and process the results.

I want to be able to configure the email target based on environment.

I have the following Spring Integration XML snippet in resources.xml:

<mail:inbound-channel-adapter id="imapAdapter"
          store-uri="imaps://myEmailAddress:[email protected]/INBOX"
          java-mail-properties="javaMailProperties"
          channel="receiveEmailChannel"
          should-delete-messages="false"
          should-mark-messages-as-read="true"
          auto-startup="true">
    <int:poller max-messages-per-poll="1" fixed-rate="15" time-unit="SECONDS">
    </int:poller>
</mail:inbound-channel-adapter>

I have the following environment specific configuration snippet in Config.groovy:

environments {
    development {
        email.store.ui = 'imaps://myDevEmailAddress:[email protected]/INBOX'
    }
    test {
        email.store.ui = 'imaps://myTestEmailAddress:[email protected]/INBOX'
    }
    production {
        email.store.ui = 'imaps://myProdEmailAddress:[email protected]/INBOX'
    }
}    

How do I tie the email.store.ui definition in Config.groovy to the store-ui attribute in resources.xml?

Upvotes: 1

Views: 776

Answers (2)

GeoGriffin
GeoGriffin

Reputation: 1095

I guess I should have read to the bottom of the page... The answer is in section 15.5 Property Placeholder Configuration

I just needed:

<mail:inbound-channel-adapter id="imapAdapter"
          store-uri="${email.store.ui}"
          java-mail-properties="javaMailProperties"
          channel="receiveEmailChannel"
          should-delete-messages="false"
          should-mark-messages-as-read="true"
          auto-startup="true">
    <int:poller max-messages-per-poll="1" fixed-rate="15" time-unit="SECONDS">
    </int:poller>
</mail:inbound-channel-adapter>

Thanks for the nudge.

Upvotes: 0

Ian Roberts
Ian Roberts

Reputation: 122364

Grails sets up a PropertyPlaceholderConfigurer that takes its values from Config.groovy, so the normal Spring property placeholder syntax should work

store-uri="${email.store.ui}"

Upvotes: 3

Related Questions