Search in sources :

Example 1 with RelaxedBindingNotWritablePropertyException

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

the class ConfigurationPropertiesBindingPostProcessorTests method unknownFieldFailureMessageContainsDetailsOfPropertyOrigin.

@Test
public void unknownFieldFailureMessageContainsDetailsOfPropertyOrigin() {
    this.context = new AnnotationConfigApplicationContext();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "com.example.baz=spam");
    this.context.register(TestConfiguration.class);
    try {
        this.context.refresh();
        fail("Expected exception");
    } catch (BeanCreationException ex) {
        RelaxedBindingNotWritablePropertyException bex = (RelaxedBindingNotWritablePropertyException) ex.getRootCause();
        assertThat(bex.getMessage()).startsWith("Failed to bind 'com.example.baz' from '" + TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME + "' to 'baz' " + "property on '" + TestConfiguration.class.getName());
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RelaxedBindingNotWritablePropertyException(org.springframework.boot.bind.RelaxedBindingNotWritablePropertyException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 RelaxedBindingNotWritablePropertyException (org.springframework.boot.bind.RelaxedBindingNotWritablePropertyException)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1