springboot 同一个工程下不同模块之间的类相互调用
出现了这个问题,
import成功了,但是方法用不了。
包的依赖已经引用了
这是A模块的pom,xml
<parent>
<groupId>com.tdt</groupId>
<artifactId>ads-modulars</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<version>1.0.0</version>
<artifactId>ads-modulars-sys</artifactId>
<packaging>jar</packaging>
这是B 模块的pom.xml
<dependency>
<groupId>com.tdt</groupId>
<artifactId>ads-modulars-sys</artifactId>
<version>1.0.0</version>
</dependency>
请问是什么原因?
是怎么调用不了呢,方法不能打印出来?还是执行的时候报错?
包名的问题吧,扫不到B的包
如A的启动类在a.b.c.d下
B你需要的类在a.b.c.e.service下,这样是扫不到B的那个类的,默认只扫描a.b.c.d下的类,注入到spring
@SpringBootApplication(scanBasePackages = {"a.b.c.d","a.b.c.e"})
如果前面的包和我说的一样,可以直接这样
@SpringBootApplication(scanBasePackages = {"a.b.c"})
把对应的包路径交给spring管理就可以了
两个模块的groupId必须都是com.tdt
说明你没把 UserService 装配到容器中
B模块install下
这种提示可以不用管,或者加上 @SuppressWarnings注解
直接丢个项目git地址出来,大家帮你改就好了
把你B模块的父工程引入