Question about the swagger-springmvc

1,564 views
Skip to first unread message

oriol....@bidnetwork.org

unread,
Mar 20, 2013, 12:07:27 PM3/20/13
to swagger-sw...@googlegroups.com
I've developing and API and I want to use swagger spring mvc to generate the documentation
After following the steps.. I can't do it work

in the log of start of the server i can see several lines like:

 WARN  [AnnotatedParameterFilter] public net.bidx.api.response.BidxResponse net.bidx.api.MemberApi.create(net.bidx.api.dto.MemberRegisterForm,org.springframework.validation.BindingResult,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws net.bidx.system.exception.api.InvalidArgumentsException,net.bidx.system.exception.api.EntityAlreadyExistsException,net.bidx.system.exception.api.InvalidBidxEntityException,net.bidx.system.exception.UserExistInGroupException is missing @ApiParam annotation - so generating default documentation

so it seems that is scanning correctly

But when I go to
http://localhost:8080/app/api/v1/oriol/api-docs  to get the json I have this error:

 DEBUG [RequestMappingHandlerMapping] Did not find handler method for [app/api/v1/oriol/api-docs]
 TRACE [DispatcherServlet] Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@1f7a17e3] in DispatcherServlet with name 'Spring MVC Dispatcher'

and I have this configuration
 <bean id="swaggerConfiguration" class="com.mangofactory.swagger.SwaggerConfiguration">
        <property name="basePath" value="http://localhost:8080/app/api/v1/oriol/"/>
...


any idea why I don't have the controller?

thanks

Oriol

tony tam

unread,
Mar 20, 2013, 12:20:47 PM3/20/13
to swagger-sw...@googlegroups.com
Hi Oriol, there's a new sample for swagger + spring + CXF + Tomcat here:


Can you take a peek there to see if that helps you get started?  I intend on getting a tutorial up for these technologies but it's just not there yet.

Tony

oriol....@bidnetwork.org

unread,
Mar 20, 2013, 12:41:40 PM3/20/13
to swagger-sw...@googlegroups.com
Hi, thanks for your reply
I tried.. but I can't start the server

[ERROR] Unknown lifecycle phase "tomcat6". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.
Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, g
enerate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, depl
oy, pre-site, site, post-site, site-deploy, pre-clean, clean, post-clean. -> [Help 1]

with the cmd: mvn package tomcat6:run

any idea?

tony tam

unread,
Mar 20, 2013, 2:11:43 PM3/20/13
to swagger-sw...@googlegroups.com
are you sure you're in the right working directory?  you should run that command directly from the sample directory which is samples/java-jaxrs-cxf

oriol....@bidnetwork.org

unread,
Mar 21, 2013, 5:06:15 AM3/21/13
to swagger-sw...@googlegroups.com
yes, you are right, I was at the incorrect folder
with the correct folder I've that error:

D:\projects\bidx\workspace\swagger-core\samples\java-jaxrs-cxf>mvn package tomcat6:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building swagger-java-cxf-sample 1.2.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] Could not transfer metadata com.wordnik:swagger-core_2.9.1:1.2.2-SNAPSHOT/maven-metadata.xml from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): Conne
ction to https://oss.sonatype.org refused
[WARNING] Failure to transfer com.wordnik:swagger-core_2.9.1:1.2.2-SNAPSHOT/maven-metadata.xml from https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resoluti
on will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced. Original error: Could not transfer metadata com.wordnik:swagger-core_2.9.1:1.2.2-SNA
PSHOT/maven-metadata.xml from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): Connection to https://oss.sonatype.org refused
[WARNING] Could not transfer metadata com.wordnik:swagger-jaxrs_2.9.1:1.2.2-SNAPSHOT/maven-metadata.xml from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): Conn
ection to https://oss.sonatype.org refused
[WARNING] Failure to transfer com.wordnik:swagger-jaxrs_2.9.1:1.2.2-SNAPSHOT/maven-metadata.xml from https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolut
ion will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced. Original error: Could not transfer metadata com.wordnik:swagger-jaxrs_2.9.1:1.2.2-S
NAPSHOT/maven-metadata.xml from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): Connection to https://oss.sonatype.org refused
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:25.317s
[INFO] Finished at: Thu Mar 21 09:39:19 CET 2013
[INFO] Final Memory: 13M/166M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project swagger-java-cxf-sample_2.9.1: Could not resolve dependencies for project com.wordnik:swagger-java-cxf-sample_2.9.1:war:1.2.2-SNAPSHOT: Failed to collect depe
ndencies for [org.reflections:reflections:jar:0.9.8 (compile), org.springframework:spring-context:jar:3.2.1.RELEASE (compile), org.springframework:spring-context-support:jar:3.2.1.RELEASE (compile), o
rg.springframework:spring-web:jar:3.2.1.RELEASE (compile), org.apache.cxf:cxf-rt-frontend-jaxrs:jar:2.7.3 (compile), org.apache.cxf:cxf-rt-transports-http:jar:2.7.3 (compile), org.apache.cxf:cxf-rt-rs
-extension-providers:jar:2.7.3 (compile), javax.ws.rs:jsr311-api:jar:1.1.1 (compile), org.codehaus.jackson:jackson-jaxrs:jar:1.9.11 (compile), org.codehaus.jackson:jackson-xc:jar:1.9.11 (compile), org
.slf4j:slf4j-api:jar:1.6.3 (compile), org.slf4j:log4j-over-slf4j:jar:1.6.3 (runtime), org.slf4j:jcl-over-slf4j:jar:1.6.3 (compile), org.slf4j:jul-to-slf4j:jar:1.6.3 (compile), ch.qos.logback:logback-c
lassic:jar:1.0.9 (runtime), com.wordnik:swagger-core_2.9.1:jar:1.2.2-SNAPSHOT (compile), com.wordnik:swagger-jaxrs_2.9.1:jar:1.2.2-SNAPSHOT (compile), javax.servlet:servlet-api:jar:2.5 (provided), org
.scala-lang:scala-library:jar:2.9.1-1 (compile), org.springframework:spring-test:jar:3.2.1.RELEASE (test), org.apache.cxf:cxf-rt-transports-http-jetty:jar:2.7.3 (test), org.scalatest:scalatest_2.9.1:j
ar:1.6.1 (test), junit:junit:jar:4.8.1 (test)]: Failed to read artifact descriptor for com.wordnik:swagger-core_2.9.1:jar:1.2.2-SNAPSHOT: Could not transfer artifact com.wordnik:swagger-core_2.9.1:pom
:1.2.2-SNAPSHOT from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): Connection to https://oss.sonatype.org refused: Connection timed out: connect -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
D:\projects\bidx\workspace\swagger-core\samples\java-jaxrs-cxf>

