org.springframework.core.env.ConfigurableEnvironment#containsProperty ( )源码实例Demo

下面列出了org.springframework.core.env.ConfigurableEnvironment#containsProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
			}
		});
	}
}
 
源代码2 项目: Moss   文件: MultRegisterCenterServerMgmtConfig.java
private String getProperty(String property, ConfigurableEnvironment env) {
    return env.containsProperty(property) ? env.getProperty(property) : "";
}
 
@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));
}
 
@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));
}
 
@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");
    }
}
 
@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));
    }
}
 
@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));
	}
}
 
@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);
}
 
@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));
    }
}
 
源代码10 项目: Kafdrop   文件: EnvironmentSetupListener.java
@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));
   }
}
 
@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);
	}
}
 
@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);
}
 
@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)));
    }
}
 
源代码14 项目: Moss   文件: MultRegisterCenterServerMgmtConfig.java
private String getProperty(String property, ConfigurableEnvironment env) {
    return env.containsProperty(property) ? env.getProperty(property) : "";
}
 
private boolean isMultiRegionEnabled(ConfigurableEnvironment environment)
{
    return environment.containsProperty(ParameterStorePropertySourceConfigurationProperties.MULTI_REGION_SSM_CLIENT_REGIONS);
}
 
private boolean hasCustomEndpoint(ConfigurableEnvironment environment)
{
    return environment.containsProperty(ParameterStorePropertySourceConfigurationProperties.SSM_CLIENT_CUSTOM_ENDPOINT);
}
 
源代码17 项目: CogStack-Pipeline   文件: Main.java
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();
        }
    }
}
 
protected static boolean isSet(ConfigurableEnvironment environment, String propertyName) {

		return environment.containsProperty(propertyName)
			&& StringUtils.hasText(environment.getProperty(propertyName));
	}