gpt4 book ai didi

spring-boot - Spring Boot YAML 绑定(bind) : Failed to bind properties

转载 作者:行者123 更新时间:2023-12-04 16:04:09 24 4
gpt4 key购买 nike

我正在尝试绑定(bind) generator.yaml带有 GeneratorConfig 类型对象的文件使用 Spring Boot 2.0.5.RELEASE:

生成器.yaml:

entry:
name: "node-1"
expectedState: HEALTHY
@Component
@PropertySource("classpath:generator.yaml")
@ConfigurationProperties
public class GeneratorConfig {
private Entry entry;

// getter and setter
}
public class Entry {

private String name;
private NodeState expectedState;

// getters and setters
}

我得到以下异常:
2018-12-11 13:11:53.885  INFO 3923 --- [           main] com.project.mmgenerator.MMGenerator     : Starting MMGenerator on madmin’s-MacBook-Pro with PID 3923 (/Users/jscherman/IdeaProjects/sentinel/mock-metrics-generator/out/production/classes started by jscherman in /Users/jscherman/IdeaProjects/sentinel)
2018-12-11 13:11:53.889 DEBUG 3923 --- [ main] com.project.mmgenerator.MMGenerator : Running with Spring Boot v2.0.5.RELEASE, Spring v5.0.9.RELEASE
2018-12-11 13:11:53.890 INFO 3923 --- [ main] com.project.mmgenerator.MMGenerator : No active profile set, falling back to default profiles: default
2018-12-11 13:11:53.934 INFO 3923 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3eb91815: startup date [Tue Dec 11 13:11:53 ART 2018]; root of context hierarchy
2018-12-11 13:11:55.292 INFO 3923 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
2018-12-11 13:11:55.314 INFO 3923 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-12-11 13:11:55.314 INFO 3923 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
2018-12-11 13:11:55.318 INFO 3923 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/jscherman/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-12-11 13:11:55.403 INFO 3923 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-12-11 13:11:55.403 INFO 3923 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1471 ms
2018-12-11 13:11:56.209 INFO 3923 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-12-11 13:11:56.210 INFO 3923 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-12-11 13:11:56.210 INFO 3923 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-12-11 13:11:56.210 INFO 3923 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-12-11 13:11:56.210 INFO 3923 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-12-11 13:11:56.210 INFO 3923 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2018-12-11 13:11:56.210 INFO 3923 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-12-11 13:11:56.317 INFO 3923 --- [ main] c.m.s.metric.InfluxDBMetricsConnector : Setting InfluxDB connector with database name sentinel_db
2018-12-11 13:11:56.345 INFO 3923 --- [ main] c.m.mmgenerator.adapter.AdapterService : Building adapter service (sentinel-url=http://localhost:8080/, mmgenerator-url=http://localhost:8081/)
2018-12-11 13:11:56.431 WARN 3923 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'generatorEntriesController' defined in file [/Users/jscherman/IdeaProjects/sentinel/mock-metrics-generator/out/production/classes/com/project/mmgenerator/entry/GeneratorEntriesController.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'generatorConfig': Could not bind properties to 'GeneratorConfig' : prefix=, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'entry' to com.project.mmgenerator.input.Entry
2018-12-11 13:11:56.433 INFO 3923 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-12-11 13:11:56.447 INFO 3923 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-11 13:11:56.451 ERROR 3923 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'entry' to com.project.mmgenerator.input.Entry:

Property: entry
Value:
Origin: "entry" from property source "class path resource [generator.yaml]"
Reason: No converter found capable of converting from type [java.lang.String] to type [com.project.mmgenerator.input.Entry]

Action:

Update your application's configuration

有谁知道发生了什么?任何帮助,将不胜感激。

最佳答案

尝试从 'name:' 的值中删除双引号 ("),Spring 会自动将其绑定(bind)为字符串,您无需将其指定为“字符串”

关于spring-boot - Spring Boot YAML 绑定(bind) : Failed to bind properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53728337/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com