how do I register a custom conversion Service in spring 3 / webflow 2?

Posted by nont on Stack Overflow See other posts from Stack Overflow or by nont
Published on 2010-06-15T15:08:52Z Indexed on 2010/06/15 15:12 UTC
Read the original article Hit count: 1024

Filed under:
|
|

I've been trying to follow this example and using the reference to guide me, but I'm having no luck.

I've defined a converter:

import org.springframework.binding.convert.converters.StringToObject;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

public class StringToDateTwoWayConverter  extends StringToObject {
    private DateFormat format = null;

    public StringToDateTwoWayConverter () {
        super(StringToDateTwoWayConverter.class);
        format = new SimpleDateFormat("MM/dd/yyyy");

    }

    @Override
    protected Object toObject(String string, Class targetClass) throws Exception {
        Date date = null;
        try {
            date = format.parse(string);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
        return date;
    }

    @Override
    protected String toString(Object object) throws Exception {
        Date date = (Date) object;
        return format.format(date);
    }
}

and a conversionService:

import org.springframework.binding.convert.service.DefaultConversionService;
import org.springframework.stereotype.Component;

@Component("conversionService")
public class ApplicationConversionService extends DefaultConversionService
{
    @Override
    protected void addDefaultConverters() {
        super.addDefaultConverters();        
        this.addConverter(new StringToDateTwoWayConverter());
        this.addConverter("shortDate", new StringToDateTwoWayConverter());

    }
}

and configured it:

<webflow:flow-builder-services id="flowBuilderServices" conversion-service="conversionService" .../>

However, upon startup, I'm greeted with this exception:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)': Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.core.convert.ConversionService]: Could not convert constructor argument value of type [com.yadayada.converter.ApplicationConversionService] to required type [org.springframework.core.convert.ConversionService]: Failed to convert value of type 'com.yadayada.converter.ApplicationConversionService' to required type 'org.springframework.core.convert.ConversionService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.yadayada.converter.ApplicationConversionService] to required type [org.springframework.core.convert.ConversionService]: no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:687)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:195)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:993)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:897)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
    ... 60 more

I'm thoroughly puzzled why its not working. The conversion service implements ConversionService through its base class, so I don't see the problem. Any insight much appreciated!

© Stack Overflow or respective owner

Related posts about java

Related posts about spring