Java Code Examples for org.springframework.core.env.ConfigurableEnvironment#containsProperty()

The following examples show how to use org.springframework.core.env.ConfigurableEnvironment#containsProperty() . 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: FunctionDeployerConfiguration.java    From spring-cloud-function with Apache License 2.0 7 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
String functionName = environment.containsProperty("function.name") ? environment.getProperty("function.name") : null;
	String functionLocation = environment.containsProperty("function.location") ? environment.getProperty("function.location") : null;
	if (StringUtils.hasText(functionName) || StringUtils.hasText(functionLocation)) {
		MutablePropertySources propertySources = environment.getPropertySources();
		propertySources.forEach(ps -> {
			if (ps instanceof PropertiesPropertySource) {
				((MapPropertySource) ps).getSource().put(FunctionProperties.PREFIX + ".definition", functionName);
				((MapPropertySource) ps).getSource().put(FunctionProperties.PREFIX + ".location", functionLocation);
			}
		});
	}
}
 
Example 2
Source File: PlatformMybatisApplicationRunListener.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
    Properties props = new Properties();

    if (environment.containsProperty(MYBATIS_ENCRYPT_PASSWORD)) {
        System.setProperty(MYBATIS_ENCRYPT_PASSWORD, environment.getProperty(MYBATIS_ENCRYPT_PASSWORD));
    }

    if (environment.containsProperty(MYBATIS_ENCRYPT_SALT)) {
        System.setProperty(MYBATIS_ENCRYPT_SALT, environment.getProperty(MYBATIS_ENCRYPT_SALT));
    }

    if (environment.containsProperty(SHA1_COLUMN_HANDLER_SALT)) {
        System.setProperty(SHA1_COLUMN_HANDLER_SALT, environment.getProperty(SHA1_COLUMN_HANDLER_SALT));
    }
    if (environment.containsProperty(MYBATIS_TYPE_HANDLERS_PACKAGE)) {
        props.put(MYBATIS_TYPE_HANDLERS_PACKAGE,
            environment.getProperty(MYBATIS_TYPE_HANDLERS_PACKAGE) + "," + MYBATIS_TYPE_HANDLERS_PACKAGE_VALUE);
    } else {
        props.put(MYBATIS_TYPE_HANDLERS_PACKAGE, MYBATIS_TYPE_HANDLERS_PACKAGE_VALUE);
    }
    environment.getPropertySources().addFirst(new PropertiesPropertySource("summerframeworkMybatis", props));
}
 
Example 3
Source File: MybatisplusApplicationRunListener.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
    Properties props = new Properties();
    if (!environment.containsProperty(ID_TYPE)) {

        props.put(ID_TYPE, ID_TYPE_AUTO);
    }

    if (environment.containsProperty(MYBATIS_TYPE_HANDLERS_PACKAGE)) {
        props.put(MYBATIS_TYPE_HANDLERS_PACKAGE,
            environment.getProperty(MYBATIS_TYPE_HANDLERS_PACKAGE) + "," + MYBATIS_TYPE_HANDLERS_PACKAGE_VALUE);
    } else {
        props.put(MYBATIS_TYPE_HANDLERS_PACKAGE, MYBATIS_TYPE_HANDLERS_PACKAGE_VALUE);
    }
    environment.getPropertySources().addFirst(new PropertiesPropertySource("summerframeworkMybatisplus", props));
}
 
Example 4
Source File: WebapiApplicationRunListener.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
    String profiles = environment.getProperty("spring.profiles.active");
    List<String> productProfiles = Arrays.asList("prod", "product");
    if (environment.containsProperty(PLATFORM_PROFILE_PRODUCT_NAME)) {
        productProfiles = Arrays.asList(environment.getProperty(PLATFORM_PROFILE_PRODUCT_NAME));
    }
    if (!StringUtils.isEmpty(profiles)) {
        if (productProfiles.stream().anyMatch(p -> profiles.toLowerCase().contains(p.toLowerCase()))) {
            environment.addActiveProfile("noSwagger");
        } else {
            environment.addActiveProfile("swagger");
        }
    }else {
        // 不指定profile则默认开启swagger,开发机一般不指定
        environment.addActiveProfile("swagger");
    }
}
 
Example 5
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with Apache License 2.0 6 votes vote down vote up
private String getProperty(String property, ConfigurableEnvironment env) {
    return env.containsProperty(property) ? env.getProperty(property) : "";
}
 
Example 6
Source File: TraceEnvironmentPostProcessor.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
    SpringApplication application) {
  Map<String, Object> map = new HashMap<>();

  if (!environment.containsProperty(SPRING_AOP_PROXY_TARGET_CLASS)) {
    map.put(SPRING_AOP_PROXY_TARGET_CLASS, "true");
  }

  addOrReplace(environment.getPropertySources(), map);
}
 
Example 7
Source File: FlowableLiquibaseEnvironmentPostProcessor.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(final ConfigurableEnvironment env, final SpringApplication app) {
    if (!env.containsProperty(LIQUIBASE_PROPERTY)) {
        env.getPropertySources().addLast(
                new MapPropertySource("flowable-liquibase-override", Map.of(LIQUIBASE_PROPERTY, false)));
    }
}
 
Example 8
Source File: BootstrapEnvironmentPostProcessorIntegrationTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {
	HashMap<String, Object> map = new HashMap<>();

	if (!environment.containsProperty("conditional.property")) {
		map.put("conditional.property", "conditional.value");
	}
	map.put("unconditional.property", "unconditional.value");

	MapPropertySource propertySource = new MapPropertySource("test-epp-map", map);
	environment.getPropertySources().addFirst(propertySource);
}
 
Example 9
Source File: CustomRuntimeEnvironmentPostProcessor.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {
	if (!environment.containsProperty(CUSTOM_RUNTIME)) {
		Map<String, Object> defaults = getDefaultProperties(environment);
		defaults.putIfAbsent("spring.cloud.function.web.export.source.url",
				"http://${AWS_LAMBDA_RUNTIME_API:localhost}/2018-06-01/runtime/invocation/next");
		defaults.putIfAbsent("spring.cloud.function.web.export.sink.url",
				"http://${AWS_LAMBDA_RUNTIME_API:localhost}/2018-06-01/runtime/invocation/{{destination}}/response");
		defaults.put("spring.cloud.function.web.export.sink.name",
				"origin|${_HANDLER:}");
		defaults.put(CUSTOM_RUNTIME, true);
	}
}
 
Example 10
Source File: EnvironmentSetupListener.java    From Kafdrop with Apache License 2.0 5 votes vote down vote up
@Override
public void environmentPrepared(ConfigurableEnvironment environment)
{
   if (environment.containsProperty(SM_CONFIG_DIR))
   {
      Stream.of("kafdrop", "global")
         .map(name -> readProperties(environment, name))
         .filter(Objects::nonNull)
         .forEach(iniPropSource -> environment.getPropertySources()
            .addLast(iniPropSource));
   }
}
 
Example 11
Source File: FlowableLiquibaseEnvironmentPostProcessor.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    String liquibaseProperty = getLiquibaseProperty();
    if (!environment.containsProperty(liquibaseProperty)) {
        LOGGER.warn("Liquibase has not been explicitly enabled or disabled. Overriding default from Spring Boot from `true` to `false`. "
            + "Flowable pulls in Liquibase, but does not use the Spring Boot configuration for it. "
            + "If you are using it you would need to set `{}` to `true` by yourself", liquibaseProperty);
        Map<String, Object> source = new HashMap<>();
        source.put(liquibaseProperty, false);
        environment.getPropertySources().addLast(new MapPropertySource("flowable-liquibase-override", source));
    }
}
 
