ComponentScan或EntityScan在另一个项目中无法找到实体。

huangapple go评论60阅读模式
英文:

ComponentScan or EntityScan don't find entities in another project

问题

我有一个 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 目录中删除这些项目但是我始终得到相同的错误作为截图附加[stacktrace][1]

  [1]: https://i.stack.imgur.com/6U712.jpg
英文:

I have spring boot project in which I import entities from my other spring boot project.

Dependence on a project with entities is as follows

    &lt;dependency&gt;
        &lt;groupId&gt;models&lt;/groupId&gt;
        &lt;artifactId&gt;models&lt;/artifactId&gt;
        &lt;version&gt;0.2&lt;/version&gt;
    &lt;/dependency&gt;

The main project is configured as follows

@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
@ComponentScan(basePackages = &quot;model.entity&quot;)
public class SecurityService {
    public static void main(String[] args) {
        run(SecurityService.class, args);
    }
}

I've tried using @ComponentScan and @EntityScan. I tried to delete these projects from the .m2 directory but I always get the same error (attach as screeshoot) stacktrace

答案1

得分: 1

这是我的错误,我忘记添加

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
英文:

it is my mistake, I forgot add

&lt;dependency&gt;
		&lt;groupId&gt;mysql&lt;/groupId&gt;
		&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
	&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年9月21日 23:32:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63995453.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定