超全模态模型 × Harness 升级,升级解锁 ArkClaw,最新支持 DeepSeek-V4 系列与 GLM-5.1
我的application.yml配置如下:
application.yml
payment-routing-config: drivers: - id: 'ANETC' weight: 80 backups: ['EPAYC', 'NMIC', 'ANETD'] - id: 'EPAYC' weight: 80 backups: ['ANETC', 'NMIC', 'ANETD'] - id: 'NMI' weight: 80 backups: ['EPAYC', 'ANETC', 'ANETD']
对应的Java代码:
@ConfigurationProperties("paymentRoutingConfig") public record PaymentRoutingConfig( List<PaymentDriver> drivers ) { } record PaymentDriver( String id, int weight, List<String> backups ) { }
使用@Inject注入时,drivers属性为空列表;但将List<PaymentDriver>改为List<Object>后,配置能正确填充:
@Inject
drivers
List<PaymentDriver>
List<Object>
PaymentRoutingConfig[drivers=[{id=ANETC, weight=80, backups=[EPAYC, NMIC, ANETD]}, {id=EPAYC, weight=80, backups=[ANETC, NMIC, ANETD]}, {id=NMI, weight=80, backups=[EPAYC, ANETC, ANETD]}]]
注入方式:
@Inject PaymentRoutingConfig paymentRoutingConfig;
我疑惑@ConfigurationProperties是否不支持复杂对象,于是做了简化测试。
@ConfigurationProperties
修改后的Java代码:
@ConfigurationProperties("paymentRoutingConfig") public record PaymentRoutingConfig( PaymentDriver driver ) { } record PaymentDriver( String id, int weight ) { }
对应的yaml配置:
payment-routing-config: driver: id: 'test' weight: 10
此时出现注入错误:
Message: Failed to inject value for parameter [driver] of class: com.***.paymentservice.infrastructure.PaymentRoutingConfig Message: Error resolving property value [payment-routing-config.driver]. Property doesn't exist Path Taken: new PaymentController() --> PaymentController.paymentRoutingConfig --> new PaymentRoutingConfig([PaymentDriver driver]) Path Taken: new PaymentController() --> PaymentController.paymentRoutingConfig --> new PaymentRoutingConfig([PaymentDriver driver]) io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [driver] of class: com.***.paymentservice.infrastructure.PaymentRoutingConfig
请求解决该配置加载异常问题。
Micronaut的@ConfigurationProperties绑定复杂嵌套对象时,需要确保嵌套实体类(如PaymentDriver)具备可访问性,且配置绑定机制能正确识别其属性。另外部分旧版本Micronaut对Java Record的嵌套绑定支持存在兼容性问题。
PaymentDriver
确保嵌套Record的访问权限 将内部的PaymentDriver改为public修饰,或单独定义为顶级类(独立.java文件)。默认嵌套Record为包私有,Micronaut配置绑定机制无法访问其构造器与属性。
public
.java
修改后代码示例:
@ConfigurationProperties("paymentRoutingConfig") public record PaymentRoutingConfig( List<PaymentDriver> drivers ) { } // 改为public顶级Record public record PaymentDriver( String id, int weight, List<String> backups ) { }
补充必要依赖(旧版本Micronaut) 若你的Micronaut版本低于3.2.x,需引入micronaut-validation依赖,它是复杂对象配置绑定的必要组件:
micronaut-validation
// Gradle示例 implementation("io.micronaut.validation:micronaut-validation")
Maven配置:
<dependency> <groupId>io.micronaut.validation</groupId> <artifactId>micronaut-validation</artifactId> </dependency>
简化场景的修复 单个对象场景同样需要确保PaymentDriver为public:
@ConfigurationProperties("paymentRoutingConfig") public record PaymentRoutingConfig( PaymentDriver driver ) { } public record PaymentDriver( String id, int weight ) { }
配置文件无需修改即可正常绑定。
PaymentRoutingConfig
@PackageScan
内容的提问来源于stack exchange,提问作者testing123
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起
模型再升级,30秒超长叙事, 模态参考扩容
模型自由,工具不限,最新支持 Deepseek-V4 系列、GLM-5.3 系列
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列
大模型19元起,Al应用9.9元畅享,新人首购爆款尽享优惠