sách gpt4 ăn đã đi

java - Spring Webflow 绑定(bind) : Converter - java. lang.IllegalArgumentException : Each converter object must implement one of the Converter . .. 接口(interface)

In lại 作者:搜寻专家 更新时间:2023-10-31 20:22:42 32 4
mua khóa gpt4 giày nike

我在 Spring 的 XML 配置文件之一中有以下代码:

  










但我在部署期间(在 JBoss 上)遇到以下异常:

java.lang.IllegalArgumentException: Each converter object must implement one of the Converter, ConverterFactory, or GenericConverter interfaces

知道为什么吗?据我所知,org.springframework.binding.convert.converters.StringToDateĐúng Converter 的实现。

更新:

刚找到cái này答案,这表明混合使用 ConverterPropertyEditor 可能会导致问题。我的应用程序中确实有一部分使用了 PropertyEditor,但据我所知,该文档并未讨论混合使用这两个系统的任何问题。

堆栈跟踪:

Caused by: java.lang.IllegalArgumentException: Each converter object must implement one of the Converter, ConverterFactory, or GenericConverter interfaces
at org.springframework.core.convert.support.ConversionServiceFactory.registerConverters(ConversionServiceFactory.java:106)
at org.springframework.context.support.ConversionServiceFactoryBean.afterPropertiesSet(ConversionServiceFactoryBean.java:56)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 146 more

Cập nhật 2:

我将 xml 更改为:

  











我的自定义转换器是:

package my.project;

nhập java.util.Date;

import org.springframework.core.convert.converter.Converter;

public class StringToDate extends org.springframework.binding.convert.converters.StringToDate implements Converter {

public Date convert(String source) {

Date date = null;

thử {
date = (Date) convertSourceToTargetClass(getPattern(), getTargetClass());
} catch (Ngoại lệ e) {

}

return date;
}

}

但是,阅读 the following forum thread我希望转换能够工作。如果我没弄错,他们会说一旦转换器设置正确,它就应该与 Spring Batch 一起工作,即它不需要任何特殊设置即可使其专门与 Spring Batch 一起工作。但是我在批处理任务期间仍然收到 BindException ......知道为什么吗?

查看新的堆栈跟踪:

Caused by: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'target' on field 'datetimeInactive': rejected value [2011-04-27]; codes [typeMismatch.target.datetimeInactive,typeMismatch.datetimeInactive,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [target.datetimeInactive,datetimeInactive]; arguments []; default message [datetimeInactive]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'datetimeInactive'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'datetimeInactive': no matching editors or conversion strategy found]
Field error in object 'target' on field 'datetimeActive': rejected value [2011-04-27]; codes [typeMismatch.target.datetimeActive,typeMismatch.datetimeActive,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [target.datetimeActive,datetimeActive]; arguments []; default message [datetimeActive]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'datetimeActive'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'datetimeActive': no matching editors or conversion strategy found]
at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.mapFieldSet(BeanWrapperFieldSetMapper.java:186)
at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:42)
at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:179)
... 45 more

另见我的 original question (仍未解决)。

câu trả lời hay nhất

您确定应该使用 org.springframework.context.support.ConversionServiceFactoryBean 吗?这是一个 spring-core 定义的类。它需要以下内容:

org.springframework.core.convert.converter.GenericConverter
org.springframework.core.convert.converter.Converter
org.springframework.core.convert.converter.ConverterFactory

你正试图给它发送一个

org.springframework.binding.convert.converters.Converter

一个是spring-core,另一个是spring-webflow转换器。您可能想尝试自己创建一个@Service

@Service("conversionService")
public class MyConversionService extends DefaultConversionService {

public void ConversionService() {
addDefaultConverters();
}

@Ghi đè
protected void addDefaultConverters() {
super.addDefaultConverters();
}

}

关于java - Spring Webflow 绑定(bind) : Converter - java. lang.IllegalArgumentException : Each converter object must implement one of the Converter . .. 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9070982/

32 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress