Java Code Examples for org.springframework.core.env.PropertyResolver#getProperty()

The following examples show how to use org.springframework.core.env.PropertyResolver#getProperty() . 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: VelocityTemplateAvailabilityProvider.java    From velocity-spring-boot-project with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isTemplateAvailable(String view, Environment environment,
                                   ClassLoader classLoader, ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.apache.velocity.app.VelocityEngine", classLoader)) {
        PropertyResolver resolver = new CompatibleRelaxedPropertyResolver(environment);
        String loaderPath = resolver.getProperty("resource-loader-path",
                "spring.velocity." + VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH);
        String prefix = resolver.getProperty("prefix",
                "spring.velocity." + VelocityProperties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix",
                "spring.velocity." + VelocityProperties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(loaderPath + prefix + view + suffix)
                .exists();
    }
    return false;
}
 
Example 2
Source File: IdUtils.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
public static String getDefaultInstanceId(PropertyResolver resolver,
		boolean includeHostname) {
	String vcapInstanceId = resolver.getProperty("vcap.application.instance_id");
	if (StringUtils.hasText(vcapInstanceId)) {
		return vcapInstanceId;
	}

	String hostname = null;
	if (includeHostname) {
		hostname = resolver.getProperty("spring.cloud.client.hostname");
	}
	String appName = resolver.getProperty("spring.application.name");

	String namePart = combineParts(hostname, SEPARATOR, appName);

	String indexPart = resolver.getProperty("spring.application.instance_id",
			resolver.getProperty("server.port"));

	return combineParts(namePart, SEPARATOR, indexPart);
}
 
Example 3
Source File: DubboAutoConfiguration.java    From dubbo-spring-boot-project with Apache License 2.0 5 votes vote down vote up
/**
 * Creates {@link ServiceAnnotationBeanPostProcessor} Bean
 *
 * @param propertyResolver {@link PropertyResolver} Bean
 * @return {@link ServiceAnnotationBeanPostProcessor}
 */
@ConditionalOnProperty(prefix = DUBBO_SCAN_PREFIX, name = BASE_PACKAGES_PROPERTY_NAME)
@ConditionalOnBean(name = BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME)
@Bean
public ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor(
        @Qualifier(BASE_PACKAGES_PROPERTY_RESOLVER_BEAN_NAME) PropertyResolver propertyResolver) {
    Set<String> packagesToScan = propertyResolver.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet());
    return new ServiceAnnotationBeanPostProcessor(packagesToScan);
}
 
Example 4
Source File: AbstractEmailTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Bean
public PropertiesParser propertiesParser(PropertyResolver propertyResolver) {
    return new DefaultPropertiesParser() {
        @Override
        public String parseProperty(String key, String value, PropertiesLookup properties) {
            return propertyResolver.getProperty(key);
        }
    };
}
 
Example 5
Source File: AbstractODataTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Bean
public PropertiesParser propertiesParser(PropertyResolver propertyResolver) {
    return new DefaultPropertiesParser() {
        @Override
        public String parseProperty(String key, String value, PropertiesLookup properties) {
            return propertyResolver.getProperty(key);
        }
    };
}
 
