简体   繁体   English

Spring Webflow绑定:Converter - java.lang.IllegalArgumentException:每个转换器对象必须实现一个Converter ...接口

[英]Spring Webflow binding: Converter - java.lang.IllegalArgumentException: Each converter object must implement one of the Converter … interfaces

I have the following code in one of the Spring's XML config files: 我在Spring的XML配置文件之一中有以下代码:

  <mvc:annotation-driven conversion-service="conversionService" />

  <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="org.springframework.binding.convert.converters.StringToDate">
                <property name="pattern" value="yyyy-MM-dd" />            
            </bean>
        </list>
    </property>
  </bean>

But I am getting the following exception during deployment (on JBoss): 但是我在部署期间遇到了以下异常(在JBoss上):

java.lang.IllegalArgumentException: Each converter object must implement one of the Converter, ConverterFactory, or GenericConverter interfaces java.lang.IllegalArgumentException:每个转换器对象必须实现Converter,ConverterFactory或GenericConverter接口之一

Any idea why? 知道为什么吗? As far as I can see, org.springframework.binding.convert.converters.StringToDate is an implementation of Converter . 据我所知, org.springframework.binding.convert.converters.StringToDateConverter一个实现。

UPDATE: 更新:

Just found this answer, that suggests that mixing Converter s and PropertyEditor s might cause problems. 刚刚找到这个答案,这表明混合ConverterPropertyEditor可能会导致问题。 I do have part in my app that use PropertyEditor s, but as far as I can see, the documentation does not talk about any problem with mixing the two systems. 我确实参与了使用PropertyEditor的应用程序,但据我所知,文档没有讨论混合这两个系统的任何问题。

Stack trace: 堆栈跟踪:

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

UPDATE 2: 更新2:

I changed my xml to be: 我改变了我的xml:

  <mvc:annotation-driven conversion-service="conversionService" />

  <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <set>
            <bean class="my.project.StringToDate">
                <!-- org.springframework.binding.convert.converters.StringToDate DEFAULT_PATTERN = "yyyy-MM-dd" -->
                <property name="pattern" value="yyyy-MM-dd" />
            </bean>
        </set>
    </property>
  </bean>

My custom converter is: 我的自定义转换器是:

package my.project;

import java.util.Date;

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

public class StringToDate extends org.springframework.binding.convert.converters.StringToDate implements Converter<String, Date> {

    public Date convert(String source) {

        Date date = null;

        try {
            date = (Date) convertSourceToTargetClass(getPattern(), getTargetClass());
        } catch (Exception e) {

        }

        return date;
    }

}

HOWEVER, reading the following forum thread I would expect the conversion to work. 但是,阅读以下论坛帖子我希望转换能够正常工作。 If I get them right, they are saying that once the converter is set correctly, it should be working with Spring Batch, ie it does not require any special setting to make it work specifically with Spring Batch. 如果我说得对,他们说一旦转换器设置正确,就应该使用Spring Batch,即它不需要任何特殊设置就可以使它专门用于Spring Batch。 But I am still getting a BindException during the batch task... any idea why? 但是我在批处理任务期间仍然遇到BindException ...任何想法为什么?

See the new stack trace: 查看新堆栈跟踪:

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

See also my original question (still unsolved). 另见我原来的问题 (仍未解决)。

Are you sure you should be using the org.springframework.context.support.ConversionServiceFactoryBean ? 您确定要使用org.springframework.context.support.ConversionServiceFactoryBean吗? This is a spring-core defined class. 这是一个Spring-core定义的类。 It expects the following: 它预计如下:

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

You are trying to send it a 你正试图发送它

org.springframework.binding.convert.converters.Converter

One is a spring-core, the other is a spring-webflow converter. 一个是弹簧芯,另一个是弹簧网流转换器。 You may want to try and create a @Service yourself 您可能想尝试自己创建一个@Service

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

    public void ConversionService() {
        addDefaultConverters();
    }

    @Override
    protected void addDefaultConverters() {
        super.addDefaultConverters();
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalArgumentException:找不到类型返回值的转换器 - java.lang.IllegalArgumentException: No converter found for return value of type 转换器类抛出异常java.lang.IllegalArgumentException - Converter class throwing exception java.lang.IllegalArgumentException java.lang.IllegalArgumentException:未找到类型为java.util.HashMap的返回值的转换器 - java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.HashMap java.lang.IllegalArgumentException:未找到类型为java.util.ArrayList的返回值的转换器 - java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList Spring Converter复杂对象 - Spring Converter Complex Object 如何在java中实现单元转换器 - How to implement a unit converter in java java.lang.IllegalArgumentException:参数绑定的名称不得为 null 或空 - java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty Spring Data &amp; mongodb 转换器错误:java.lang.StackOverflowError - Spring Data & mongodb Converter error: java.lang.StackOverflowError java8聚合对象转换器 - java8 aggregate object converter Spring 启动 java.lang.IllegalArgumentException: URL 必须以 'jdbc' 开头 - Spring Boot java.lang.IllegalArgumentException: URL must start with 'jdbc'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM