无法运行Swagger-SpringMVC(WAS)

时间:2016-04-07 21:30:37

标签: java spring spring-mvc swagger swagger-ui

我无法让Swagger-SpringMVC使用以下配置。你可以检查并告知我缺少什么。

@RestController
public class MarketingProfileRestService {

    private static final String SPECIFIC = GENERAL + "/{id}";

    @Autowired
    private RestClient restClient;  

    @RequestMapping(value = SPECIFIC, method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody   
    public ResponseEntity<Profile> getProfile(
            @PathVariable("id") String id) {        
        System.out.println("Id is : " + id);
        Profile profile = restClient.getProfile(id); 
        return new ResponseEntity<Profile>(profile, HttpStatus.OK);
    }

}

@Configuration
@EnableSwagger
@EnableWebMvc
public class SwaggerConfig {

    private SpringSwaggerConfig springSwaggerConfig;

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

    @Bean
    public SwaggerSpringMvcPlugin customImplementation(){

        return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
                .apiInfo(apiInfo())
                .includePatterns("/.*"); // assuming the API lives at something like http://myapp/api
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo(
                "My Project's REST API",
                "This is a description of your API.",
                "API TOS",
                "me@wherever.com",
                "API License",
                "API License URL"
        );
        return apiInfo;
    }
}


<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">


    <context:component-scan base-package="com.abc.marketingprofileservice" />


    <mvc:annotation-driven />



</beans>

compile group: 'com.mangofactory', name:'swagger-springmvc', version:'0.8.8'

当我打开http://localhost:9080/MarketingProfileService/rest/api-docs时,我看到的只是

此XML文件似乎没有与之关联的任何样式信息。文档树如下所示。

我确实看到日志中的映射是正确的

[4/7/16 16:12:14:155 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/profiles/{id}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<com.nm.marketingprofileservice.model.Profile> com.nm.marketingprofileservice.service.rest.MarketingProfileRestService.getProfile(java.lang.String)
[4/7/16 16:12:14:155 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/profiles],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.Collection<com.nm.marketingprofileservice.model.Profile>> com.nm.marketingprofileservice.service.rest.MarketingProfileRestService.getPersons()
[4/7/16 16:12:14:155 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/api-docs],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.wordnik.swagger.model.ResourceListing> com.mangofactory.swagger.controllers.DefaultSwaggerController.getResourceListing(java.lang.String)
[4/7/16 16:12:14:155 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/api-docs/{swaggerGroup}/{apiDeclaration}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.wordnik.swagger.model.ApiListing> com.mangofactory.swagger.controllers.DefaultSwaggerController.getApiListing(java.lang.String,java.lang.String)
[4/7/16 16:12:14:171 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/profiles/{id}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<com.nm.marketingprofileservice.model.Profile> com.nm.marketingprofileservice.service.rest.MarketingProfileRestService.getProfile(java.lang.String)
[4/7/16 16:12:14:171 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/profiles],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.Collection<com.nm.marketingprofileservice.model.Profile>> com.nm.marketingprofileservice.service.rest.MarketingProfileRestService.getPersons()
[4/7/16 16:12:14:171 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/api-docs],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.wordnik.swagger.model.ResourceListing> com.mangofactory.swagger.controllers.DefaultSwaggerController.getResourceListing(java.lang.String)
[4/7/16 16:12:14:171 CDT] 0000007e RequestMappin I org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry register Mapped "{[/api-docs/{swaggerGroup}/{apiDeclaration}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.wordnik.swagger.model.ApiListing> com.mangofactory.swagger.controllers.DefaultSwaggerController.getApiListing(java.lang.String,java.lang.String)
[4/7/16 16:12:14:251 CDT] 0000007e RequestMappin I org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache Looking for @ControllerAdvice: WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Thu Apr 07 16:12:13 CDT 2016]; parent: Root WebApplicationContext

我错过了什么。 BTW这是在java 1.6下运行,因为我们的WAS服务器在1.6下运行。不幸的是我们目前无法升级java版本。我在网上搜索了很多,但是找不到一个完整的例子来设置招摇。

0 个答案:

没有答案