我已经写了这段代码:
@Configuration
@Slf4j
public class Config
{
@Autowired
private List<CustomEditor<?>> editors;
@PostConstruct
private void postConstructor()
{
log.debug("postConstructor: editors={}", editors);
for (CustomEditor<?> editor : editors)
PropertyEditorManager.registerEditor(editor.returnedClass(), editor.getClass());
}
}
和
public abstract class CustomEditor<T> implements PropertyEditor
{
protected T value;
public Class<?> returnedClass()
{
ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
return (Class<?>) type.getActualTypeArguments()[0];
}
它很好的工作,但我想改进我的代码,我不想实现我的对象因为注册只要求上课。
有没有用春天这样做?