springboot模块里面调用另外一个模块的方法实现
bug描述:
在一个springboot模块里面调用另外一个模块的方法
通过下面的代码可以看到,我的方法所在的模块是在com.bpmn.camunda.sync.provider里面,而我导入的包是在另外一个模块里面 com.bpmn.camunda.common.service 如果直接启动项目会报错。
package com.bpmn.camunda.sync.provider.server.impl;
import com.bpmn.camunda.common.service.IActHiCommentService;
@Service
public class CActIdUserServiceImpl extends AbstractSupperService<CActIdUserMapper, CActIdUserModel, CActIdUserDTO> implements CActIdUserService {
@Autowired
private IActHiCommentService iActHiCommentService;
项目背景:
普通的springclou项目。
解决方法:
我们应该在主方法里面加上包的扫描,springbooot会自动扫描到bean,并注入到Ioc容器里面。
一个是 加上componentScan 加上了 "com.bpmn.camunda.common.service"
@ComponentScan(basePackages = {"com.bpmn.camunda.auth","com.bpmn.camunda.sync","com.bpmn.camunda.common.service"})
@SpringBootApplication
@ComponentScan(basePackages = {"com.bpmn.camunda.auth","com.bpmn.camunda.sync","com.bpmn.camunda.common.service"})
@MapperScan({"com.bpmn.camunda.sync.provider.mapper","com.bpmn.camunda.common.mapper"})
@EnableDiscoveryClient
@EnableProcessApplication
@EnableFeignClients(basePackages = {"com.bpmn.camunda","com.focusin.bpmn"})
@EnableAopLog
public class BpmnCamundaSyncApplication {
public static void main(String[] args) {
SpringApplication.run(BpmnCamundaSyncApplication.class, args);
}
}
其实只加上了service方法还不够,因为service大概率会调用mapper方法,所以还需要加上mapper扫描。
@MapperScan({"com.bpmn.camunda.sync.provider.mapper","com.bpmn.camunda.common.mapper"})
总结:
添加其他模块的bean时,spring并不能直接扫描到该bean,需要我们手动设置扫描路径。
到此这篇关于springboot模块里面调用另外一个模块的方法实现的文章就介绍到这了,更多相关springboot模块调用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
关于SpringMVC中数据绑定@ModelAttribute注解的使用
这篇文章主要介绍了关于SpringMVC中数据绑定@ModelAttribute注解的使用,SpringMVC是一个基于Spring框架的Web框架,它提供了一种简单、灵活的方式来开发Web应用程序,在开发Web应用程序时,我们需要将用户提交的数据绑定到我们的Java对象上,需要的朋友可以参考下2023-07-07
基于Jenkins搭建.NET Core持续集成环境过程图解
这篇文章主要介绍了基于Jenkins搭建.NET Core持续集成环境过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2020-08-08
java中Executor,ExecutorService,ThreadPoolExecutor详解
这篇文章主要介绍了java中Executor,ExecutorService,ThreadPoolExecutor详解的相关资料,需要的朋友可以参考下2017-02-02
Springboot+mybatis plus找不到mapper.xml的问题解决
本文主要介绍了Springboot+mybatis plus找不到mapper.xml的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2023-05-05
Java concurrency线程池之Callable和Future_动力节点Java学院整理
这篇文章主要为大家详细介绍了Java concurrency线程池之Callable和Future,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-06-06


最新评论