elunez / eladmin

eladmin jpa 版本:项目基于 Spring Boot 2.6.4、 Jpa、 Spring Security、Redis、Vue的前后端分离的后台管理系统,项目采用分模块开发方式, 权限控制采用 RBAC,支持数据字典与数据权限管理,支持一键生成前后端代码,支持动态路由
https://eladmin.vip/demo
Apache License 2.0
21.04k stars 7.33k forks source link

求助,生成一个新包,提示找不到XxxRepository #536

Closed esinhee closed 3 years ago

esinhee commented 3 years ago

用代码生成器生成一个新的模块,使用新包路径,运行的时候提示找不到XxxRepository。 确认AppRun里已经加了@ComponentScan(basePackages = {"me.zhengjie.","com.itam."}) 依然提示一下的错误,请教是什么原因,谢谢。 `*** APPLICATION FAILED TO START


Description:

Parameter 0 of constructor in com.itam.company.service.impl.XxxServiceImpl required a bean of type 'com.itam.company.repository.XxxRepository' that could not be found.

Action:

Consider defining a bean of type 'com.itam.company.repository.XxxRepository' in your configuration.`

nbwgl commented 3 years ago

同样的问题,不知道怎么解决,已经加了包扫描。 代码生成完之后没有加@Repository注解,我手工添加后也一样,还是说没有找到bean

nbwgl commented 3 years ago

@ComponentScan: 会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Controller,@Configuration等

@EntityScan:  会自动扫描指定包下的全部标有@Entity的类

@EnableJpaRepositories: 会自动扫描指定包下的全部标有@Repository的类

elunez commented 3 years ago

使用这种方式 @ComponentScan({"me.zhengjie.","com.demo."})

https://www.cnblogs.com/powerwu/articles/12091969.html

chaohui2 commented 3 years ago

找到 AppRun.java 类定义处加上三个注解,可以解决这个问题。

@ComponentScan(basePackages ={"me.zhengjie","com.xxxxxxx"})
@EnableJpaRepositories({"com.xxxxxxx.**.repository","me.zhengjie.**.repository"})
@EntityScan({"com.xxxxxxx.*","me.zhengjie.*"})
Evi5 commented 3 years ago

找到 AppRun.java 类定义处加上三个注解,可以解决这个问题。

@ComponentScan(basePackages ={"me.zhengjie","com.xxxxxxx"})
@EnableJpaRepositories({"com.xxxxxxx.**.repository","me.zhengjie.**.repository"})
@EntityScan({"com.xxxxxxx.*","me.zhengjie.*"})

亲测有效!