要在自定义对象上使用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
?
(Class<List<Customer>>) new ArrayList<Customer>().getClass();