无法绑定属性

ryt*_*ytr 6 java spring spring-mvc eclipselink spring-boot

我已经将Spring Boot从版本1.5.6更新到2.0.0,并且已经开始出现很多问题.一个是主题中给出的问题.我有一个属性的类

@Data
@ConfigurationProperties("eclipseLink")
public class EclipseLinkProperties { ... }
Run Code Online (Sandbox Code Playgroud)

我在配置中使用它

@Configuration
@EnableConfigurationProperties(EclipseLinkProperties.class)
public class WebDatasourceConfig { ... }
Run Code Online (Sandbox Code Playgroud)

在编辑过程中,他把我扔了

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
Run Code Online (Sandbox Code Playgroud)

它的意思是

Configuration property name 'eclipseLink' is not valid
Run Code Online (Sandbox Code Playgroud)

在Spring Boot更新之前,一切正常.

And*_*son 14

eclipseLink不是有效的前缀.如文档中所述,应该使用kebab-case而不是camelCase.所以你的前缀应该是eclipse-link而不是eclipseLink.


小智 6

你可以改变:

@ConfigurationProperties("eclipseLink")
Run Code Online (Sandbox Code Playgroud)

到:

@ConfigurationProperties("eclipselink")
Run Code Online (Sandbox Code Playgroud)

您不需要更改属性文件。这样可以避免错误。Spring 将能够找到 eclipseLink.* 属性。