spring mvc - always http error 404 : after useing swagger-codegen generat i can't use the rest service -
description when generate code swagger-codegen, got 3 problems .
first : error creating bean name 'documentationpluginsbootstrapper'
second:error creating bean name 'webmvcrequesthandlerprovider'
last one: org.springframework.http.invalidmediatypeexception: invalid mime type "json": not contain '/'
i google solutions , , remove annotation :@enablewebmvc , @enableswagger2 , there nothing wrong
then deploy project , , can't use .
the used url
:localhost:8002/basic/resources/api/tb-build
as expected, should have got json data , truth http error 404
swagger-codegen version
2.2.1
command line used generation
java -jar j:\swagger-codegen-cli-2.2.1.jar generate -i "c:\users\angelina\desktop\basic.json" -l spring --library spring-mvc -o server/basic/spring-mvc
some configuration: pom.xml:
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>io.swagger</groupid> <artifactid>swagger-spring</artifactid> <packaging>jar</packaging> <name>swagger-spring</name> <version>1.0.0</version> <build> <sourcedirectory>src/main/java</sourcedirectory> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.6</version> </plugin> <plugin> <artifactid>maven-failsafe-plugin</artifactid> <version>2.6</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> <plugin> <groupid>org.eclipse.jetty</groupid> <artifactid>jetty-maven-plugin</artifactid> <version>${jetty-version}</version> <configuration> <webappconfig> <contextpath>/basic</contextpath> </webappconfig> <webappsourcedirectory>target/${project.artifactid}-${project.version}</webappsourcedirectory> <stopport>8079</stopport> <stopkey>stopit</stopkey> <httpconnector> <port>8002</port> <idletimeout>60000</idletimeout> </httpconnector> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>start</goal> </goals> <configuration> <scanintervalseconds>0</scanintervalseconds> <daemon>true</daemon> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>${slf4j-version}</version> </dependency> <!--spring dependencies --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>${spring-version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${spring-version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>${spring-version}</version> </dependency> <!--springfox dependencies--> <dependency> <groupid>io.springfox</groupid> <artifactid>springfox-swagger2</artifactid> <version>${springfox-version}</version> </dependency> <dependency> <groupid>io.springfox</groupid> <artifactid>springfox-swagger-ui</artifactid> <version>${springfox-version}</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.datatype</groupid> <artifactid>jackson-datatype-joda</artifactid> <version>${jackson-version}</version> </dependency> <dependency> <groupid>joda-time</groupid> <artifactid>joda-time</artifactid> <version>2.9.4</version> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>${junit-version}</version> <scope>test</scope> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>${servlet-api-version}</version> </dependency> </dependencies> <properties> <java.version>1.7</java.version> <maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.target>${java.version}</maven.compiler.target> <jetty-version>9.2.15.v20160210</jetty-version> <slf4j-version>1.7.21</slf4j-version> <junit-version>4.12</junit-version> <servlet-api-version>2.5</servlet-api-version> <springfox-version>2.4.0</springfox-version> <jackson-version>2.4.5</jackson-version> <spring-version>4.2.5.release</spring-version> </properties> </project>
swaggeruiconfiguration:
package io.swagger.configuration; import org.springframework.context.annotation.componentscan; import org.springframework.context.annotation.configuration; import org.springframework.context.annotation.propertysource; import org.springframework.context.annotation.import; import org.springframework.web.servlet.config.annotation.enablewebmvc; import org.springframework.web.servlet.config.annotation.resourcehandlerregistry; import org.springframework.web.servlet.config.annotation.webmvcconfigureradapter; import springfox.documentation.swagger2.annotations.enableswagger2; @javax.annotation.generated(value = "class io.swagger.codegen.languages.springcodegen", date = "2017-08-20t12:34:41.309+08:00") @configuration @componentscan(basepackages = "io.swagger.api") @enablewebmvc @enableswagger2 //loads spring beans required framework @propertysource("classpath:swagger.properties") @import(swaggerdocumentationconfig.class) public class swaggeruiconfiguration extends webmvcconfigureradapter { private static final string[] servlet_resource_locations = { "/" }; private static final string[] classpath_resource_locations = { "classpath:/meta-inf/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" }; private static final string[] resource_locations; static { resource_locations = new string[classpath_resource_locations.length + servlet_resource_locations.length]; system.arraycopy(servlet_resource_locations, 0, resource_locations, 0, servlet_resource_locations.length); system.arraycopy(classpath_resource_locations, 0, resource_locations, servlet_resource_locations.length, classpath_resource_locations.length); } private static final string[] static_index_html_resources; static { static_index_html_resources = new string[resource_locations.length]; (int = 0; < static_index_html_resources.length; i++) { static_index_html_resources[i] = resource_locations[i] + "index.html"; } } @override public void addresourcehandlers(resourcehandlerregistry registry) { if (!registry.hasmappingforpattern("/webjars/**")) { registry.addresourcehandler("/webjars/**").addresourcelocations("classpath:/meta-inf/resources/webjars/"); } if (!registry.hasmappingforpattern("/**")) { registry.addresourcehandler("/**").addresourcelocations(resource_locations); } } }
Comments
Post a Comment