Example 12
Source File: GatewayRSocketEnvironmentPostProcessor.java    From spring-cloud-rsocket with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment env,
		SpringApplication application) {
	Boolean enabled = env.getProperty("spring.cloud.gateway.rsocket.enabled",
			Boolean.class, true);
	if (enabled && !env.containsProperty("spring.rsocket.server.port")) {
		Map<String, Object> map = Collections
				.singletonMap("spring.rsocket.server.port", 7002);
		env.getPropertySources()
				.addLast(new MapPropertySource("Default Gateway RSocket Port", map));
	}
}
 
Example 13
Source File: JobCenterEurekaConfigurationListener.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
    if (!environment.containsProperty(defaultZoneKey)) {
        Properties props = new Properties();
        props.put(defaultZoneKey, defaultZone);
        environment.getPropertySources().addFirst(new PropertiesPropertySource("defaultJobCentoerConfig", props));
    }
}
 
Example 14
Source File: SpringSessionAutoConfiguration.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
protected static boolean isSet(ConfigurableEnvironment environment, String propertyName) {

		return environment.containsProperty(propertyName)
			&& StringUtils.hasText(environment.getProperty(propertyName));
	}
 
Example 15
Source File: Main.java    From CogStack-Pipeline with Apache License 2.0 4 votes vote down vote up
public static void setUpApplicationContext(ConfigurableEnvironment environment, Properties properties) {
    @SuppressWarnings("resource")
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.registerShutdownHook();
    ctx.setEnvironment(environment);

    // TODO: need a proper way to validate input properties specified by user
    String executionMode = environment.getProperty("execution.mode", "local").toLowerCase();
    if (executionMode != "local" && executionMode != "remote")
        throw new RuntimeException("Invalid execution mode specified. Must be `local` (default) or `remote`.");

    String instanceType = "";
    if (executionMode == "remote")
    {
        if (!environment.containsProperty("execution.instanceType")) {
            throw new RuntimeException("Instance type in remote execution not specified. Must be `master` or `slave`.");
        }

        instanceType = environment.getRequiredProperty("execution.instanceType").toLowerCase();
        if (instanceType != "master" && instanceType != "slave")
            throw new RuntimeException("Invalid instance type in remote execution mode specified. Must be `master` or `slave`.");
    }

    boolean useScheduling;
    try {
        useScheduling = Boolean.parseBoolean(environment.getProperty("scheduler.useScheduling", "false"));
    } catch (Exception e) {
        throw new RuntimeException("Invalid scheduling option specified. Must be `true` or `false` (default).");
    }

    // set appropriate job configuration
    if (executionMode == "remote" && instanceType == "slave") {
        ctx.register(JobConfiguration.class);
        ctx.refresh();
    } else { // execution mode local or remote with master
        if (useScheduling) {
            ctx.register(ScheduledJobLauncher.class);
            ctx.refresh();
        } else {
            ctx.register(SingleJobLauncher.class);
            ctx.refresh();
            SingleJobLauncher launcher = ctx.getBean(SingleJobLauncher.class);
            launcher.launchJob();
        }
    }
}
 
Example 16
Source File: DefaultParameterStorePropertySourceConfigurationStrategy.java    From spring-boot-parameter-store-integration with MIT License 4 votes vote down vote up
private boolean hasCustomEndpoint(ConfigurableEnvironment environment)
{
    return environment.containsProperty(ParameterStorePropertySourceConfigurationProperties.SSM_CLIENT_CUSTOM_ENDPOINT);
}
 
Example 17
Source File: ParameterStorePropertySourceEnvironmentPostProcessor.java    From spring-boot-parameter-store-integration with MIT License 4 votes vote down vote up
private boolean isMultiRegionEnabled(ConfigurableEnvironment environment)
{
    return environment.containsProperty(ParameterStorePropertySourceConfigurationProperties.MULTI_REGION_SSM_CLIENT_REGIONS);
}
 
Example 18
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with Apache License 2.0 4 votes vote down vote up
private String getProperty(String property, ConfigurableEnvironment env) {
    return env.containsProperty(property) ? env.getProperty(property) : "";
}