欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Java RelaxedPropertyResolver类使用实例

最编程 2024-01-16 11:06:06
...

实例1: isTemplateAvailable

import org.springframework.boot.bind.RelaxedPropertyResolver; //导入依赖的package包/类
@Override
public boolean isTemplateAvailable(String view, Environment environment,
                                   ClassLoader classLoader, ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.apache.velocity.app.VelocityEngine", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment,
                "spring.velocity.");
        String loaderPath = resolver.getProperty("resource-loader-path",
                VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH);
        String prefix = resolver.getProperty("prefix",
                VelocityProperties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix",
                VelocityProperties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(loaderPath + prefix + view + suffix)
                             .exists();
    }
    return false;
}
 

实例2: getValue

import org.springframework.boot.bind.RelaxedPropertyResolver; //导入依赖的package包/类
private String getValue(String source, String defaultValue) {
	if (this.environment == null) {
		addWarn("No Spring Environment available to resolve " + source);
		return defaultValue;
	}
	String value = this.environment.getProperty(source);
	if (value != null) {
		return value;
	}
	int lastDot = source.lastIndexOf(".");
	if (lastDot > 0) {
		String prefix = source.substring(0, lastDot + 1);
		RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
				this.environment, prefix);
		return resolver.getProperty(source.substring(lastDot + 1), defaultValue);
	}
	return defaultValue;
}
 

实例3: getMatchOutcome

import org.springframework.boot.bind.RelaxedPropertyResolver; //导入依赖的package包/类
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	final RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(),
			"holon.swagger.");

	if (!resolver.getProperty("holon.swagger.enabled", boolean.class, true)) {
		return ConditionOutcome.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition")
				.because("holon.swagger.enabled is false"));
	}

	if (resolver.containsProperty("resourcePackage")) {
		return ConditionOutcome.noMatch(
				ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("resourcePackage"));
	}
	Map<String, Object> ag = resolver.getSubProperties("apiGroups");
	if (ag != null && ag.size() > 0) {
		return ConditionOutcome
				.noMatch(ConditionMessage.forCondition("SwaggerApiAutoDetectCondition").available("apiGroups"));
	}
	return ConditionOutcome.match();
}
 

实例4: setEnvironment

import org.springframework.boot.bind.RelaxedPropertyResolver; //导入依赖的package包/类
public void setEnvironment(Environment environment) {
    this.propertyResolver = new RelaxedPropertyResolver(environment, null);
    this.url = propertyResolver.getProperty("spring.datasource.url");
    this.userName= propertyResolver.getProperty("spring.datasource.username");
    this.password = propertyResolver.getProperty("spring.datasource.password");
    this.driveClassName = propertyResolver.getProperty("spring.datasource.driver-class-name");
    this.filters = propertyResolver.getProperty("spring.datasource.filters");
    this.maxActive = propertyResolver.getProperty("spring.datasource.maxActive");
    this.initialSize = propertyResolver.getProperty("spring.datasource.initialSize");
    this.maxWait = propertyResolver.getProperty("spring.datasource.maxWait");
    this.minIdle = propertyResolver.getProperty("spring.datasource.minIdle");
    this.timeBetweenEvictionRunsMillis = propertyResolver.getProperty("spring.datasource.timeBetweenEvictionRunsMillis");
    this.minEvictableIdleTimeMillis = propertyResolver.getProperty("spring.datasource.minEvictableIdleTimeMillis");
    this.validationQuery = propertyResolver.getProperty("spring.datasource.validationQuery");
    this.testWhileIdle = propertyResolver.getProperty("spring.datasource.testWhileIdle");
    this.testOnBorrow = propertyResolver.getProperty("spring.datasource.testOnBorrow");
    this.testOnReturn = propertyResolver.getProperty("spring.datasource.testOnReturn");
    this.poolPreparedStatements = propertyResolver.getProperty("spring.datasource.poolPreparedStatements");
    this.maxOpenPreparedStatements = propertyResolver.getProperty("spring.datasource.maxOpenPreparedStatements");
    this.typeAliasesPackage = propertyResolver.getProperty("mybatis.typeAliasesPackage");
    this.xmlLocation = propertyResolver.getProperty("mybatis.xmlLocation");
}
 

实例5: initTargetDataSources

import org.springframework.boot.bind.RelaxedPropertyResolver; //导入依赖的package包/类
/**
 * @param env
 * @Title: initTargetDataSources
 * @Description: 初始化更多数据源
 * @author Kola 6089555
 * @date 2017年4月24日 下午6:45:32
 */
private void initTargetDataSources(Environment env) {
    RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "druid.slaveSource.");
    String slaveNodes = propertyResolver.getProperty("node");
    if (StringUtils.isNotBlank(slaveNodes)) {
        for (String dsPrefix : slaveNodes.split(",")) {
            if (StringUtils.isNotBlank(dsPrefix)) {
                String dataSourceClass = new RelaxedPropertyResolver(env, "druid.slaveSource." + dsPrefix + ".").getProperty("type");
                if (StringUtils.isNotBlank(dataSourceClass)) {
                    DataSource dataSource = buildDataSource(dataSourceClass);
                    dataBinder(dataSource, env, "druid.slaveSource." + dsPrefix);
                    targetDataSources.put(dsPrefix, dataSource);
                }
            }
        }
    }
}
 

推荐阅读