mardi 3 mars 2015

Spring Looking at Default Value Before Resolving Placeholder

I've been searching forever for an issue similar to mine, but wasn't able to find one. Thus, I hope it's not a duplicate post.


Well, I'm using spring integration to search for documents in my mongodb. Once it finds one, it sends the payload to another method. I have a property file that I want to be resolved on this find and send configuration, so I use placeholders instead of static values.


Here's my xml:



<int:inbound-channel-adapter id="sendClientMailInboundAdapter"
expression="@repository.findClient()"
channel="sendClientMailChannel"
auto-startup="${send.mail.active:false}">
<int:poller fixed-rate="${send.mail.poller.time:60}" time-unit="SECONDS" max-messages-per-poll="1" />
</int:inbound-channel-adapter>

<int:channel id="sendClientMailChannel" />

<int:service-activator input-channel="sendClientMailChannel" expression="@service.sendClientMail(payload)" />


Right. Now.. I've got an AppConfig class which loads the property file.



@Configuration
@PropertySource("http://ift.tt/1DKTY9L")
public class AppConfig {

public static Environment env;
...

@Bean
public static PropertySourcesPlaceholderConfigurer appConfigConfigurer(Environment env) {
AppConfig.env = env;
PropertySourcesPlaceholderConfigurer appConfigConfigurer = new PropertySourcesPlaceholderConfigurer();
appConfigConfigurer.setIgnoreUnresolvablePlaceholders(true);
appConfigConfigurer.setIgnoreResourceNotFound(true);
return appConfigConfigurer;
}
}


So.. My problem is the default value. If I do NOT specify the default value, spring resolves the placeholder. If it's specified, though, it seems spring ignores the placeholder (maybe it doesn't wait for it to resolve) and set the default value instead!


I could use context:property-placeholder location. I've done that and it worked, but since I'm already loading the file on my configuration class, I'd rather have spring read properties from there so I would not have to remember to adjust two files in case property file changes its folder, for instance.


My question: Is there a way to tell spring to wait for the placeholder to resolve before looking at the default value?


edit: Just so people know.. I changed xml to java config, using placeholder / default value like before and it worked perfectly.


Here is the equivalent snippet:



@InboundChannelAdapter(value = "sendClientMailChannel", autoStartup="${send.mail.active:false}",
poller = @Poller(fixedRate="${send.mail.poller.time.in.millis:60000}", maxMessagesPerPoll="1"))
public Review findClient() {
return repository.findClient();
}

@ServiceActivator(inputChannel="sendClientMailChannel")
public void sendToClient(Client payload) {
service.sendClientMail(payload);
}

@Bean
public DirectChannel sendClientMailChannel() {
return new DirectChannel();
}


note: I didn't have to ref the property file.


Aucun commentaire:

Enregistrer un commentaire