Microservice startup error: java.lang.IllegalArgumentException: Not a managed type: class com.xxx.xxx.model.User

Problem phenomenon:

Today, after building a microservice architecture project, when starting a microservice, I encountered the following error:

java.lang.IllegalArgumentException: Not a managed type: class com.xxx.xxx.model.xxx


problem analysis:

According to the error message, this is because an entity class under the model could not be found , that is to say, no matching directory path was found!

This is because in the microservice architecture, the current microservice will go down the current path to match this path:

This is my dao interface:

When inheriting jpa, you need to pass in the entity class, and this entity class is placed in another microservice, so when the path is specified, it is found that it cannot be found under the current microservice, so it needs to be in the startup class. Specify the package path of the entity class (e.g.:

@EntityScan(basePackages={"com.stephen.shopcommon"})

), after the configuration, it will go to the entire project to match this path, so the entity class path of the corresponding microservice can be found.


Solution:

Add the @EntityScan annotation to the current startup class, and configure the microservice path referenced by the entity class in the basePackages property:

Successful startup:

Guess you like

Origin blog.csdn.net/weixin_42585386/article/details/109201668