问题现象:
今天在学习swagger的过程中,发现了一个问题:接口信息无法显示:
No operations defined in spec!
问题分析:
这个信息的意思就是: 规范中没有定义操作(也就是:配置中没有定义接口api)!
出现这个问题的原因有很多:
1.swagger配置类中配置controller的包路径出错(可能性最大)
通过查看配置类的包路径,发现并没有问题:
2.controller层的swagger注解配置有误
发现controller层配置也没有问题:
3.启动类的注解配置有问题
启动类这里唯一可疑的就是这个配置:
@ComponentScan(“com.stephen.shoporder.config”)
于是我把它去掉再重新访问,发现可以了:
@EnableFeignClients//启动Fegin支持
@EnableDiscoveryClient//启动DiscoveryClient支持(用于服务注册和发现,可获取到注册中心的所有服务)
@EntityScan(basePackages = {"com.stephen.shopcommon"})
@SpringBootApplication
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
}
}
由此可见是因为这个注解,指定了包路径,导致项目忽略了controller包路径,从而导致api丢失!
解决方法:
@EnableFeignClients//启动Fegin支持
@EnableDiscoveryClient//启动DiscoveryClient支持(用于服务注册和发现,可获取到注册中心的所有服务)
@EntityScan(basePackages = {"com.stephen.shopcommon"})
@ComponentScan("com.stephen.shoporder.config")
@SpringBootApplication
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
}
}
将注解 @ComponentScan(“com.stephen.shoporder.config”) 去掉:
@EnableFeignClients//启动Fegin支持
@EnableDiscoveryClient//启动DiscoveryClient支持(用于服务注册和发现,可获取到注册中心的所有服务)
@EntityScan(basePackages = {"com.stephen.shopcommon"})
@SpringBootApplication
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
}
}
版权声明:本文为weixin_42585386原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。