Search in sources :

Example 1 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class ServerPropertiesTests method testServerHeader.

@Test
public void testServerHeader() throws Exception {
    RelaxedDataBinder binder = new RelaxedDataBinder(this.properties, "server");
    binder.bind(new MutablePropertyValues(Collections.singletonMap("server.server-header", "Custom Server")));
    assertThat(this.properties.getServerHeader()).isEqualTo("Custom Server");
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 2 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class ServerPropertiesTests method testServletPathAsPrefix.

@Test
public void testServletPathAsPrefix() throws Exception {
    RelaxedDataBinder binder = new RelaxedDataBinder(this.properties, "server");
    binder.bind(new MutablePropertyValues(Collections.singletonMap("server.servlet.path", "/foo")));
    assertThat(binder.getBindingResult().hasErrors()).isFalse();
    assertThat(this.properties.getServlet().getServletMapping()).isEqualTo("/foo/*");
    assertThat(this.properties.getServlet().getServletPrefix()).isEqualTo("/foo");
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 3 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class ServerPropertiesTests method testSlashOfContextPathIsDefaultValue.

@Test
public void testSlashOfContextPathIsDefaultValue() {
    new RelaxedDataBinder(this.properties, "server").bind(new MutablePropertyValues(Collections.singletonMap("server.servlet.contextPath", "/")));
    assertThat(this.properties.getServlet().getContextPath()).isEqualTo("");
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 4 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project dubbo by alibaba.

the class RelaxedDubboConfigBinder method bind.

@Override
public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, boolean ignoreInvalidFields, Object configurationBean) {
    RelaxedDataBinder relaxedDataBinder = new RelaxedDataBinder(configurationBean);
    // Set ignored*
    relaxedDataBinder.setIgnoreInvalidFields(ignoreInvalidFields);
    relaxedDataBinder.setIgnoreUnknownFields(ignoreUnknownFields);
    // Get properties under specified prefix from PropertySources
    // Convert Map to MutablePropertyValues
    MutablePropertyValues propertyValues = new MutablePropertyValues(configurationProperties);
    // Bind
    relaxedDataBinder.bind(propertyValues);
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues)

Example 5 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class SpringProfileDocumentMatcher method extractSpringProfiles.

protected List<String> extractSpringProfiles(Properties properties) {
    SpringProperties springProperties = new SpringProperties();
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new PropertiesPropertySource("profiles", properties));
    PropertyValues propertyValues = new PropertySourcesPropertyValues(propertySources);
    new RelaxedDataBinder(springProperties, "spring").bind(propertyValues);
    List<String> profiles = springProperties.getProfiles();
    return profiles;
}
Also used : PropertySourcesPropertyValues(org.springframework.boot.bind.PropertySourcesPropertyValues) PropertyValues(org.springframework.beans.PropertyValues) PropertiesPropertySource(org.springframework.core.env.PropertiesPropertySource) RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertySources(org.springframework.core.env.MutablePropertySources) PropertySourcesPropertyValues(org.springframework.boot.bind.PropertySourcesPropertyValues)

Aggregations

RelaxedDataBinder (org.springframework.boot.bind.RelaxedDataBinder)12 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)10 Test (org.junit.Test)7 PropertySourcesPropertyValues (org.springframework.boot.bind.PropertySourcesPropertyValues)2 PropertyValues (org.springframework.beans.PropertyValues)1 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)1 MutablePropertySources (org.springframework.core.env.MutablePropertySources)1 PropertiesPropertySource (org.springframework.core.env.PropertiesPropertySource)1