Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7669779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:40:22+00:00 2026-05-31T15:40:22+00:00

I’m using CXF RS 2.5.1 with Spring 3.0.6-RELEASE. I would like to have multiple

  • 0

I’m using CXF RS 2.5.1 with Spring 3.0.6-RELEASE. I would like to have multiple implementation classes for “a single endpoint”. I see that this issue was reported and fixed https://issues.apache.org/jira/browse/CXF-2439, however, when I try to do it, CXF just selects the first resource class from jaxrs:serviceBeans tag. For the other request, I see this message on tomcat console as “No operation matching request path /account/rest/transfer is found”. Below is the configuration. Appreciate any input.

web.xml

    <listener>
        <listener-class> org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:account-servlet.xml</param-value>
    </context-param>

      <servlet>
    <servlet-name>CXF Servlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
       </servlet>

      <servlet-mapping>
    <servlet-name>CXF Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
      </servlet-mapping>

account-servlet.xml

    <jaxrs:server id="accountService" address="/rest">
        <jaxrs:serviceBeans>
            <ref bean="transferService" />
                <ref bean="balanceService"/>
        </jaxrs:serviceBeans>
        <jaxrs:extensionMappings>
            <entry key="xml" value="application/xml" />
        </jaxrs:extensionMappings>
    </jaxrs:server>


    <bean id="transferService" class="com.mycompany.service.TransferService"/>
    <bean id="balanceService" class="com.mycompany.service.BalanceService"/>

BalanceService.java (imports omitted)

        package com.mycompany.service;
        @Path("/")
         @Produces("application/xml")
        public class BalanceService{

    @GET
    @Path("/balance")
    public String getBalance() {
        StringBuilder response = new StringBuilder(128);
        response.append("<Balance>")
            .append("<amount>").append("250.00").append("</amount>")
            .append("</Balance>");
        return response.toString();
    }
       }

TransferService.java (imports omitted)

package com.mycompany.service;

@Path("/")
@Produces("application/xml")
public class TransferService {

    @GET
    @Path("/transfer")
    public String getTransfer() {

        StringBuilder response = new StringBuilder(128);
        response.append("<Transfer>")
            .append("<amount>").append("350.00").append("</amount>")
            .append("</Transfer>");
        return response.toString();
    }
  }

Please ignore any programming irregularities/standards as it’s just a sample app for the POC.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:40:24+00:00Added an answer on May 31, 2026 at 3:40 pm

    So I spend some time searching the internet but found no solution to this problem. There is a note written in the documentation that can be used to deduce the solution.

    http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics-Customselectionbetweenmultipleresources

    Hence I wrote a custom resource comparator, did the appropriate jaxrs:server configuration and Eureka! it worked!. Now, I have 2 implementation classes mapped to a single resource/address in javax:rs address.

    Please be advised that logic in custom resource comparator shown below may vary based on the URL pattern.

    Providing source of all the files. Hope that this will help someone in future 🙂

    web.xml

    <web-app>
      <display-name>Archetype Created Web Application</display-name>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/account-servlet.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
        <servlet>
            <servlet-name>CXF Servlet</servlet-name>
            <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>CXF Servlet</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
    
    </web-app>
    

    account-servlet.xml (applicationContext)

    <beans>
        <jaxrs:server id="accountService" address="/rest">
            <jaxrs:serviceBeans>
                <ref bean="accountServiceImpl" />
                <ref bean="transferServiceImpl" />
            </jaxrs:serviceBeans>
            <jaxrs:resourceComparator>
                <bean id="accountServiceComparator" class="com.etrade.comparator.AccountServiceComparator"/>
            </jaxrs:resourceComparator>
            <jaxrs:extensionMappings>
                <entry key="xml" value="application/xml" />
            </jaxrs:extensionMappings>
        </jaxrs:server>
    
        <bean id="accountServiceImpl" class="com.etrade.service.AccountService" />
        <bean id="transferServiceImpl" class="com.etrade.service.TransferService" />
    </beans>
    

    pom.xml

      <modelVersion>4.0.0</modelVersion>
      <groupId>cxf.rest</groupId>
      <artifactId>account</artifactId>
      <packaging>war</packaging>
      <version>0.0.1-SNAPSHOT</version>
      <name>account Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
    
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-bundle-jaxrs</artifactId>
                <version>2.5.0</version>
            </dependency> 
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>3.0.5.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>3.0.5.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>3.0.5.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>3.0.5.RELEASE</version>
            </dependency>
    
      </dependencies>
      <build>
    
        <plugins>
          <plugin>
            <!-- This plugin is needed for the servlet example -->
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>7.2.0.v20101020</version>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
              <execution><goals><goal>java</goal></goals></execution>
            </executions>
          </plugin>
        </plugins>
    
        <finalName>account</finalName>
      </build>
    </project>
    

    Custom Resource comparator

    package com.etrade.comparator;
    
    import java.lang.reflect.Method;
    
    import javax.ws.rs.Path;
    
    import org.apache.cxf.jaxrs.ext.ResourceComparator;
    import org.apache.cxf.jaxrs.impl.UriInfoImpl;
    import org.apache.cxf.jaxrs.model.ClassResourceInfo;
    import org.apache.cxf.jaxrs.model.OperationResourceInfo;
    import org.apache.cxf.message.Message;
    
    public class AccountServiceComparator implements ResourceComparator{
    
        public int compare(ClassResourceInfo arg0, ClassResourceInfo arg1,
                Message message) {
    
            UriInfoImpl uriInfo = new UriInfoImpl(message);
    
            String path = uriInfo.getPath();
            String[] pathArray = path.split("/");
            String resourceUrlName = pathArray[1];
    
            System.out.println("Path : "+resourceUrlName);
    
            Method[] methods = arg0.getServiceClass().getMethods();
            int value = 1;
            String resource = null;
            for(Method method : methods) {
    
                Path annotationPath = method.getAnnotation(javax.ws.rs.Path.class);
                if(null != annotationPath){
                    String pathValue = annotationPath.value();
                    String[] parts = pathValue.split("/");
                    resource = parts[1];
                    System.out.println("resource : "+resource);
                }
    
                if(resourceUrlName.contains(resource)){
                    value = -1; 
                }
    
            }
            return value;
        }
    
        public int compare(OperationResourceInfo arg0, OperationResourceInfo arg1,
                Message arg2) {
            return 0;
        }
    
    }
    

    Implementation classes/beans

    AccountService.java

    package com.etrade.service;
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    
    @Path("/account")
    @Produces("application/xml")
    public class AccountService {
    
        @GET
        @Produces("application/xml")
        @Path("/balance/{id}")
        public String accountBalance(@PathParam("id") long id) {
            System.out.println("id : "+id);
            StringBuilder response = new StringBuilder(256);
            response.append("<Response>").append("<id>").append(id)
            .append("</id>").append("<balance>").append("250.00").append("</balance>")
            .append("</Response>");
    
            return response.toString();
        }
    
    }
    

    TransferService.java

    package com.etrade.service;
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    
    @Path("/account")
    @Produces("application/xml")
    public class TransferService {
    
        @GET
        @Produces("application/xml")
        @Path("/transfer/{id}")
        public String accountTransfer(@PathParam("id") long id) {
            System.out.println("transfer id : "+id);
            StringBuilder response = new StringBuilder(256);
            response.append("<Response>").append("<id>").append(id)
            .append("</id>").append("<transfer>").append("250.00").append("</transfer>")
            .append("</Response>");
    
            return response.toString();
        }
    
    
    }
    

    URLs:

    http://localhost:8080/rest/account/balance/12
    http://localhost:8080/rest/transfer/balance/13
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.