[ 
https://issues.apache.org/jira/browse/CXF-7724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16577292#comment-16577292
 ] 

Andriy Redko commented on CXF-7724:
-----------------------------------

Hi [~dlu66061],

In this particular case the issue comes from the fact that you define 2 
separate application classes for `serverOne` and `serverTwo` which do not have 
any singletons or classes. The simple solution would be:
 *  In OneServerConfig please change the JaxRsApiApplication to:  

{code:java}
    @ApplicationPath("/")
    public class JaxRsApiApplication extends Application {
        @Override
        public Set<Object> getSingletons() {
            return Collections.singleton(oneServer);
        }
    }{code}
 * Similarly, in TwoServerConfig please change the JaxRsApiApplication to:

{code:java}
    @ApplicationPath("/")
    public class twoServerJaxRsApiApplication extends Application {
        @Override
        public Set<Object> getSingletons() {
            return Collections.singleton(twoServer);
        }
    }{code}
And you should see the proper API descriptions for each context path. Thanks!

 

Best Regards,

    Andriy Redko

> CXF Swagger2Feature does not display methods with Java based configuration
> --------------------------------------------------------------------------
>
>                 Key: CXF-7724
>                 URL: https://issues.apache.org/jira/browse/CXF-7724
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>         Environment: Eclipse Oxygen, Tomcat 8.0.32, CXF 3.1.11, Spring 
> 4.3.9-RELEASE. 
> No Spring Boot.
>            Reporter: Dongfeng Lu
>            Priority: Major
>         Attachments: CxfSwaggerIssue_Java_configuration.zip, Figure 1.png, 
> Figure 2.png, Figure 3.png, Figure 4.png, Figure 5.png
>
>
> Related to the ticket CXF-7722, I also tried Java based configuration with 
> the Swagger2Feature.
> This ticket is different from CXF-7722 in 2 ways:
> 1. CXF-7722 uses XML configuration, while this one uses Java based 
> configuration.
> 2. CXF-7722 does not display methods only with an non-empty context root, 
> while this one does not display no matter the context root is empty or not.
> "Figure 1" shows the project structure of this simple sample project. 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
> {code:java}
> @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();
> }
> {code}
> The structure for "serverTwo" is basically the same, with the main part of 
> the "TwoServerConfig.java" as
> {code:java}
> @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();
> }
> {code}
> So you can see that the two "Servers" are basically the same, and they are 
> loaded in "AppConfig.java" via
> {code:java}
> @Import({TwoServerConfig.class, OneServerConfig.class}){code}
> "Figure 2" and "Figure 3" show the cases when context root is empty, while 
> "Figure 4" and "Figure 5" shows the cases with non-empty context root. They 
> all display the titles correctly, but none of them has any method, and we 
> don't even see the "Show/Hide" link.
> The attached sample project is a maven project. 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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to