web-dev-qa-db-ja.com

springfox-swagger-uiをSpring MVCで動作させることができません

私は数日を探して解決策を見つけることができませんでした、ほとんどの例はスプリングブーツとグラドルを扱っていますが、私はスプリングmvcとmavenのみを使用しています。

Springfox-swagger-ui依存関係を削除すると、アプリは正常に実行され、次のようにJSONが期待どおりに返されますhttp:\\ localhost:8080\restful\v2\api-docs?group = restful-api

何らかの理由で、私の春のアプリケーションはswagger-ui.htmlを渡すことができず、index.htmlを設定すると同じ応答を返します

私は追加しようとしました:

  1. Web.xmlのウェルカムリストファイル
  2. リソースハンドラー
  3. デフォルトのサーブレット処理

動作しませんでした。

アプリ構成

package au.com.speak.restful.spring;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import     org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "au.com.speak.restful.api" })
public class AppConfig extends WebMvcConfigurerAdapter {

    // ========= Overrides ===========

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LocaleChangeInterceptor());
    }

    // ========= Beans ===========

    @Bean(name = "localeResolver")
    public LocaleResolver getLocaleResolver() {
        return new CookieLocaleResolver();
    }

    @Bean(name = "messageSource")
    public MessageSource getMessageSources() {
        ReloadableResourceBundleMessageSource messageSource = new     ReloadableResourceBundleMessageSource();
        messageSource.setBasenames("/WEB-INF/resources/properties/error", "/WEB-INF/resources/properties/validation");
        messageSource.setCacheSeconds(0);

        return messageSource;
    }
}

Swagger Config

package au.com.speak.restful.spring;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig  {

    @Bean
    public Docket restfulApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("restful-api")
                .select()
                .build()
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {

        ApiInfo apiInfo = new ApiInfo(
                "My Apps API Title",
                "My Apps API Description",
                "My Apps API Version",
                "My Apps API terms of service",
                "My Apps API Contact Email",
                "My Apps API Licence Type",
                "My Apps API License URL"
        );
        return apiInfo;
    }
}

私が持っているコードは次のとおりです。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://Java.Sun.com/xml/ns/javaee"     xsi:schemaLocation="http://Java.Sun.com/xml/ns/javaee     http://Java.Sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

    <display-name>example restful api</display-name>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <listener>
        <listener-class>
            org.springframework.security.web.session.HttpSessionEventPublisher
        </listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>                    org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            au.com.speak.restful.spring.AppConfig
            au.com.speak.restful.spring.PropertyConfig
            au.com.speak.restful.spring.SecurityConfig
            au.com.speak.restful.spring.ServiceConfig
            au.com.speak.restful.spring.PersistenceConfig
            au.com.speak.restful.spring.SwaggerConfig
        </param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.xml</param-value>
    </context-param>

    <!--
        Reads request input using UTF-8 encoding
    -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--
        Apply Spring Security Filter to all Requests
     -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--
        Handles all requests into the application
    -->
    <servlet>
        <servlet-name>model</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>*</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>model</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

エラー

