Closed esinhee closed 3 years ago
同样的问题,不知道怎么解决,已经加了包扫描。 代码生成完之后没有加@Repository注解,我手工添加后也一样,还是说没有找到bean
@ComponentScan: 会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Controller,@Configuration等
@EntityScan: 会自动扫描指定包下的全部标有@Entity的类
@EnableJpaRepositories: 会自动扫描指定包下的全部标有@Repository的类
使用这种方式 @ComponentScan({"me.zhengjie.","com.demo."})
找到 AppRun.java 类定义处加上三个注解,可以解决这个问题。
@ComponentScan(basePackages ={"me.zhengjie","com.xxxxxxx"})
@EnableJpaRepositories({"com.xxxxxxx.**.repository","me.zhengjie.**.repository"})
@EntityScan({"com.xxxxxxx.*","me.zhengjie.*"})
找到 AppRun.java 类定义处加上三个注解,可以解决这个问题。
@ComponentScan(basePackages ={"me.zhengjie","com.xxxxxxx"}) @EnableJpaRepositories({"com.xxxxxxx.**.repository","me.zhengjie.**.repository"}) @EntityScan({"com.xxxxxxx.*","me.zhengjie.*"})
亲测有效!
用代码生成器生成一个新的模块,使用新包路径,运行的时候提示找不到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.`