Spring Data/JPA DomainClassConverter をセットアップして、(文字列) ID をドメイン クラス自体に自動的に変換しようとしています。
私のプロジェクトはJava Configを使用しています(したがってxmlはありません)。
私の WebConfig には、現在次のものがあります。
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new DomainClassConverter<DefaultFormattingConversionService>((DefaultFormattingConversionService) registry));
}
}
これを印刷すると、変換サービス内で見ることができるため、これは DomainClassConverter を正常に接続しているようです。
ConversionService converters =
..<default converters>..
org.springframework.data.repository.support.DomainClassConverter@6ea4ce0d, org.springframework.core.convert.support.IdToEntityConverter@5d3f03b, org.springframework.core.convert.support.ObjectToObjectConverter@1d40b47a
しかし、ネストされたフォーム (Order with Customer ref) を送信すると、Customer は自動的に変換されないため、次のようになります。
Failed to convert property value of type java.lang.String to required type org.mycomp.domain.Customer for property customer; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.mycomp.domain.Customer] for property customer: no matching editors or conversion strategy found
ここで何か間違ったことをしているのだろうか?