I think when you have the two separate endpoints it's necessary to set the setUsePathBasedConfig value to "true", otherwise you end up with some caching of APIs. The following JIRA explains it better:
https://issues.apache.org/jira/browse/CXF-6740 It seems that the problem with "setUsePathBasedConfig" is set to true might be unique to spring-boot, as the following CXF demo sets it to true for multiple endpoints in Tomcat and it appears to work correctly: https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/jax_rs/description_swagger2_web/src/main/webapp/WEB-INF/context.xml Could you create a JIRA for it and attach the test-case? Colm. On Wed, Apr 11, 2018 at 6:27 PM, Dongfeng Lu <[email protected]> wrote: > Let me explain a little bit more about the structure of this simple > project. In the attached "Figure 1", you can see there are two main > packages "serverOne" and "serverTwo". Under each one, there is an interface > like "OneServer.java", an implementation like "OneServerImpl.java", and a > CXF configuration file like "OneServerConfig.java". The main part of the > "OneServerConfig.java" is > > @Bean > @DependsOn("cxf") > public Server oneServerServerREST(ApplicationContext appContext) { > JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance(). > createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class); > factory.setServiceBean(oneServer); > factory.setAddress("/oneServer"); > factory.setProviders(restProviderList(appContext, oneServer)); > > Swagger2Feature feature = new Swagger2Feature(); > // customize some of the properties > feature.setTitle("oneServer"); > feature.setResourcePackage("com.example.api.serverOne"); > feature.setBasePath("/oneServer"); > feature.setUsePathBasedConfig(Boolean.TRUE); > feature.setScan(true); > feature.setScanAllResources(true); > > factory.getFeatures().add(feature); > > return factory.create(); > } > > The structure for "serverTwo" is basically the same, with the main part of > the "TwoServerConfig.java" as > > @Bean > @DependsOn("cxf") > public Server twoServerServerREST(ApplicationContext appContext) { > JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance(). > createEndpoint(twoServerJaxRsApiApplication(), > JAXRSServerFactoryBean.class); > factory.setServiceBean(twoServer); > factory.setAddress("/twoServer"); > factory.setProviders(restProviderList(appContext, twoServer)); > > Swagger2Feature feature = new Swagger2Feature(); > // customize some of the properties > feature.setTitle("twoServer"); > feature.setResourcePackage("com.example.api.serverTwo"); > feature.setBasePath("/twoServer"); > feature.setUsePathBasedConfig(Boolean.TRUE); > feature.setScan(true); > feature.setScanAllResources(true); > > factory.getFeatures().add(feature); > > return factory.create(); > } > > So you can see that the two "Servers" are basically the same, and they are > loaded in "AppConfig.java" via > > @Import({TwoServerConfig.class, OneServerConfig.class}) > > I am attaching 4 more screenshots here with comments to further explain > what we expects and what is happening. "Figure 2" and "Figure 3" show the > cases when "feature.setUsePathBasedConfig(Boolean.TRUE);" is enabled in > both "OneServerConfig.java" and "TwoServerConfig.java". Like I stated in my > first email, they display the titles correctly, but both pages do not have > any method, and I don't even see the "Show/Hide" link. > > "Figure 4" and "Figure 5" show the cases when "feature. > setUsePathBasedConfig(Boolean.TRUE);" is commented out in both > "OneServerConfig.java" and "TwoServerConfig.java". Both display the same > thing, which is the API on "twoServer" with the actual API showing. I can > show/hide the API to show the two methods, "/two" and "/two/feed". We need > "Figure 4" to display "oneServer" APIs. > > I hope I have explained my case clearly. Please help. > > Dongfeng > > > On Tuesday, April 10, 2018, 5:47:52 PM CDT, Dongfeng Lu < > [email protected]> wrote: > > > Hi. We have been using CXF for a long time, and we would like to add > Swagger 2 to our project. However, I have been having a hard time doing it. > I have been searching on the web for a couple of days, but I still cannot > figure it out. I need help. > > For easy communication, I have build a sample project to illustrate my > issue. You can unzip it and run "mvn clean tomcat7:run" in the directory, > and then you can access it with "http://localhost:8080" to display the > two REST services, built on two org.apache.cxf.endpoint.Servers. > > If I comment out "feature.setUsePathBasedConfig(Boolean.TRUE);" in both > "OneServerConfig.java" and "TwoServerConfig.java", then both " > http://localhost:8080/oneServer/api-docs?url=/oneServer/swagger.json" and > "http://localhost:8080/twoServer/api-docs?url=/twoServer/swagger.json" > display the same thing, which is the API on "twoServer" with the actual API > showing. I can show/hide the API to show the two methods, "/two" and > "/two/feed". Why do they display the same thing? > > If I enable "feature.setUsePathBasedConfig(Boolean.TRUE);" in both > "OneServerConfig.java" and "TwoServerConfig.java", then " > http://localhost:8080/oneServer/api-docs?url=/oneServer/swagger.json" > displays a page titled correctly with "oneServer", while " > http://localhost:8080/twoServer/api-docs?url=/twoServer/swagger.json" > displays a page titled correctly with "twoServer". Seems correct, but both > pages do not have any method, and I don't even see the "Show/Hide" link. > Where does those methods go? > > Of course, we want each link to display its own Swagger information > correctly, with all available methods. What have I been doing wrong? Please > help. Thanks in advance. > > Dongfeng > -- Colm O hEigeartaigh Talend Community Coder http://coders.talend.com
