0

apache cxf と spring を使用して安らかな Web サービスとして公開したい 2 つのクラスがありますが、2 つの異なるクラスの 2 つの Web サービスを公開できません。2 番目のサービスの呼び出し中にランタイム例外が発生しました。私のproject.plzで使用している.xmlと2つのクラスのいずれかがこの問題を修正します

  `enter code here`  web.xml
    --------

   <!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd" >

     <web-app>
    <display-name>ApacheCXF Sample Application</display-name>

      <!-- Add for Spring support -->
      <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
     </context-param>




     <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-        class>
 </listener>



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

       <init-param>
     <param-name>com.sun.jersey.config.property</param-name>
      <param-value>com.iton.restExamples.ServiceOneImpl</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
   </servlet>


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

    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
    <param-value>com.iton.restExamples.ServiceTwoImpl</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
   </servlet>

  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/base/*</url-pattern>
  </servlet-mapping>



 <servlet-mapping>
    <servlet-name>AnotherCXFServlet</servlet-name>
    <url-pattern>/another/*</url-pattern>
 </servlet-mapping>

 </web-app>


    applicatin context.xml
    ------------------------

   <?xml version="1.0" encoding="UTF-8"?>
    <beans default-autowire="byName"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/util          http://www.springframework.org/schema/util/spring-util-3.0.xsd
            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

<context:component-scan base-package="com.example" />

<!-- <import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
-->
   <jaxrs:server id="restContainer" address="/">
    <jaxrs:serviceBeans>

        <ref bean="serviceOne"/>
        <ref bean="serviceTwo"/>
       </jaxrs:serviceBeans>


 </jaxrs:server>






   <bean id="serviceOne" class="com.iton.restExamples.ServiceOneImpl"></bean>
   <bean id="serviceTwo" class="com.iton.restExamples.ServiceTwoImpl"></bean>
   </beans>


   ServiceOneImpl.java
    ---------------

  package com.iton.restExamples;


  import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;

 public class ServiceOneImpl implements ServiceOne {

public ServiceOneImpl() {
    // TODO Auto-generated constructor stub
}

@Override
@GET
@Produces("text/plain")
@Path("/one")
public String mesgTwo(@QueryParam("msg") String mesgTwo) {
    System.out.println(mesgTwo);
    System.out.println("welcome message");

    return mesgTwo;

}

   }


   SeriveTwoImpl.java
    -------------------

    package com.iton.restExamples;

   import javax.ws.rs.GET;
   import javax.ws.rs.Path;
    import javax.ws.rs.Produces;

     public class ServiceTwoImpl implements ServiceTwo {

public ServiceTwoImpl() {
    // TODO Auto-generated constructor stub
}

@Override
@GET
@Produces("text/plain")
@Path("/two")
public String mesgTwo(String mesg) {
    mesg="Welcome";
    System.out.println(mesg);
    System.out.println("welcome message in Serive two");

    return mesg;

}

    }
4

1 に答える 1