美文网首页
SpringBoot 引用其他模块的@Component or

SpringBoot 引用其他模块的@Component or

作者: 火星移民局局长 | 来源:发表于2020-09-02 11:15 被阅读0次

Module 01:

@Component

class TokenUtils{

}

Module 02:

1,maven 依赖module 01

2,在使用TokenUtils的地方@Autowired 注解 启用会提示找不到TokenUtils

3,在启用类上添加注解@ComponentScan注入依赖的包路径;此时启动成功,但所有接口路径访问失败

原因:

@ComponentScan会将@SpringBootApplication所默认注入的包路径替换掉,导致找不到对应的Controller;

解决:

@ComponentScan将启动类所在的包路径也注入进去;

SpringBoot 引用其他模块的@Component or @Service

相关文章

网友评论

      本文标题:SpringBoot 引用其他模块的@Component or

      本文链接:https://www.haomeiwen.com/subject/qlxrcctx.html