ComponentScan 或 EntityScan 在另一个项目中找不到实体
Posted
技术标签:
【中文标题】ComponentScan 或 EntityScan 在另一个项目中找不到实体【英文标题】:ComponentScan or EntityScan don't find entities in another project 【发布时间】:2021-01-07 17:40:18 【问题描述】:我有一个 spring boot 项目,我从我的其他 spring boot 项目中导入实体。
对一个有实体的项目的依赖如下
<dependency>
<groupId>models</groupId>
<artifactId>models</artifactId>
<version>0.2</version>
</dependency>
主工程配置如下
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
@ComponentScan(basePackages = "model.entity")
public class SecurityService
public static void main(String[] args)
run(SecurityService.class, args);
我尝试过使用@ComponentScan 和@EntityScan。我试图从 .m2 目录中删除这些项目,但我总是得到相同的错误(附加为 screeshoot)stacktrace
【问题讨论】:
也许你必须从依赖项中指定包名 【参考方案1】:是我的错,我忘了加
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
【讨论】:
以上是关于ComponentScan 或 EntityScan 在另一个项目中找不到实体的主要内容,如果未能解决你的问题,请参考以下文章
-002-@ComponentScan@Autowired的用法