2015-04-27 23:03:47,805 INFO   - Loading XML bean definitions from ServletContext resource [/swagger-ui.html]
2015-04-27 23:03:47,811 ERROR  - Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 2 in XML document from ServletContext resource [/swagger-ui.html] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 7;  Element type "html" must be declared.
at   org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.Java:399)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.Java:336)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.Java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.Java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.Java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.Java:188)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.Java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.Java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.Java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.Java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:452)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.Java:663)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:629)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.Java:677)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.Java:548)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.Java:489)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.Java:136)
at javax.servlet.GenericServlet.init(GenericServlet.Java:158)
at  org.Apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.Java:1231)
at org.Apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.Java:1144)
at org.Apache.catalina.core.StandardWrapper.load(StandardWrapper.Java:1031)
at org.Apache.catalina.core.StandardContext.loadOnStartup(StandardContext.Java:4913)
at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5200)
at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
at org.Apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.Java:725)
at org.Apache.catalina.core.ContainerBase.addChild(ContainerBase.Java:701)
at org.Apache.catalina.core.StandardHost.addChild(StandardHost.Java:717)
at org.Apache.catalina.startup.HostConfig.manageApp(HostConfig.Java:1618)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:483)
at org.Apache.Tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.Java:300)
at com.Sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.Java:819)
at com.Sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.Java:801)
at org.Apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.Java:463)
at org.Apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.Java:413)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:483)
at org.Apache.Tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.Java:300)
at com.Sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.Java:819)
at com.Sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.Java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.Java:1466)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.Java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.Java:1307)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.Java:1399)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.Java:828)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:483)
at Sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.Java:323)
at Sun.rmi.transport.Transport$1.run(Transport.Java:200)
at Sun.rmi.transport.Transport$1.run(Transport.Java:197)
at Java.security.AccessController.doPrivileged(Native Method)
at Sun.rmi.transport.Transport.serviceCall(Transport.Java:196)
at Sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.Java:568)
at Sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.Java:826)
at Sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$240(TCPTransport.Java:683)
at Sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/1746485750.run(Unknown Source)
at Java.security.AccessController.doPrivileged(Native Method)
at Sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.Java:682)
at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1142)
at     Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:617)
at Java.lang.Thread.run(Thread.Java:745)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 7;     Element type "html" must be declared.
at com.Sun.org.Apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.Java:203)
at com.Sun.org.Apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.Java:134)
at com.Sun.org.Apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.Java:437)
at com.Sun.org.Apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.Java:368)
at com.Sun.org.Apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.Java:325)
at com.Sun.org.Apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.Java:1906)
at com.Sun.org.Apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.Java:742)
at com.Sun.org.Apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.Java:1363)
at com.Sun.org.Apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.Java:1292)
at com.Sun.org.Apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.Java:3138)
at com.Sun.org.Apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.Java:880)
at com.Sun.org.Apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.Java:606)
at com.Sun.org.Apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.Java:510)
at com.Sun.org.Apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.Java:848)
at com.Sun.org.Apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.Java:777)
at com.Sun.org.Apache.xerces.internal.parsers.XMLParser.parse(XMLParser.Java:141)
at com.Sun.org.Apache.xerces.internal.parsers.DOMParser.parse(DOMParser.Java:243)
at com.Sun.org.Apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.Java:348)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.Java:76)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.Java:429)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.Java:391)
... 66 more
13
Robert Leggett

以下をAppConfigに追加して修正しました。

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
        .addResourceHandler("swagger-ui.html")
        .addResourceLocations("classpath:/META-INF/resources/");
    registry
        .addResourceHandler("/webjars/**")
        .addResourceLocations("classpath:/META-INF/resources/webjars/");
}
19
Robert Leggett

springfox-swagger2springfox-swagger-uiのバージョンが一致しないため、このエラーが発生しました。2つの依存関係のバージョンは同じでなければなりません。

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.6.1</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.6.1</version>
</dependency>
7
Searene

Swaggerの新しいバージョンがどれほど違うかはわかりませんが、バージョン1.0.2を使用しています。また、swagger-spring-mvc-ui-0.4.jarを使用して、swagger API jspファイルとcssを取得しています。

Maven依存関係

    <dependency>
        <groupId>com.mangofactory</groupId>
        <artifactId>swagger-springmvc</artifactId>
        <version>1.0.2</version>
    </dependency>

Spring MVC 4.1.5とともに使用しています。以下は、swagger api jsonファイルを生成するために使用している唯一のファイルです。

SwaggerConfig.Java

import static org.ajar.swaggermvcui.SwaggerSpringMvcUi.WEB_JAR_RESOURCE_LOCATION;
import static org.ajar.swaggermvcui.SwaggerSpringMvcUi.WEB_JAR_RESOURCE_PATTERNS;
import static org.ajar.swaggermvcui.SwaggerSpringMvcUi.WEB_JAR_VIEW_RESOLVER_PREFIX;
import static org.ajar.swaggermvcui.SwaggerSpringMvcUi.WEB_JAR_VIEW_RESOLVER_SUFFIX;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
import com.mangofactory.swagger.models.dto.ApiInfo;
import com.mangofactory.swagger.plugin.EnableSwagger;
import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;

@EnableSwagger
public class SwaggerConfig extends WebMvcConfigurerAdapter {
    private SpringSwaggerConfig springSwaggerConfig;

