Migration of Swagger to 1.5.0 for CXF JAX-RS Build Problem

999 views
Skip to first unread message

john....@disney.com

unread,
Jun 17, 2015, 6:56:30 PM6/17/15
to swagger-sw...@googlegroups.com
Hi.

I am following the Migration Guide From Swagger Core 1.3 to 1.5. I believe I have followed the correctly, but the project won't build. All the Swagger annotations can't be resolved. Here is my information.

- CXF JAX-RS
- Build with Maven
- Downloaded swagger-jaxrs-1.5.0.jar from http://mvnrepository.com/artifact/io.swagger/swagger-jaxrs/1.5.0.
- installed the jar file in Maven\lib and was successful (in my M2 directory)
- Changed pom.xml with this dependency
     <dependency>
      <groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>

- Changed beans.xml to:
      <bean id="apiListingResource" class="io.swagger.jaxrs.listing.ApiListingResource"/>
   <bean id="swaggerSerializers" class="io.swagger.jaxrs.listing.SwaggerSerializers"/>

   <bean id="swaggerConfig" class="com.wordnik.swagger.jaxrs.config.BeanConfig">
  <property name="resourcePackage" value="com.disney.abcdm.vp2.ws"/>
<property name="version" value="1.0.0"/>
<!--<property name="basePath" value="http://localhost:8080/api-utils"/>//-->
<property name="schemes" value="http"/>
<property name="host" value="localhost:8080"/>
<property name="basePath" value="api-utils"/>
<property name="title" value="ABC EIA Utils APP"/>
<property name="description" value="This Swagger Instance is a collection ..."/>
<property name="contact" value="EIA"/>
<property name="license" value="Apache 2.0 License"/>
<property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>
<property name="scan" value="true"/>
</bean>

The error messages from the Maven build list all of the occurrences of any Swagger annotation. ("Cannot find Symbol")

In the annotated java file I have:
import com.wordnik.swagger.annotations.*;

"wordnik" is highlighted in red.

Can you see what I am missing? It's like it can't find Swagger?

Thanks,

johnh


Ron Ratovsky

unread,
Jun 18, 2015, 10:41:01 AM6/18/15
to swagger-sw...@googlegroups.com
John,

All package names of the old swagger-core modules have changed, including the ones for the annotations.
You need to search and replace everywhere in your code.
Just need to replace com.wordnik.swagger with io.swagger.

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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

john....@disney.com

unread,
Jun 18, 2015, 11:04:54 AM6/18/15
to swagger-sw...@googlegroups.com
Here's an interesting quote from  https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X  If you're migrating, you need to update your imports accordingly. This will mostly affect your annotation usage. A simple find/replace should cover this change easily.  What does that mean? What should the import statement say? And it is not clear to me if I need to change my annotations. If I have to change them, where can  I find out what to change them to?

Thanks, johnh

john....@disney.com

unread,
Jun 18, 2015, 11:06:14 AM6/18/15
to swagger-sw...@googlegroups.com
Ok, I will try that. Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

john....@disney.com

unread,
Jun 18, 2015, 11:30:57 AM6/18/15
to swagger-sw...@googlegroups.com
Sorry, that does not do it. My project does not recognize any Swagger annotations. My import looks like this: import io.swagger.annotations.*; You can see what I changed in my pom.xml and beans.xml. I believe that is to the spec in the migration document. Any ideas. I am pretty sure that 1.5.0 was installed in Maven because it is under the M2 directory. Any ideas?


On Thursday, June 18, 2015 at 7:41:01 AM UTC-7, Ron wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

john....@disney.com

unread,
Jun 18, 2015, 12:38:46 PM6/18/15
to swagger-sw...@googlegroups.com

Ron, there must be some sort of example of an annotated .java file, pom.xml file and beans.xml file for cxf jax-rs using Swagger-Core 1.5.0. This should not be difficult. johnh

Ron Ratovsky

unread,
Jun 18, 2015, 12:41:08 PM6/18/15
to swagger-sw...@googlegroups.com
All the samples have migrated to https://github.com/swagger-api/swagger-samples, including the cxf one. They're all based on the new 1.5.0.

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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.

john....@disney.com

unread,
Jun 18, 2015, 1:28:28 PM6/18/15
to swagger-sw...@googlegroups.com
I have completely followed the example. I use a bean.xml file and not an applicationContext.xml file, but have duplicated everything. I have provided the correct pom info. No errors, but import io.swagger.annotations.*; does not work. "annotations" is in red. Intellisense can't find it. 

I believe I have provided all the needed information to see if I messed up. And, it is still not seeing my annotations. Should I file this as a bug?
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
Jun 18, 2015, 1:39:20 PM6/18/15
to swagger-sw...@googlegroups.com

There’s no bug. You can see in the samples this works fine - https://github.com/swagger-api/swagger-samples/blob/master/java/java-jaxrs-cxf/src/main/java/io/swagger/sample/resource/PetResource.java#L19.

The problem is probably with the dependencies. I’d need to see the output of the following commands: mvn clean dependency:tree and mvn clean dependency:list ran at the root of the project.


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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.

john....@disney.com

unread,
Jun 18, 2015, 1:53:14 PM6/18/15
to swagger-sw...@googlegroups.com

