ByteBuddy @Entity annotation not visible to Spring Boot ClassPathBeanDefinitionScanner basePackages scan

萝らか妹 提交于 2019-12-08 07:43:34

The "problem" is that Spring looks at the original classes and not at the loaded ones. Byte Buddy registers a Java agent that transforms classes when they are loaded but retains the original class files what Spring Boot does not recognize.

Another problem is that Spring investigates the jar file upon start up and before classes are loaded. This means that the Byte Buddy agent was not even active yet when Spring collects its entities.

Instead, Spring should investigate loaded classes as class loaders might not even provide class files but I assume they try to retain the class loading order what causes this outcome.

The only alternative would be to require Byte Buddy to rewrite any relevant jar file upon start up. You would need to parse any ressource on the class path and redefine the jars containing the file. On shutdown, you should reset the state by copying back the original jar state.

Ideally, Spring would add an option to scan by looking at loaded classes instead of parsing class files as both approaches have up and downsides. From my experience, looking at loaded classes is more performant anyways as it avoids the IO duplication so the option could benefit use cases beyond agent recognition.

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