1、目的
为了实现接口与实现分离,为服务system-server抽出了一个接口模块system-api
消费端调用服务时不必另外写接口,可统一由服务端打包,提供给消费端引用。
服务端
消费端
服务端api
2、问题
在消费端引入system-api后,消费端启动报错:
2020-03-03 15:57:23.341 ERROR [cloud-client,,,] 19740 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userService in com.spring.cloud.controller.ClientController required a bean of type 'com.rock.hhp.system.service.UserService' that could not be found.
Action:
Consider defining a bean of type 'com.rock.hhp.system.service.UserService' in your configuration.
3、解决方式
3.1、在消费端启动类上的@EnableFeignClients需要指定包
3.2、在服务端api添加ApiConfig.java
1、在resources下META-INF文件夹中,添加文件spring.factories,内容如下
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.rock.hhp.system.config.ApiConfig
2、添加ApiConfig类,代码如下:
/**
* @author Rock rockhhp@163.com
* @since 2020-03-03 15:40
*/
@EnableFeignClients({"com.rock.hhp.system.service"})
public class ApiConfig {
}
问题解决,以上