Thanks for your help

tony tam

unread,
Mar 21, 2013, 9:25:48 AM3/21/13
to swagger-sw...@googlegroups.com
I think you got very unlucky and sonatype was not available when you tried it.  It appears to be back up, can you try again?

oriol....@bidnetwork.org

unread,
Mar 25, 2013, 6:08:45 AM3/25/13
to swagger-sw...@googlegroups.com
yes, it works now the example of swagger + spring + CXF + Tomcat
I'll try to look how is it working in that example and figure why is not working swagger-spring
any idea where I can try to look in?
thanks

oriol....@bidnetwork.org

unread,
Mar 25, 2013, 7:41:54 AM3/25/13
to swagger-sw...@googlegroups.com
done. It works!
Now, how I can get info about all the annotations to put on code to get some ouput like the petstore?

Thanks

tony tam

unread,
Mar 28, 2013, 3:31:58 PM3/28/13
to swagger-sw...@googlegroups.com

Craig Foote

unread,
May 20, 2014, 12:43:39 PM5/20/14
to swagger-sw...@googlegroups.com
Hi guys, I need help using swagger-springmvc-0.8.3. I've been trying to follow Marty Pitt's example and I think I'm close.

The DefaultSwaggerController is being called but is returning null because neither SwaggerApiResourceListing#initialize nor SwaggerCache#addSwaggerResourceListing are being called. I suspect a problem with my spring config entries:

<context:component-scan base-package="com.mangofactory.swagger.controllers"/>
<context:component-scan base-package="com.mangofactory.swagger.configuration"/>
<context:annotation-config/>
<mvc:default-servlet-handler/>
<context:property-placeholder location="classpath:swagger.properties"/>


Marty then has two beans declared from his test project, DocumentationConfig and CustomExtensibilityModule, but they don't compile with swagger-springmvc-0.8.3. I'm thinking I need to do something here rather than just comment out the beans. I'm just not sure what those beans are doing and if they really are required. I see it's annotated with @PostConstruct, what is supposed to call SwaggerApiResourceListing#initialize?

Any ideas?
Craig
Message has been deleted

Craig Foote

unread,
May 20, 2014, 1:40:20 PM5/20/14
to swagger-sw...@googlegroups.com

I just found that when I commented out this block in my spring config:

<mvc:annotation-driven>
  <mvc:message-converters>
    <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
      <property name="prettyPrint" value="true"/>
    </bean>
  </mvc:message-converters>
</mvc:annotation-driven>
 

... that I get a startup error saying "error creating bean with name "springSwaggerConfig" because no bean was found to satisfy its "handlerMappings" autowired field, of type org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping". On a whim, I created a bean of that type but then just got a different error.

So two things:
1. Is <mvc:annotation-driven/> not compatible with <context:annotation-config/>?
2. Assuming I can find another way to declare pretty print that works with <mvc:annotation-driven/>, what handlerMapping should I be declaring?

Craig

Craig Foote

unread,
May 20, 2014, 3:43:58 PM5/20/14
to swagger-sw...@googlegroups.com

So the more I work on this the more I think my problem is that the SwaggerApiResourceListing#initialize, annotated with @PostConstruct, is not called even though I'm using:

<context:annotation-config/>
 

Any ideas why?
Craig

Ron

unread,
May 21, 2014, 7:44:09 AM5/21/14
to swagger-sw...@googlegroups.com
Chris,

Do you use Spring IoC only or Spring MVC? If the latter and you use swagger-springmvc, I'm afraid you'd have to ask you question here - https://github.com/martypitt/swagger-springmvc
It's an external library to Swagger and they would probably be able to help you better than we can.

BR,
Ron


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ron

unread,
May 21, 2014, 7:44:27 AM5/21/14
to swagger-sw...@googlegroups.com
And apologies, meant to write Craig :)
Reply all
Reply to author
Forward
0 new messages