Spring Data DomainClassConverter not working (in combination with Java Config)

前端 未结 2 1302
深忆病人
深忆病人 2021-02-10 23:48

I\'m trying to setup the Spring Data/JPA DomainClassConverter to automatically convert (String) id\'s to the domain classes itself.

My project is uses Java Config (so no

相关标签:
2条回答
  • 2021-02-10 23:53

    DomainClassConverter should be declared as a bean (because it's ApplicationContextAware), and it registers itself in ConversionService automatically, so that you don't need to register it manually:

    @Bean @Autowired
    public DomainClassConverter domainClassConverter(ConversionService cs) {
        return new DomainClassConverter(cs);
    }
    
    0 讨论(0)
  • 2021-02-11 00:17

    The exception is telling you that you need a custom converter to turn a String into a Customer. You'll have to tokenize the input and map it into Customer fields. That's true for all your domain classes.

    A Google search also lead me to a thread in the Spring forum:

    http://forum.springsource.org/showthread.php?122944-Help-with-DomainClassConverter-configuration

    It suggests that there might be a bug, depending on which version of Spring you're using.

    0 讨论(0)
提交回复
热议问题