0

I am trying to test the flow of a spring integration XML that I built. I am using a Custom Transformer class to write my own transformation in which I am setting the profile based on the property. This property is set to dev in application.properties file. Is there anyway to dynamically change that value for test purposes? I tried passing it as VM arguments but the value of env variable in this class is still dev. It only helps in changing the target property file.

@PropertySource("classpath:application-${spring.profiles.active}.properties")
public class CustomTransformer {

    @Value("${spring.profiles.active}")
    private String env;

    public Message<?> transform(Message<String> message){
        String payload = message.getPayload().toString();
        Message<?> message2 = MessageBuilder.withPayload(payload).copyHeadersIfAbsent(message.getHeaders()).setHeader("profile", env).build();
        System.out.println("Message 2:\n" + message2.getPayload().toString());
        return message2;
    }
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Sorry, not enough info. Please, share that property and show us how you set a `profile` based on that property. – Artem Bilan Sep 12 '18 at 18:34
  • The property is set in application.properties file like this: spring.profiles.active=dev – Shrikkanth Ramesh Sep 12 '18 at 18:55
  • And is called in the xml file as – Shrikkanth Ramesh Sep 12 '18 at 19:08
  • That's something wrong. I believe you need to make yourself familiar with existing `profile` support in Spring Framework: https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-definition-profiles. I don't see reason to make a routing based on a statically defined profile value. You can just show and hide some set of beans according profile activation without any runtime overhead for dynamic resolutions. – Artem Bilan Sep 12 '18 at 19:14

0 Answers0