Java Magazine, Nov/Dec 2017
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2017 58 java ee Configurations can be easily injected with annotations and Ill show how a little later But they can also be obtained programmatically as shown in Listing 2 Listing 2 public class ConfigUsageExample public void useTheConfig Config config ConfigProvider getConfig String baseUrl config getValue server base url String class invokeEndpoint baseUrl This configuration can be overridden easily at runtime via a system property For example see the snippet given in Listing 3 which overrides server base url Listing 3 java jar myservice jar Dserver base url http another server endpoint The configuration can also be accessed via injection into your beans by using @ Inject and @ ConfigProperty annotations as shown in Listing 4 Listing 4 @ ApplicationScoped public class InjectedConfigUsageExample @ Inject
You must have JavaScript enabled to view digital editions.