I sent you a private message with an attachment of the maven stuff. Hope you got it. Thanks. I will post it publicly to make sure you get it. Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
ronMavenStuff.txt

john....@disney.com

unread,
Jun 18, 2015, 5:23:47 PM6/18/15
to swagger-sw...@googlegroups.com
Hi Ron,

Yes, the problem is one of dependencies. Errors are being narrowed down after explicitly declaring swagger-annotations in the pom. Before it was that Swagger pulled these dependencies, and now that is not true. I am wondering if the swagger-core 1.5.0 is the right one for my application. From the server log: Property 'bus' threw exception; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [io.swagger.jaxrs.config.BeanConfig] for bean with name 'swaggerConfig' defined in ServletContext resource [/WEB-INF/beans.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: io/swagger/config/Scanner

john....@disney.com

unread,
Jun 18, 2015, 7:01:40 PM6/18/15
to swagger-sw...@googlegroups.com
Had some success. Stopped using Swagger-jaxrs and downloaded swagger-core. After many tweaks I get Maven to build without errors. Then I fixed the issues that Tomcat had with beansconfig/Scanner. So, now it should work. But, "Can't read swagger JSON from http://localhost:8080/api-utils/swagger.json".  This is my beansConfig. I see nothing wrong with it.

<bean id="swaggerConfig" class="io.swagger.jaxrs.config.BeanConfig">

<property name="resourcePackage" value="com.disney.abcdm.vp2.ws"/>
<property name="version" value="1.0.0"/>
  <property name="basePath" value="http://localhost:8080/api-utils"/>
  <!--<property name="schemes" value="http" />
  <property name="host" value="localhost:8080" />
  <property name="basePath" value="api-utils" />//-->
  <property name="title" value="ABC EIA Utils APP"/>
  <property name="description" value="This Swagger Instance is a collection of API Web Services built by ABC and The Walt Disney Company technologies for WATCH ABC, Partners of Disney or ABC and related Video On Demand Presentation Integrations. These APIs are used by applications integrating with the Service."/>

<property name="contact" value="EIA"/>
<property name="license" value="Apache 2.0 License"/>
<property name="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>
<property name="scan" value="true"/>
</bean>

Do you see anything wrong with this?

Thanks, johnh

john....@disney.com

unread,
Jun 19, 2015, 12:14:36 PM6/19/15
to swagger-sw...@googlegroups.com
Ron, 

Yesterday I sat down with some Java engineers in our Studio and no one can figure out why Swagger-Ui cannot read swagger. json. Step-by-step we have walked through the migration documents and the CXF example code, which you recently updated. We have tried every variation of a URL from the Swagger-UI to see if somehow we messed up the path to the the file. We have used api-docs, swagger.json and every combination of expression of host, schemes, basePath, etc. We have checked every log in Tomcat and the Maven output. How can't we even tell if Swagger built swagger.json? 

Is there anything I can provide to help you help me with this? This is my second day of trying to debug this and I don't even know what tools can help. I need to decide if there is something inherent in my project that prevents me from using the newer Swagger.

Thanks for your help.

John 

We had to explicitly add the swagger-annotations dependency:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.0</version>
<scope>compile</scope>
</dependency>

I provided my beans.xml file. Is there something wrong with the path to swagger.json. 

Ron Ratovsky

unread,
Jun 19, 2015, 1:04:13 PM6/19/15
to swagger-sw...@googlegroups.com

There seems to be an issue with your pom.xml which causes all subsequent problems.

You should revert back to the original swagger-jaxrs dependency as a first step.
The problem is that for some reason it does not load the dependencies it has. This is the issue you need to solve.
However, this is something I cannot help with within this scope, and you’d have to find a solution by yourself.

For reference, if you run mvn dependency:tree on the cxf project from our samples, you’ll see the following for the swagger-jaxrs dependency:

[INFO] +- io.swagger:swagger-jaxrs:jar:1.5.0:compile
[INFO] |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.4.2:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.2:compile
[INFO] |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.4.2:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.0:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.2:compile
[INFO] |  |  +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.2:compile
[INFO] |  |  \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] |  +- io.swagger:swagger-core:jar:1.5.0:compile
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.2:compile
[INFO] |  |  |  \- joda-time:joda-time:jar:2.2:compile
[INFO] |  |  +- io.swagger:swagger-models:jar:1.5.0:compile
[INFO] |  |  |  \- io.swagger:swagger-annotations:jar:1.5.0:compile
[INFO] |  |  \- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  +- org.reflections:reflections:jar:0.9.9:compile
[INFO] |  |  +- com.google.guava:guava:jar:15.0:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.18.2-GA:compile
[INFO] |  |  \- com.google.code.findbugs:annotations:jar:2.0.1:compile
[INFO] |  \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.4.2:compile
[INFO] |     \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.4.2:compile

Without all those dependencies, swagger-core will not work. This is why you’re not finding any of the annotations as well.

You’re output is:

[INFO] +- io.swagger:swagger-jaxrs:jar:1.5.0:compile

As you can see, no other dependencies are loaded. This is what you need to solve.

If you’re still stuck and need further assistance, we can help but that would fall under our professional services.
Feel free to contact me in person should that be the case.

BR,
Ron


Hi Ron,

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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
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.
Reply all
Reply to author
Forward
0 new messages