Why is Spring Data MongoDB unable to instantiate this nested type structure?

风格不统一 提交于 2019-12-03 05:57:18

This seems to be an issue with doubly nested inner classes and the synthetically generated constructors created by the compiler. I could reproduce that issue locally and see if we can provide a fix. In the meantime you have two options:

  1. Turn the inner class into static ones as this will remove the synthetic constructors and instantiation will work correctly.
  2. Nest the type declarations in the same way you nest the properties. I.e. move the ParamData class into the Group class, DataConfig into Config as that will cause the synthetic constructors created in a way they match instantiation order Spring Data currently relies on.

I'd suggest the former approach as it doesn't artificially bind the classes to instances of the outer class.

Failed to instantiate ... using constructor public ... ReflectionEntityInstantiator

says it cannot create the objects using reflection.

Do you have getters and setters for all the fields in all your classes? Your code above does not have them for ParamData, Config and DataConfig.

Also, if you happen to have non-default constructors in any of your classes make sure you have an empty argument constructor, else reflection will fail.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!