错误信息:
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());
}
}
}