Close

Spring Boot - typeMismatch exception with banner-mode=off with yml property file.

The property spring.main.banner-mode=off doesn't work with YAML file (application.yml). It throws following exception (Spring boot version 1.5.4.RELEASE):

org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult ...... Failed to convert property value of type 'java.lang.Boolean' to required type 'org.springframework.boot.Banner$Mode'

The reason of above exception is; YAML treats 'off' value as boolean type, whereas Spring tries to convert it to the enum type Banner.Mode.

Example

src/main/resources/application.yml

spring:
    main:
     banner-mode: off
@SpringBootConfiguration
public class ExampleMain {

  public static void main(String[] args) throws InterruptedException {
      SpringApplication.run(ExampleMain.class, args);
  }
}
20:37:29.543 [main] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/charsets.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/deploy.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/access-bridge-64.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/cldrdata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/dnsns.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/jaccess.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/jfxrt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/localedata.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/nashorn.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunec.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunjce_provider.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunmscapi.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/sunpkcs11.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/ext/zipfs.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/javaws.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jce.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jfr.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jfxswt.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/jsse.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/management-agent.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/plugin.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/resources.jar, file:/C:/Program%20Files/Java/jdk1.8.0_65/jre/lib/rt.jar, file:/D:/LogicBig/example-projects/spring-boot/yaml-banner-off-exception/target/classes/, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot-starter/1.5.4.RELEASE/spring-boot-starter-1.5.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot/1.5.4.RELEASE/spring-boot-1.5.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-context/4.3.9.RELEASE/spring-context-4.3.9.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-aop/4.3.9.RELEASE/spring-aop-4.3.9.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-beans/4.3.9.RELEASE/spring-beans-4.3.9.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-expression/4.3.9.RELEASE/spring-expression-4.3.9.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.5.4.RELEASE/spring-boot-autoconfigure-1.5.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.5.4.RELEASE/spring-boot-starter-logging-1.5.4.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar, file:/C:/Users/Joe/.m2/repository/ch/qos/logback/logback-core/1.1.11/logback-core-1.1.11.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar, file:/C:/Users/Joe/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.jar, file:/C:/Users/Joe/.m2/repository/org/springframework/spring-core/4.3.9.RELEASE/spring-core-4.3.9.RELEASE.jar, file:/C:/Users/Joe/.m2/repository/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar, file:/C:/JetBrains/IntelliJ%20IDEA%20Community%20Edition%202016.3.4/lib/idea_rt.jar]
20:37:29.543 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: Cannot bind to SpringApplication
	at org.springframework.boot.context.config.ConfigFileApplicationListener.bindToSpringApplication(ConfigFileApplicationListener.java:233)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:186)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:171)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:157)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:296)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
	at com.logicbig.example.ExampleMain.main(ExampleMain.java:10)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.springframework.validation.BindException: org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanPropertyBindingResult: 1 errors
Field error in object 'spring.main' on field 'bannerMode': rejected value [false]; codes [typeMismatch.spring.main.bannerMode,typeMismatch.bannerMode,typeMismatch.org.springframework.boot.Banner$Mode,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.main.bannerMode,bannerMode]; arguments []; default message [bannerMode]]; default message [Failed to convert property value of type 'java.lang.Boolean' to required type 'org.springframework.boot.Banner$Mode' for property 'bannerMode'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.Boolean' to required type 'org.springframework.boot.Banner$Mode' for property 'bannerMode': no matching editors or conversion strategy found]
	at org.springframework.boot.bind.PropertiesConfigurationFactory.checkForBindingErrors(PropertiesConfigurationFactory.java:359)
	at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:276)
	at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:240)
	at org.springframework.boot.context.config.ConfigFileApplicationListener.bindToSpringApplication(ConfigFileApplicationListener.java:230)
	... 18 common frames omitted

Example Project

Dependencies and Technologies Used:

  • Spring Boot 1.5.4.RELEASE
    Corresponding Spring Version 4.3.9.RELEASE
  • spring-boot-starter : Core starter, including auto-configuration support, logging and YAML.
  • JDK 1.8
  • Maven 3.3.9

yaml-banner-off-exception Select All Download
  • yaml-banner-off-exception
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources
          • application.yml

    See Also