Search in sources :

Example 1 with ConfigurationPropertiesBindingPostProcessor

use of org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor in project spring-cloud-function by spring-cloud.

the class FunctionProxyApplicationListener method bind.

private void bind(ConfigurableApplicationContext context) {
    ConfigurationPropertiesBindingPostProcessor post = new ConfigurationPropertiesBindingPostProcessor();
    post.setBeanFactory(new DefaultListableBeanFactory());
    post.setEnvironment(context.getEnvironment());
    post.setApplicationContext(new StaticApplicationContext());
    try {
        post.afterPropertiesSet();
    } catch (Exception e) {
        throw new IllegalStateException("Cannot bind properties", e);
    }
    post.postProcessBeforeInitialization(this, getClass().getName());
}
Also used : ConfigurationPropertiesBindingPostProcessor(org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory)

Example 2 with ConfigurationPropertiesBindingPostProcessor

use of org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor in project cas by apereo.

the class CasConfigurationPropertiesEnvironmentManagerTests method verifyOperationByDir.

@Test
public void verifyOperationByDir() throws Exception {
    val env = new MockEnvironment();
    val dir = FileUtils.getTempDirectory();
    env.setProperty(CasConfigurationPropertiesEnvironmentManager.PROPERTY_CAS_STANDALONE_CONFIGURATION_DIRECTORY, dir.getCanonicalPath());
    val mgr = new CasConfigurationPropertiesEnvironmentManager(new ConfigurationPropertiesBindingPostProcessor());
    assertEquals(dir.getCanonicalPath(), mgr.getStandaloneProfileConfigurationDirectory(env).getCanonicalPath());
}
Also used : lombok.val(lombok.val) ConfigurationPropertiesBindingPostProcessor(org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ConfigurationPropertiesBindingPostProcessor

use of org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor in project cas by apereo.

the class CasConfigurationPropertiesEnvironmentManagerTests method verifyOperationByFile.

@Test
public void verifyOperationByFile() throws Exception {
    val env = new MockEnvironment();
    val file = File.createTempFile("cas", ".properties");
    FileUtils.writeStringToFile(file, "server.port=8899", StandardCharsets.UTF_8);
    env.setProperty(CasConfigurationPropertiesEnvironmentManager.PROPERTY_CAS_STANDALONE_CONFIGURATION_FILE, file.getCanonicalPath());
    val mgr = new CasConfigurationPropertiesEnvironmentManager(new ConfigurationPropertiesBindingPostProcessor());
    assertEquals(file.getCanonicalPath(), mgr.getStandaloneProfileConfigurationFile(env).getCanonicalPath());
}
Also used : lombok.val(lombok.val) ConfigurationPropertiesBindingPostProcessor(org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ConfigurationPropertiesBindingPostProcessor (org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor)3 lombok.val (lombok.val)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1