    @Autowired
    public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
        this.springSwaggerConfig = springSwaggerConfig;
    }

    @Bean
    public SwaggerSpringMvcPlugin customImplementation() {
        this.springSwaggerConfig.defaultSwaggerPathProvider()
                .setApiResourcePrefix("api");
        return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
                .apiInfo(apiInfo());// .includePatterns(".*swagger.*");
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo("My APIs",
                "RESTful APIs available under My Portal", "#",
                "[email protected]", "License Information", "#");
        return apiInfo;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(WEB_JAR_RESOURCE_PATTERNS)
                .addResourceLocations(WEB_JAR_RESOURCE_LOCATION)
                .setCachePeriod(0);
    }

    @Bean
    public InternalResourceViewResolver getInternalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix(WEB_JAR_VIEW_RESOLVER_PREFIX);
        resolver.setSuffix(WEB_JAR_VIEW_RESOLVER_SUFFIX);
        return resolver;
    }

    @Override
    public void configureDefaultServletHandling(
            DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}

マイレストコントローラー

@RestController
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public class CommonUtilityServices {

    @Autowired
    private CommonUtilityService commonUtilityService;

    @ApiOperation(value = "Is Unique", notes = "This service checks if a value is already present in DB or not.<br>Below is the sample JSON object. <br> <pre><code class=\"json\">{<span class=\"attribute\"><span class=\"attribute\">\"dbField\"</span></span> : <span class=\"value\"><span class=\"string\"><span class=\"value\"><span class=\"string\">\"organization.name\"</span></span></span></span>, <span class=\"attribute\"><span class=\"attribute\">\"fieldValue\" : <span class=\"value\"><span class=\"string\"><span class=\"value\"><span class=\"string\">\"novopay\"</span></span></span></span>}</code></pre><br>'dbField' accepts value 'tableDB.DBField' format.<br>'fieldValue' is the value needs to be check for uniqueness.")
    @ApiResponses(value = {
            @ApiResponse(code = 202, message = "Request Accepted"),
            @ApiResponse(code = 400, message = "Bad Request") })
    @RequestMapping(value = "/isUnique", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody ResponseEntity<Boolean> isUnique(
            HttpServletRequest request, @RequestBody String jsonStr) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            Map<?, ?> myMap = mapper.readValue(jsonStr.toString(),
                    HashMap.class);
            String dbField = (String) myMap.get("dbField");
            String fieldValue = (String) myMap.get("fieldValue");
            String whereClause = (String) myMap.get("whereClause");
            return new ResponseEntity<Boolean>(
                    commonUtilityService
                            .isValueAlreadyInDB(dbField, fieldValue, whereClause),
                    HttpStatus.ACCEPTED);
        } catch (IOException | RuntimeException e) {
            return new ResponseEntity<Boolean>(HttpStatus.BAD_REQUEST);
        }
    }}

上記のすべての変更とは別に、sdoc.jspのローカルコピーをswagger-spring-mvc-ui-0.4.jarで使用できるようにし、デフォルトで指すURLを変更しました。

<script type="text/javascript">
$(function() {
    window.swaggerUi = new SwaggerUi({
        url: "/portal/api/api-docs", //New URL
        dom_id: "swagger-ui-container",
        supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
        onComplete: function(swaggerApi, swaggerUi) {
            log("Loaded SwaggerUI");

Web.xmlファイルに変更がなく、SwaggerConfigクラスがspring annotations/component-scanを使用してロードされることに注意してください

2

質問の著者はSpring Bootを使用していませんが、他の人を助けるためにここに投稿することにしました。 Spring SecurityとSpring Bootを使用するSpring 5.0.0.M5の場合、pom.xmlにこれらの2つの依存関係を追加することで機能しました。

 <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.6.1</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.6.1</version>
</dependency>

次に、SpringBootAppクラスにswaggerアノテーションと対応するBeanを追加しました。

@SpringBootApplication
@EnableSwagger2
public class SpringBootApp extends WebMvcConfigurerAdapter {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }

    [...]
}

その後、アプリのルートでAPIドキュメントが利用可能になります。このルートは/: http:// localhost:8080/swagger-ui.html です。

この方法を使用すると、ここで説明するような個別のSwaggerConfigも必要ありません。 http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

1