1、多个bean,即提示spring注入了多个bean,要添加@Primary或者@Qualifier
产生原因:
(1)启动类中使用了注解@ComponentScan(basePackages = {"cn.emd.platform.*"}),可能是多个模块之间都是相同包名,扫描了全部
解决方法:添加具体一点的包名,比如再加一层@ComponentScan(basePackages = {"cn.emd.platform.code.*"})
2、注入或者找不到文件
(1)如果是service等一些java文件中找不到,启动类中要添加@ComponentScan,最好两个模块之间扫描的基础包都要加上
(2)如果是mapper类文件找不到,要在mapper上面添加注解@Mapper,如果还是找不到,则要在启动类中添加@MapperScan(basePackages = {"cn.emd.admin.commonapi.mapper"})
3、引入另一个模块,不能存在相同的名称,不同包下面也不行,否则报错
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'fastDFSUtil' for bean class [cn.emd.platform.codegen.util.FastDFSUtil] conflicts with existing, non-compatible bean definition of same name and class [cn.emd.admin.commonapi.util.FastDFSUtil]
原因:有两个相同的文件,应该是springboot启动时添加了注解后都保存在一个map key/value中,所以在@RestController@Component或者@Repository等上加上限定就可以解决了
解决办法,修改文件不同名称
4、访问接口时报404错误,接口路径没有错
使用postman测试时
添加上@ComponentScan(basePackages = {"cn.emd.platform.code.*"})
其实以上产出的错误主要解决方法就是添加上
@MapperScan(basePackages = {"cn.emd.admin.commonapi.mapper"})
@ComponentScan(basePackages = {"cn.emd.admin.commonapi.*","cn.emd.platform.codegen.*"})
这两个注解在启动类中