1. Search Spring Showcase
You can find this article http://spring.io/blog/2010/07/22/spring-mvc-3-showcase
is to teach you how to use spring MVC
2. Go to GitHub to download the source code
3. The next task is to integrate the swagger in
--------------------------------------------------------------------------
1. Enter HTTPS://GITHUB.COM/SPRINGFOX/SPRINGFOX/BLOB/V1.0.2/README.MD follow one step at a
2. Join the dependency
<Dependency> <groupId>Com.mangofactory</groupId> <Artifactid>Swagger-springmvc</Artifactid> <version>1.0.1</version></Dependency>
Read here to find also less bag, meaning is swagger-springmvc in 0.9.5 version of the time to remove all of Scala's dependencies, also need spring 3.2.X or above, need to Jackson 2.4.4 or above, need to guava 15.0 or more.
Notable Dependencies
As of v0.9.5 all dependencies on Scala has been removed.
Spring 3.2.x or above
Jackson 2.4.4
Guava 15.0
<Dependency> <groupId>Com.fasterxml.jackson.core</groupId> <Artifactid>Jackson-databind</Artifactid> <version>2.4.4</version> </Dependency> <Dependency> <groupId>Com.google.guava</groupId> <Artifactid>Guava</Artifactid> <version>15.0</version> </Dependency>
The Spring Web package is then found missing and then introduced
<Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-web</Artifactid> <version>${org.springframework-version}</version> </Dependency>
All the required packages are introduced here.
3. Then follow the configuration to run the process, found a problem
June 03, 2016 6:41:05 pm org.apache.catalina.core.StandardContext loadonstartup severity: servlet/spring-mvc-showcase threw load () exceptionjava.lang.IllegalArgumentException:Conflicting Setter definitions for property "content": Org.jdom2.element#setcontent (1 params) vs Org.jdom2.element#setcontent (1 params) at Com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getSetter (pojopropertybuilder.java:293) at Com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getMutator (pojopropertybuilder.java:376) at Com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getPrimaryMember (pojopropertybuilder.java:398) at Com.mangofactory.swagger.models.property.field.FieldModelPropertyProvider.propertiesForDeserialization ( FIELDMODELPROPERTYPROVIDER.JAVA:85) at Com.mangofactory.swagger.models.property.provider.DefaultModelPropertiesProvider.propertiesForDeserialization ( defaultmodelpropertiesprovider.java:43) at Com.mangofactory.swagger.models.ModelDependencyProvider.propertiesFor (Modeldependencyprovider.java:121) at Com.mangofactory.swagger.models.ModelDependencyProvider.resolvedPropertiesAndFields ( modeldependencyprovider.java:94) at Com.mangofactory.swagger.models.ModelDependencyProvider.resolvedDependencies (modeldependencyprovider.java:75) at Com.mangofactory.swagger.models.ModelDependencyProvider.resolvedPropertiesAndFields ( modeldependencyprovider.java:108) at Com.mangofactory.swagger.models.ModelDependencyProvider.resolvedDependencies (modeldependencyprovider.java:75) At Com.mangofactory.swagger.models.ModelDependencyProvider.dependentModels (modeldependencyprovider.java:37) at Com.mangofactory.swagger.models.DefaultModelProvider.dependencies (defaultmodelprovider.java:82) at Com.mangofactory.swagger.readers.ApiModelReader.populateDependencies (apimodelreader.java:215) at Com.mangofactory.swagger.readers.ApiModelReader.readParametersApiModel (apimodelreader.java:205) at Com.mangofactory.swagger.readers.ApiModelReader.execute (apimodelreader.java:82) at Com.mangofactory.swagger.readerS.apimodelreader.execute (apimodelreader.java:39) at Com.mangofactory.swagger.core.CommandExecutor.execute ( COMMANDEXECUTOR.JAVA:13) at Com.mangofactory.swagger.scanners.ApiListingScanner.scan (apilistingscanner.java:100) At Com.mangofactory.swagger.core.SwaggerApiResourceListing.initialize (swaggerapiresourcelisting.java:72) at Com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin.initialize (swaggerspringmvcplugin.java:427) at Com.mangofactory.swagger.plugin.SwaggerPluginAdapter.onApplicationEvent (swaggerpluginadapter.java:51) at Com.mangofactory.swagger.plugin.SwaggerPluginAdapter.onApplicationEvent (swaggerpluginadapter.java:21) at Org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener ( simpleapplicationeventmulticaster.java:163) at Org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent ( simpleapplicationeventmulticaster.java:136) at Org.springframework.context.support.AbstractApplicationContext.publishEvent (abstractapplicationcontext.java:380) at Org.springframework.context.support.AbstractApplicationContext.publishEvent ( abstractapplicationcontext.java:334) at Org.springframework.context.support.AbstractApplicationContext.finishRefresh (Abstractapplicationcontext.java : 851) at Org.springframework.context.support.AbstractApplicationContext.refresh (Abstractapplicationcontext.java : 540) at Org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext ( frameworkservlet.java:667) at Org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext ( frameworkservlet.java:633) at Org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext ( frameworkservlet.java:681) at Org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext ( frameworkservlet.java:552) at Org.springframework.web.servlet.FrameworkServlet.initServletBean ( frameworkservlet.java:493) at Org.springframework.web.servlet.HttpServletBean.init (httpservletbean.java:136) at Javax.servlet.GenericServlet.init (Genericservlet.java:160) at Org.apache.catalina.core.StandardWrapper.initServlet (standardwrapper.java:1266) at Org.apache.catalina.core.StandardWrapper.loadServlet (standardwrapper.java:1185) at Org.apache.catalina.core.StandardWrapper.load (standardwrapper.java:1080) at Org.apache.catalina.core.StandardContext.loadOnStartup (standardcontext.java:5027) at Org.apache.catalina.core.StandardContext.startInternal (standardcontext.java:5314) at Org.apache.catalina.util.LifecycleBase.start (lifecyclebase.java:150) at org.apache.catalina.core.containerbase$ Startchild.call (containerbase.java:1559) at Org.apache.catalina.core.containerbase$startchild.call ( containerbase.java:1549) at Java.util.concurrent.FutureTask.run (futuretask.java:262) at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1145) at Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:615) at Java.lang.Thread.run ( thread.java:745)
Use the MVN denpendency:tree survey to find this dependency
[INFO] +-Com.rometools:rome:jar:1.5.0:compile[info] | +-Com.rometools:rome-utils:jar:1.5.0:compile[info] | \-Org.jdom:jdom:jar:2.0.2:compile
The use of the place is a controller, and then the dependency delete, the relevant Java code deleted, just fine.
4. Simplest API generation, no additional configuration required
<class= "Com.mangofactory.swagger.configuration.SpringSwaggerConfig"/ >
Jar Source Access
Access/api-docs this path to generate Swagger object
5. Custom Configuration with inherited default configuration
@Configuration @enablewebmvc@enableswagger@componentscan ("Com.myapp.controllers") Public classCustomjavapluginconfig {PrivateSpringswaggerconfig Springswaggerconfig; @Autowired Public voidsetspringswaggerconfig (Springswaggerconfig springswaggerconfig) { This. Springswaggerconfig =Springswaggerconfig; } @Bean//Don ' t forget the @Bean annotation PublicSwaggerspringmvcplugin customimplementation () {return NewSwaggerspringmvcplugin ( This. springswaggerconfig). Apiinfo (Apiinfo ()). IncludePatterns (". *pet.*"); } Privateapiinfo Apiinfo () {apiinfo apiinfo=NewApiinfo ("My Apps API Title", "My Apps API Description", "My Apps API Terms of service", "My Apps API Contact Email", "My Apps API Licence Type", "My Apps API License URL" ); returnApiinfo; }}
It is important to note that Componentscan cannot scan the org.springframework or it will error
caused by:java.lang.IllegalArgumentException: @EnableAsync annotation metadata is not injected
In general, this is not scanned, because it is the addition of some code on the basis of showcase, it is easy to make this problem.
You can get rid of this annotation class directly.
6. Some configurations can be put forward
7. Connect the Swagger UI
Project code: [Email protected]:witaste/spring-mvc-showcase.git
(ii) Spring-mvc-showcase and SWAGGER-SPRINGMVC's grievances