Skip to content

Converter beans cannot be defined as lambdas #24413

Closed
@Hoysing

Description

@Hoysing
@Configuration
public class ConverterConfig {
    @Bean
    public Converter<String, LocalDate> localDateConverter() {
        return source -> LocalDate.parse(source, CommonConstants.DATE_FORMATTER);
//        return new Converter<String, LocalDate>() {
//            @Override
//            public LocalDate convert(String source) {
//                return LocalDate.parse(source, CommonConstants.DATE_FORMATTER);
//            }
//        };
    }
}

start app successfully when add converter without the lambda exp.otherwise,failed to start app and the following result will be outputted.
Can't spring boot infer the type from the lambda exp?

Caused by: java.lang.IllegalArgumentException: Unable to determine source type <S> and target type <T> for your Converter [org.hoysing.stress.converter.ConverterConfig$$Lambda$1601/1414642952]; does the class parameterize those types?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions