0

I've build a native image with graalvm and micronaut, but my native-image app cannot get the environmental variable using @Value annotation. When I try to run the app as jar, it works just fine.

@Singleton
public class WebComponentService {
    @Value("${config.adyen.merchantaccount}")
    private String merchantAccount;
}

This is the error I get

Message: Error setting field value: No field 'merchantAccount' found for type: example.micronaut.getOriginKeys.WebComponentService Path Taken: new GetOriginKeysController([WebComponentService webComponentService]) io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [merchantAccount] of class: example.micronaut.getOriginKeys.WebComponentService

However, when I try to get the environmental variables like this, it works fine.

Map<String, String> environmentVars  = System.getenv();
String merchantAccount = environmentVars.get("CONFIG_ADYEN_MERCHANTACCOUNT");

This is how I run the native app

$ CONFIG_ADYEN_MERCHANTACCOUNT=CommercetoolsGmbHDE775 ./theNativeApp
Lojza Ibg
  • 658
  • 9
  • 32

1 Answers1

0

The key you have used here @Value("${config.adyen.merchantaccount}") is different than environmentVars.get("CONFIG_ADYEN_MERCHANTACCOUNT");

Make sure they're the same

  • Thanks for the reply. How come it works with JAR? Can you explain? I suppose micronaut does support relaxed binding for @Value like Spring does. https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-relaxed-binding – Lojza Ibg Oct 04 '20 at 10:29
  • 1
    Relaxed binding isn't available with ```@Value```. See [this](https://github.com/spring-projects/spring-boot/issues/4413) discussion – Hasham Rasheed Oct 04 '20 at 13:19
  • I udpated my code to use `@Value("${CONFIG_ADYEN_MERCHANTACCOUNT}")` and it still doesn't work. I don't think it's related to relaxed binding, since I built JAR from it and it works just fine. When I use that JAR to build a native-image, it stops working. – Lojza Ibg Nov 07 '20 at 09:21