swagger study notes 2 No operations defined in spec!

Problem phenomenon:

In the process of learning swagger today, I found a problem: the interface information cannot be displayed:

No operations defined in spec!


problem analysis:

The meaning of this message is: There is no operation defined in the specification (that is: no interface api is defined in the configuration ) !

There are many reasons for this problem:

1. The package path of the controller configured in the swagger configuration class is wrong (the most likely)

By looking at the package path of the configuration class, I found that there is no problem:

2. The swagger annotation configuration of the controller layer is incorrect

It is found that there is no problem with the controller layer configuration:

3. There is a problem with the annotation configuration of the startup class

The only suspicious thing about the startup class is this configuration:

@ComponentScan("com.stephen.shoporder.config")

So I removed it and revisited it and found that it was OK:

@EnableFeignClients//启动Fegin支持
@EnableDiscoveryClient//启动DiscoveryClient支持(用于服务注册和发现,可获取到注册中心的所有服务)
@EntityScan(basePackages = {"com.stephen.shopcommon"})
@SpringBootApplication
public class OrderApplication {

	public static void main(String[] args) {
		SpringApplication.run(OrderApplication.class, args);
	}
}

It can be seen that because of this annotation, the package path is specified, which causes the project to ignore the controller package path, which causes the api to be lost!


Solution:

@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);
	}
}

Remove the comment  @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);
	}
}

 

Guess you like

Origin blog.csdn.net/weixin_42585386/article/details/109353691