无法绑定属性
Could not bind properties
我已经将 Spring Boot 从版本 1.5.6 更新到 2.0.0,并且开始出现很多问题。一是题目中给出的问题。
我有一个 class 属性
@Data
@ConfigurationProperties("eclipseLink")
public class EclipseLinkProperties { ... }
我在配置中使用的
@Configuration
@EnableConfigurationProperties(EclipseLinkProperties.class)
public class WebDatasourceConfig { ... }
编译的时候,他把我扔了
2018-03-18 18:44:58.560 INFO 3528 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.context.properties.ConversionServiceDeducer$Factory' of type [org.springframework.boot.context.properties.ConversionServiceDeducer$Factory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-18 18:44:58.575 WARN 3528 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webDatasourceConfig': Unsatisfied dependency expressed through field 'eclipseLinkProperties'; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'eclipseLink-com.web.web.config.properties.EclipseLinkProperties': Could not bind properties to 'EclipseLinkProperties' : prefix=eclipseLink, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'eclipseLink' is not valid
意思是
Configuration property name 'eclipseLink' is not valid
在 Spring 引导更新之前一切正常。
eclipseLink
不是有效的前缀。因为应该使用 described in the documentation kebab-case 而不是驼峰式。所以你的前缀应该是 eclipse-link
而不是 eclipseLink
.
Spring boot 2.0 不支持驼峰式大小写。它会抛出 InvalidConfigurationPropertyNameException: Configuration 属性 name '********' is not valid.
当一个 .yml 文件中的新配置未添加到所有 .yml 文件中时遇到此问题(test.yml 具体而言)
您可以更改:
@ConfigurationProperties("eclipseLink")
至:
@ConfigurationProperties("eclipselink")
您不需要更改属性文件。这样可以避免错误。 Spring 将能够找到 eclipseLink.* 属性。
我已经将 Spring Boot 从版本 1.5.6 更新到 2.0.0,并且开始出现很多问题。一是题目中给出的问题。 我有一个 class 属性
@Data
@ConfigurationProperties("eclipseLink")
public class EclipseLinkProperties { ... }
我在配置中使用的
@Configuration
@EnableConfigurationProperties(EclipseLinkProperties.class)
public class WebDatasourceConfig { ... }
编译的时候,他把我扔了
2018-03-18 18:44:58.560 INFO 3528 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.context.properties.ConversionServiceDeducer$Factory' of type [org.springframework.boot.context.properties.ConversionServiceDeducer$Factory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-18 18:44:58.575 WARN 3528 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webDatasourceConfig': Unsatisfied dependency expressed through field 'eclipseLinkProperties'; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'eclipseLink-com.web.web.config.properties.EclipseLinkProperties': Could not bind properties to 'EclipseLinkProperties' : prefix=eclipseLink, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'eclipseLink' is not valid
意思是
Configuration property name 'eclipseLink' is not valid
在 Spring 引导更新之前一切正常。
eclipseLink
不是有效的前缀。因为应该使用 described in the documentation kebab-case 而不是驼峰式。所以你的前缀应该是 eclipse-link
而不是 eclipseLink
.
Spring boot 2.0 不支持驼峰式大小写。它会抛出 InvalidConfigurationPropertyNameException: Configuration 属性 name '********' is not valid.
当一个 .yml 文件中的新配置未添加到所有 .yml 文件中时遇到此问题(test.yml 具体而言)
您可以更改:
@ConfigurationProperties("eclipseLink")
至:
@ConfigurationProperties("eclipselink")
您不需要更改属性文件。这样可以避免错误。 Spring 将能够找到 eclipseLink.* 属性。