org.springframework.core.env.AbstractEnvironment Java Examples
The following examples show how to use
org.springframework.core.env.AbstractEnvironment.
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: EnvironmentConfigurationLogger.java From pcf-crash-course-with-spring-boot with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { LOGGER.info("{}", prop); // Object resolved = environment.getProperty(prop, Object.class); // if (resolved instanceof String) { // LOGGER.info("{}", environment.getProperty(prop)); // } }); LOGGER.info("==========================================="); }
Example #2
Source File: EnvironmentConfigurationLogger.java From pcf-crash-course-with-spring-boot with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { LOGGER.info("{}", prop); // Object resolved = environment.getProperty(prop, Object.class); // if (resolved instanceof String) { // LOGGER.info("{}", environment.getProperty(prop)); // } }); LOGGER.info("==========================================="); }
Example #3
Source File: EnvironmentConfigurationLogger.java From pcf-crash-course-with-spring-boot with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { LOGGER.info("{}", prop); // Object resolved = environment.getProperty(prop, Object.class); // if (resolved instanceof String) { // LOGGER.info("{}", environment.getProperty(prop)); // } }); LOGGER.info("==========================================="); }
Example #4
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #5
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #6
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #7
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #8
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #9
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #10
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #11
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #12
Source File: EnvironmentConfigurationLogger.java From kubernetes-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { Object resolved = environment.getProperty(prop, Object.class); if (resolved instanceof String) { LOGGER.info("{} - {}", prop, environment.getProperty(prop)); } else { LOGGER.info("{} - {}", prop, "NON-STRING-VALUE"); } }); LOGGER.debug("==========================================="); }
Example #13
Source File: EnvironmentConfigurationLogger.java From docker-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.debug("====== Environment and configuration ======"); LOGGER.debug("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { LOGGER.debug("{}", prop); // Object resolved = environment.getProperty(prop, Object.class); // if (resolved instanceof String) { // LOGGER.info("{}", environment.getProperty(prop)); // } }); LOGGER.debug("==========================================="); }
Example #14
Source File: EnvironmentConfigurationLogger.java From docker-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.debug("====== Environment and configuration ======"); LOGGER.debug("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { LOGGER.debug("{}", prop); // Object resolved = environment.getProperty(prop, Object.class); // if (resolved instanceof String) { // LOGGER.info("{}", environment.getProperty(prop)); // } }); LOGGER.debug("==========================================="); }
Example #15
Source File: EnvironmentConfigurationLogger.java From docker-crash-course with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.debug("====== Environment and configuration ======"); LOGGER.debug("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> { LOGGER.debug("{}", prop); // Object resolved = environment.getProperty(prop, Object.class); // if (resolved instanceof String) { // LOGGER.info("{}", environment.getProperty(prop)); // } }); LOGGER.debug("==========================================="); }
Example #16
Source File: Application.java From Mahuta with Apache License 2.0 | 6 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment env = event.getApplicationContext().getEnvironment(); log.trace("====== Environment and configuration ======"); log.trace("Active profiles: {}", Arrays.toString(env.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) env).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .filter(prop -> !(prop.contains("credentials") || prop.contains("password"))) .forEach(prop -> log.trace("{}: {}", prop, env.getProperty(prop))); log.info("==========================================="); log.info("Application [{} - version: {}, build time: {}] Started !", buildProperties.getGroup() + ":" + buildProperties.getArtifact(), buildProperties.getVersion(), buildProperties.getTime()); log.info("==========================================="); }
Example #17
Source File: DaqStartup.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
public static synchronized void start(String[] args) throws IOException { String daqName = getProperty("c2mon.daq.name"); if (daqName == null) { throw new RuntimeException("Please specify the DAQ process name using 'c2mon.daq.name'"); } // The JMS mode (single, double, test) is controlled via Spring profiles String mode = getProperty("c2mon.daq.jms.mode"); if (mode != null) { System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, mode); } if (application == null) { application = new SpringApplicationBuilder(DaqStartup.class) .bannerMode(Banner.Mode.OFF) .build(); } context = application.run(args); driverKernel = context.getBean(DriverKernel.class); driverKernel.init(); log.info("DAQ core is now initialized"); }
Example #18
Source File: SimpleEnvironmentVariablesProvider.java From spring-cloud-task with Apache License 2.0 | 6 votes |
private Map<String, String> getCurrentEnvironmentProperties() { Map<String, String> currentEnvironment = new HashMap<>(); Set<String> keys = new HashSet<>(); for (PropertySource<?> propertySource : ((AbstractEnvironment) this.environment) .getPropertySources()) { if (propertySource instanceof MapPropertySource) { keys.addAll(Arrays .asList(((MapPropertySource) propertySource).getPropertyNames())); } } for (String key : keys) { currentEnvironment.put(key, this.environment.getProperty(key)); } return currentEnvironment; }
Example #19
Source File: DispatcherWebscript.java From alfresco-mvc with Apache License 2.0 | 6 votes |
protected void configureDispatcherServlet(DispatcherServlet dispatcherServlet) { if (inheritGlobalProperties) { final Properties globalProperties = (Properties) this.applicationContext.getBean("global-properties"); ConfigurableEnvironment servletEnv = dispatcherServlet.getEnvironment(); servletEnv.merge(new AbstractEnvironment() { @Override public MutablePropertySources getPropertySources() { MutablePropertySources mutablePropertySources = new MutablePropertySources(); mutablePropertySources .addFirst(new PropertiesPropertySource("alfresco-global.properties", globalProperties)); return mutablePropertySources; } }); } }
Example #20
Source File: BeanFactory.java From vividus with Apache License 2.0 | 5 votes |
private static String[] getActiveProfiles() { try { String value = ConfigurationResolver.getInstance().getProperties() .getProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME); return value != null ? value.split(",") : new String[]{}; } catch (IOException e) { throw new IllegalStateException(e); } }
Example #21
Source File: EnvironmentSecurityManagerIntegrationTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey() { SecurityManager securityManager = new SecurityManager() { @Override public void checkPermission(Permission perm) { // Disallowing access to System#getenv means that our // ReadOnlySystemAttributesMap will come into play. if ("getenv.*".equals(perm.getName())) { throw new AccessControlException("Accessing the system environment is disallowed"); } // Disallowing access to the spring.profiles.active property means that // the BeanDefinitionReader won't be able to determine which profiles are // active. We should see an INFO-level message in the console about this // and as a result, any components marked with a non-default profile will // be ignored. if (("getenv." + AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME).equals(perm.getName())) { throw new AccessControlException( format("Accessing system environment variable [%s] is disallowed", AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)); } } }; System.setSecurityManager(securityManager); DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf); reader.register(C1.class); assertThat(bf.containsBean("c1"), is(false)); }
Example #22
Source File: EnvironmentConfigurationLogger.java From pcf-crash-course-with-spring-boot with MIT License | 5 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.info("====== Environment and configuration ======"); LOGGER.info("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> LOGGER.info("{}", prop));// environment.getProperty(prop) LOGGER.info("==========================================="); }
Example #23
Source File: EnvironmentProperties.java From alibaba-rsocket-broker with Apache License 2.0 | 5 votes |
@Override public Enumeration<?> propertyNames() { Set<String> names = new HashSet<>(); for (PropertySource<?> propertySource : ((AbstractEnvironment) env).getPropertySources()) { if (propertySource instanceof EnumerablePropertySource) { Collections.addAll(names, ((EnumerablePropertySource) propertySource).getPropertyNames()); } } return Collections.enumeration(names); }
Example #24
Source File: EnvironmentConfigurationLogger.java From docker-crash-course with MIT License | 5 votes |
@SuppressWarnings("rawtypes") @EventListener public void handleContextRefresh(ContextRefreshedEvent event) { final Environment environment = event.getApplicationContext().getEnvironment(); LOGGER.debug("====== Environment and configuration ======"); LOGGER.debug("Active profiles: {}", Arrays.toString(environment.getActiveProfiles())); final MutablePropertySources sources = ((AbstractEnvironment) environment).getPropertySources(); StreamSupport.stream(sources.spliterator(), false).filter(ps -> ps instanceof EnumerablePropertySource) .map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream).distinct() .forEach(prop -> LOGGER.debug("{}", prop));// environment.getProperty(prop) LOGGER.debug("==========================================="); }
Example #25
Source File: EnvironmentSecurityManagerIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey() { SecurityManager securityManager = new SecurityManager() { @Override public void checkPermission(Permission perm) { // Disallowing access to System#getenv means that our // ReadOnlySystemAttributesMap will come into play. if ("getenv.*".equals(perm.getName())) { throw new AccessControlException("Accessing the system environment is disallowed"); } // Disallowing access to the spring.profiles.active property means that // the BeanDefinitionReader won't be able to determine which profiles are // active. We should see an INFO-level message in the console about this // and as a result, any components marked with a non-default profile will // be ignored. if (("getenv." + AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME).equals(perm.getName())) { throw new AccessControlException( format("Accessing system environment variable [%s] is disallowed", AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)); } } }; System.setSecurityManager(securityManager); DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf); reader.register(C1.class); assertThat(bf.containsBean("c1"), is(false)); }
Example #26
Source File: LogFeederProps.java From ambari-logsearch with Apache License 2.0 | 5 votes |
@PostConstruct public void init() { properties = new Properties(); MutablePropertySources propSrcs = ((AbstractEnvironment) env).getPropertySources(); ResourcePropertySource propertySource = (ResourcePropertySource) propSrcs.get("class path resource [" + LogFeederConstants.LOGFEEDER_PROPERTIES_FILE + "]"); if (propertySource != null) { Stream.of(propertySource) .map(MapPropertySource::getPropertyNames) .flatMap(Arrays::<String>stream) .forEach(propName -> properties.setProperty(propName, env.getProperty(propName))); } else { throw new IllegalArgumentException("Cannot find logfeeder.properties on the classpath"); } }
Example #27
Source File: DubboRelaxedBinding2AutoConfiguration.java From dubbo-spring-boot-project with Apache License 2.0 | 5 votes |
@Bean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) public PropertyResolver dubboScanBasePackagesPropertyResolver(ConfigurableEnvironment environment) { ConfigurableEnvironment propertyResolver = new AbstractEnvironment() { @Override protected void customizePropertySources(MutablePropertySources propertySources) { Map<String, Object> dubboScanProperties = getSubProperties(environment.getPropertySources(), DUBBO_SCAN_PREFIX); propertySources.addLast(new MapPropertySource("dubboScanProperties", dubboScanProperties)); } }; ConfigurationPropertySources.attach(propertyResolver); return new DelegatingPropertyResolver(propertyResolver); }
Example #28
Source File: EnvironmentSecurityManagerIntegrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey() { SecurityManager securityManager = new SecurityManager() { @Override public void checkPermission(Permission perm) { // Disallowing access to System#getenv means that our // ReadOnlySystemAttributesMap will come into play. if ("getenv.*".equals(perm.getName())) { throw new AccessControlException("Accessing the system environment is disallowed"); } // Disallowing access to the spring.profiles.active property means that // the BeanDefinitionReader won't be able to determine which profiles are // active. We should see an INFO-level message in the console about this // and as a result, any components marked with a non-default profile will // be ignored. if (("getenv." + AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME).equals(perm.getName())) { throw new AccessControlException( format("Accessing system environment variable [%s] is disallowed", AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)); } } }; System.setSecurityManager(securityManager); DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf); reader.register(C1.class); assertThat(bf.containsBean("c1"), is(false)); }
Example #29
Source File: EventBasedConfigurationChangeDetector.java From spring-cloud-kubernetes with Apache License 2.0 | 5 votes |
public EventBasedConfigurationChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties, KubernetesClient kubernetesClient, ConfigurationUpdateStrategy strategy, ConfigMapPropertySourceLocator configMapPropertySourceLocator, SecretsPropertySourceLocator secretsPropertySourceLocator) { super(environment, properties, kubernetesClient, strategy); this.configMapPropertySourceLocator = configMapPropertySourceLocator; this.secretsPropertySourceLocator = secretsPropertySourceLocator; this.watches = new HashMap<>(); }
Example #30
Source File: PollingConfigurationChangeDetector.java From spring-cloud-kubernetes with Apache License 2.0 | 5 votes |
public PollingConfigurationChangeDetector(AbstractEnvironment environment, ConfigReloadProperties properties, KubernetesClient kubernetesClient, ConfigurationUpdateStrategy strategy, ConfigMapPropertySourceLocator configMapPropertySourceLocator, SecretsPropertySourceLocator secretsPropertySourceLocator) { super(environment, properties, kubernetesClient, strategy); this.configMapPropertySourceLocator = configMapPropertySourceLocator; this.secretsPropertySourceLocator = secretsPropertySourceLocator; }