org.springframework.core.env.CommandLinePropertySource Java Examples
The following examples show how to use
org.springframework.core.env.CommandLinePropertySource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringApplication.java From spring-javaformat with Apache License 2.0 | 6 votes |
/** * Add, remove or re-order any {@link PropertySource}s in this application's * environment. * @param environment this application's environment * @param args arguments passed to the {@code run} method * @see #configureEnvironment(ConfigurableEnvironment, String[]) */ protected void configurePropertySources(ConfigurableEnvironment environment, String[] args) { MutablePropertySources sources = environment.getPropertySources(); if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) { sources.addLast( new MapPropertySource("defaultProperties", this.defaultProperties)); } if (this.addCommandLineProperties && args.length > 0) { String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME; if (sources.contains(name)) { PropertySource<?> source = sources.get(name); CompositePropertySource composite = new CompositePropertySource(name); composite.addPropertySource(new SimpleCommandLinePropertySource( "springApplicationCommandLineArgs", args)); composite.addPropertySource(source); sources.replace(name, composite); } else { sources.addFirst(new SimpleCommandLinePropertySource(args)); } } }
Example #2
Source File: CfDataSourceEnvironmentPostProcessor.java From java-cfenv with Apache License 2.0 | 4 votes |
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { increaseInvocationCount(); if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) { CfJdbcEnv cfJdbcEnv = new CfJdbcEnv(); CfJdbcService cfJdbcService = null; try { cfJdbcService = cfJdbcEnv.findJdbcService(); cfJdbcService = this.isEnabled(cfJdbcService, environment) ? cfJdbcService : null; } catch (Exception e) { List<CfJdbcService> jdbcServices = cfJdbcEnv.findJdbcServices().stream() .filter(service -> this.isEnabled(service, environment)) .collect(Collectors.toList()); if (jdbcServices.size() > 1) { if (invocationCount == 1) { DEFERRED_LOG.debug( "Skipping execution of CfDataSourceEnvironmentPostProcessor. " + e.getMessage()); } return; } cfJdbcService = jdbcServices.size() == 1 ? jdbcServices.get(0) : null; } if (cfJdbcService != null) { ConnectorLibraryDetector.assertNoConnectorLibrary(); Map<String, Object> properties = new LinkedHashMap<>(); properties.put("spring.datasource.url", cfJdbcService.getJdbcUrl()); properties.put("spring.datasource.username", cfJdbcService.getUsername()); properties.put("spring.datasource.password", cfJdbcService.getPassword()); Object driverClassName = cfJdbcService.getDriverClassName(); if (driverClassName != null) { properties.put("spring.datasource.driver-class-name", driverClassName); } MutablePropertySources propertySources = environment.getPropertySources(); if (propertySources.contains( CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) { propertySources.addAfter( CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, new MapPropertySource("cfenvjdbc", properties)); } else { propertySources .addFirst(new MapPropertySource("cfenvjdbc", properties)); } if (invocationCount == 1) { DEFERRED_LOG.info( "Setting spring.datasource properties from bound service [" + cfJdbcService.getName() + "]"); } } } else { DEFERRED_LOG.debug( "Not setting spring.datasource.url, not in Cloud Foundry Environment"); } }
Example #3
Source File: ProfileApplicationListener.java From spring-cloud-skipper with Apache License 2.0 | 4 votes |
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { this.environment = event.getEnvironment(); Iterable<CloudProfileProvider> cloudProfileProviders = ServiceLoader.load(CloudProfileProvider.class); if (ignoreFromSystemProperty() || ignoreFromEnvironmentVariable() || cloudProfilesAlreadySet(cloudProfileProviders)) { return; } boolean addedCloudProfile = false; boolean addedKubernetesProfile = false; for (CloudProfileProvider cloudProfileProvider : cloudProfileProviders) { if (cloudProfileProvider.isCloudPlatform(environment)) { String profileToAdd = cloudProfileProvider.getCloudProfile(); if (!Arrays.asList(environment.getActiveProfiles()).contains(profileToAdd)) { if (profileToAdd.equals(KubernetesCloudProfileProvider.PROFILE)) { addedKubernetesProfile = true; } environment.addActiveProfile(profileToAdd); addedCloudProfile = true; } } } if (!addedKubernetesProfile) { Map<String, Object> properties = new LinkedHashMap<>(); properties.put("spring.cloud.kubernetes.enabled", false); logger.info("Setting property 'spring.cloud.kubernetes.enabled' to false."); MutablePropertySources propertySources = environment.getPropertySources(); if (propertySources != null) { if (propertySources.contains( CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) { propertySources.addAfter( CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, new MapPropertySource("skipperProfileApplicationListener", properties)); } else { propertySources .addFirst(new MapPropertySource("skipperProfileApplicationListener", properties)); } } } if (!addedCloudProfile) { environment.addActiveProfile("local"); } }
Example #4
Source File: ProfileApplicationListener.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { this.environment = event.getEnvironment(); Iterable<CloudProfileProvider> cloudProfileProviders = ServiceLoader.load(CloudProfileProvider.class); if (ignoreFromSystemProperty() || ignoreFromEnvironmentVariable() || cloudProfilesAlreadySet(cloudProfileProviders)) { return; } boolean addedCloudProfile = false; boolean addedKubernetesProfile = false; for (CloudProfileProvider cloudProfileProvider : cloudProfileProviders) { if (cloudProfileProvider.isCloudPlatform(environment)) { String profileToAdd = cloudProfileProvider.getCloudProfile(); if (!Arrays.asList(environment.getActiveProfiles()).contains(profileToAdd)) { if (profileToAdd.equals(KubernetesCloudProfileProvider.PROFILE)) { addedKubernetesProfile = true; } environment.addActiveProfile(profileToAdd); addedCloudProfile = true; } } } if (!addedKubernetesProfile) { Map<String, Object> properties = new LinkedHashMap<>(); properties.put("spring.cloud.kubernetes.enabled", false); logger.info("Setting property 'spring.cloud.kubernetes.enabled' to false."); MutablePropertySources propertySources = environment.getPropertySources(); if (propertySources != null) { if (propertySources.contains( CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) { propertySources.addAfter( CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, new MapPropertySource("skipperProfileApplicationListener", properties)); } else { propertySources .addFirst(new MapPropertySource("skipperProfileApplicationListener", properties)); } } } if (!addedCloudProfile) { environment.addActiveProfile("local"); } }
Example #5
Source File: MempoolFeeRateProvider.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
private static Optional<String[]> args(Environment env) { return Optional.ofNullable( env.getProperty(CommandLinePropertySource.DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME, String[].class)); }