springboot项目报错---在a.impl中使用b.Impl

错误信息:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
11:14:43.841 ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter 42 report - 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'com.xxx.xxx.api.system.service.ThingService' that could not be found.


Action:

Consider defining a bean of type 'com.xxx.xxx.api.system.service.ThingService' in your configuration.


Process finished with exit code 0

原因:

1. 背景---一个a.Impl里,引用另一个b.Impl中的方法,方法写错

在建类自动生成时,少写@Resource   忘记继承 implements ThingService       @Override

a.Impl写法:

用法:thingService.updateThing(url, thingRequest, "");//调用改方法

public class DeviceServiceImpl implements DeviceService {

    @Resource
    ThingService thingService; //声明引用的service

    /**
     * 新增一条设备信息
     *
     * @param request
     * @return
     */
    @Override
    public String add(DeviceAddRequest request) {
        //若模板为空,只存数据库,不存模型
        if (StrKit.isEmpty(request.getTemplateid())) {
            return addToDatabase(request,"");
        }else{//若模板不为空,先存模型,后存数据库
            //先调模型,将设备名称,模板id存入模型
            ThingAddRequest thingRequest = new ThingAddRequest();
            thingRequest.setName(request.getDevicename());
            thingRequest.setThingTemplateId(request.getTemplateid());
            String resultsId = thingService.updateThing(url, thingRequest, "");//调用改方法
            //存数据库
            return addToDatabase(request,resultsId);
        }
    }

b.Impl写法:

@Service
public class ThingServiceImpl implements ThingService {
    /**
     * 新建thing
     * @param targetUrl 请求地址
     * @param requestObj 请求参数,新增thing数组
     * @return 操作结果,查看results属性,返回的String[]是新增节点的uri
     * "results": ["a01e8e76-9d5e-435d-8c9e-8fd14f5e75ca"]
     */
    @Override
    public String updateThing(String targetUrl , ThingAddRequest requestObj, String token){
        String requestStr = JSON.toJSONString(requestObj);
        String url = targetUrl + "/thing" ;
        try {
            String responseStr =  HttpHelper.post(url, requestStr, token);
            JSONObject responseJson = (JSONObject) JSON.parse(responseStr);
            if (responseJson.getString("statuscode").equals("-1")){
                throw new CustomException(responseJson.getString("message"));
            }
            return responseJson.getString("results");
        } catch (RuntimeException e){
            throw new CustomException(e.getMessage());
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值