Example 6
Source File: AbstractHibernateDatastore.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
protected AbstractHibernateDatastore(MappingContext mappingContext, SessionFactory sessionFactory, PropertyResolver config, ApplicationContext applicationContext, String dataSourceName) {
    super(mappingContext, config, (ConfigurableApplicationContext) applicationContext);
    this.connectionSources = new SingletonConnectionSources<>(new HibernateConnectionSource(dataSourceName, sessionFactory, null, null ), config);
    this.sessionFactory = sessionFactory;
    this.dataSourceName = dataSourceName;
    initializeConverters(mappingContext);
    if(applicationContext != null) {
        setApplicationContext(applicationContext);
    }

    osivReadOnly = config.getProperty(CONFIG_PROPERTY_OSIV_READONLY, Boolean.class, false);
    passReadOnlyToHibernate = config.getProperty(CONFIG_PROPERTY_PASS_READONLY_TO_HIBERNATE, Boolean.class, false);
    isCacheQueries = config.getProperty(CONFIG_PROPERTY_CACHE_QUERIES, Boolean.class, false);

    if( config.getProperty(SETTING_AUTO_FLUSH, Boolean.class, false) ) {
        this.defaultFlushModeName = FlushMode.AUTO.name();
        defaultFlushMode = FlushMode.AUTO.level;
    }
    else {
        FlushMode flushMode = config.getProperty(SETTING_FLUSH_MODE, FlushMode.class, FlushMode.COMMIT);
        this.defaultFlushModeName = flushMode.name();
        defaultFlushMode = flushMode.level;
    }
    failOnError = config.getProperty(SETTING_FAIL_ON_ERROR, Boolean.class, false);
    markDirty = config.getProperty(SETTING_MARK_DIRTY, Boolean.class, false);
    this.tenantResolver = new FixedTenantResolver();
    this.multiTenantMode = MultiTenancySettings.MultiTenancyMode.NONE;
    this.schemaHandler = new DefaultSchemaHandler();
}
 
Example 7
Source File: AbstractHibernateConnectionSourceFactory.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
protected <F extends ConnectionSourceSettings> HibernateConnectionSourceSettings buildSettings(String name, PropertyResolver configuration, F fallbackSettings, boolean isDefaultDataSource) {
    HibernateConnectionSourceSettingsBuilder builder;
    HibernateConnectionSourceSettings settings;
    if(isDefaultDataSource) {
        String qualified = Settings.SETTING_DATASOURCES + '.' + Settings.SETTING_DATASOURCE;
        builder = new HibernateConnectionSourceSettingsBuilder(configuration, "", fallbackSettings);
        Map config = configuration.getProperty(qualified, Map.class, Collections.emptyMap());
        settings = builder.build();
        if(!config.isEmpty()) {

            DataSourceSettings dsfallbackSettings = null;
            if(fallbackSettings instanceof HibernateConnectionSourceSettings) {
                dsfallbackSettings = ((HibernateConnectionSourceSettings)fallbackSettings).getDataSource();
            }
            else if(fallbackSettings instanceof DataSourceSettings) {
                dsfallbackSettings = (DataSourceSettings) fallbackSettings;
            }
            DataSourceSettingsBuilder dataSourceSettingsBuilder = new DataSourceSettingsBuilder(configuration, qualified, dsfallbackSettings);
            DataSourceSettings dataSourceSettings = dataSourceSettingsBuilder.build();
            settings.setDataSource(dataSourceSettings);
        }
    }
    else {
        String prefix = Settings.SETTING_DATASOURCES + "." + name;
        settings = buildSettingsWithPrefix(configuration, fallbackSettings, prefix);
    }
    return settings;
}
 
Example 8
Source File: TrimouTemplateAvailabilityProvider.java    From trimou with Apache License 2.0 5 votes vote down vote up
public boolean isTemplateAvailable(final String view, final Environment environment, final ClassLoader classLoader,
        final ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.trimou.Mustache", classLoader)) {
        final PropertyResolver resolver =
                new RelaxedPropertyResolver(environment, TrimouProperties.PROPERTY_PREFIX + '.');
        final String prefix = resolver.getProperty("prefix", SpringResourceTemplateLocator.DEFAULT_PREFIX);
        final String suffix = resolver.getProperty("suffix", SpringResourceTemplateLocator.DEFAULT_SUFFIX);
        final String resourceLocation = prefix + view + suffix;
        return resourceLoader.getResource(resourceLocation).exists();
    }
    return false;
}
 
Example 9
Source File: VcapServiceCredentialsEnvironmentPostProcessor.java    From spring-cloud-cloudfoundry with Apache License 2.0 4 votes vote down vote up
private String resolve(PropertyResolver resolver, String serviceId, String key) {
	return resolver.getProperty(
			String.format("vcap.services.%s.credentials.%s", serviceId, key), "");
}