Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未捕获Springfox Swagger配置和文档_Java_Spring Mvc_Tomcat7_Swagger Ui_Swagger 2.0 - Fatal编程技术网

Java 未捕获Springfox Swagger配置和文档

Java 未捕获Springfox Swagger配置和文档,java,spring-mvc,tomcat7,swagger-ui,swagger-2.0,Java,Spring Mvc,Tomcat7,Swagger Ui,Swagger 2.0,这是我第一次来这里。因此,我们在SpringMVC中构建了一个应用程序,该应用程序处理REST调用,使用2个java类作为控制器。其中一个用@Controller显式注释,另一个用@Component注释。(2种定义路线的方式略有不同) 我们面临的问题是,尽管我们进行了配置/设置,但我们只看到一个没有端点和文档的空UI。它基本上是一块空白画布。我们做了大量的搜索,尽管尝试了bean和定义的多种配置,但仍然遇到了相同的问题 最近,我们尝试了以下示例: 下面是我们的设置/配置和相关文件的一些片段 控

这是我第一次来这里。因此,我们在SpringMVC中构建了一个应用程序,该应用程序处理REST调用,使用2个java类作为控制器。其中一个用@Controller显式注释,另一个用@Component注释。(2种定义路线的方式略有不同)

我们面临的问题是,尽管我们进行了配置/设置,但我们只看到一个没有端点和文档的空UI。它基本上是一块空白画布。我们做了大量的搜索,尽管尝试了bean和定义的多种配置,但仍然遇到了相同的问题

最近,我们尝试了以下示例:

下面是我们的设置/配置和相关文件的一些片段

控制器类别:

UserDeviceAuthenticationController

@RestController
public class UserDeviceAuthenticationController {

private static final Logger LOGGER = Logger
        .getLogger(UserDeviceAuthenticationController.class);

/**
 * 
 * @param response
 * @param request
 * @param deviceID: a misnomer. This field is different for every client set up on Fitbit
 * @throws IOException
 * @throws ParseException
 */
@RequestMapping(value = "/fitbitEndPoint", method = RequestMethod.POST)
public void fitbitEndPoint(HttpServletResponse response,
      //Body logic redacted

}
PHDDeviceRestService

@Path("device/v2.0")
@Component
public class PHDDeviceRestService extends BaseServiceImpl {

    @POST
    @Path("/{deviceId}/url")
    @Produces({ MediaType.APPLICATION_JSON })
    @Consumes({ MediaType.APPLICATION_JSON })
    public Response getDeviceURL(GetDeviceURLRequest getDeviceURLRequest, @PathParam("deviceId") Long deviceId) throws PHDWebServiceException {
         //Logic redacted
    }
配置文件:

Pom.xml中的相关Swagger Springfox依赖项

<!-- Swagger dependency -->
<dependencies>
   <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>2.6.0</version>
   </dependency>
   <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>2.6.0</version>
   </dependency>
</dependencies>
带有ViewController和ResourceHandler的WebMvcConfig类:

@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addRedirectViewController("/documentation/v2/api-docs", "/v2/api-docs?group=restful-api");
    registry.addRedirectViewController("/documentation/swagger-resources/configuration/ui","/swagger-resources/configuration/ui");
    registry.addRedirectViewController("/documentation/swagger-resources/configuration/security","/swagger-resources/configuration/security");
    registry.addRedirectViewController("/documentation/swagger-resources", "/swagger-resources");
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("documentation/swagger-ui.html")
    .addResourceLocations("classpath:/META-INF/resources/");

    registry.addResourceHandler("documentation/webjars/**")
    .addResourceLocations("classpath:/META-INF/resources/webjars/");
}

}

谢谢你通读了所有这些。如果您还想查看我们的代码/文件,或者我遗漏了什么,请告诉我。欢迎您的任何意见

你可能已经找到了答案,但如果有人有同样的问题,这可能会帮助他们:

对我来说,诀窍是将包含我的
SwaggerConfig
的包添加到
ComponentScan basePackages
列表中。基本上我有相同的
SwaggerConfig
,但我的
应用程序
文件(我使用的是Spring boot)如下所示:

@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {
        "my.test.config",
        "my.test.controllers",
        "my.test.models"})
public class SwaggerTestApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SwaggerTestApplication.class, args);
    }
}

重要的部分是
组件扫描中的
“my.test.config”
包,其中定义了
SwaggerConfig

您可能已经找到了答案,但如果有人有同样的问题,这可能会帮助他们:

对我来说,诀窍是将包含我的
SwaggerConfig
的包添加到
ComponentScan basePackages
列表中。基本上我有相同的
SwaggerConfig
,但我的
应用程序
文件(我使用的是Spring boot)如下所示:

@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {
        "my.test.config",
        "my.test.controllers",
        "my.test.models"})
public class SwaggerTestApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SwaggerTestApplication.class, args);
    }
}

重要的部分是
组件扫描中的
“my.test.config”
包,其中定义了
SwaggerConfig

Hi tudor。谢谢你的建议。我们使用的是SpringMVC,而不是SpringBoot。无论如何,我们定义了一个web.xml文件,该文件指向webmvc-config.xml和applicationContext.xml文件。在这些文件中,已设置并定义了“”。基本包包含所有类和java文件,包括我已经定义的SwaggerConfig。例如,SwaggerConfig文件属于com.uhg.phd.Configuration,应该已经对其进行了包括在内的扫描。XML不像直接内联Java定义它们那样健壮吗?XML和用Java定义它们一样健壮——所以这不是问题所在。如果您还没有,您可能想在官方存储库中查看一下这个示例:并确保找到您的SwaggerConfig(从示例中):。。。这就是我现在能想到的。嗨,都铎。谢谢你的建议。我们使用的是SpringMVC,而不是SpringBoot。无论如何,我们定义了一个web.xml文件,该文件指向webmvc-config.xml和applicationContext.xml文件。在这些文件中,已设置并定义了“”。基本包包含所有类和java文件,包括我已经定义的SwaggerConfig。例如,SwaggerConfig文件属于com.uhg.phd.Configuration,应该已经对其进行了包括在内的扫描。XML不像直接内联Java定义它们那样健壮吗?XML和用Java定义它们一样健壮——所以这不是问题所在。如果您还没有,您可能想在官方存储库中查看一下这个示例:并确保找到您的SwaggerConfig(从示例中):。。。这就是我现在能想到的。
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {
        "my.test.config",
        "my.test.controllers",
        "my.test.models"})
public class SwaggerTestApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SwaggerTestApplication.class, args);
    }
}