Spring @Value属性用于自定义对象列表

问题描述 投票:1回答:1

要在自定义对象上使用Spring注释@Value,我们可以使用扩展了PropertyEditorSupport的自定义处理程序,并将其放入CustomEditorConfigurer中,这在Spring @Value property for custom class中进行了描述。

但是,我找不到在[[自定义对象列表上使用@Value的方法。

例如,我想这样做:

@Value("${data.customer}") private List<Customer> customers;

首先,我必须创建一个自定义处理程序:

public class CustomerListEditor extends PropertyEditorSupport { // implements getAsText() and setAsText() }

之后,我必须将List<Customer>映射到CustomerListEditor中的CustomEditorConfigurer。但是,表达式List<Customer>.class不是有效的Java语法。

如何正确将List<Customer>映射到CustomerListEditor中的CustomEditorConfigurer

java spring spring-annotations
1个回答
0
投票
您需要执行以下操作:

(Class<List<Customer>>) new ArrayList<Customer>().getClass();

© www.soinside.com 2019 - 2024. All rights reserved.