2017-01-17 4 views
0

私はJerseyを使用して、strutsアプリケーションに簡単なWebサービスを提供しようとしています。Jersey/Strutsアプリケーションで

私は、次のようなエラーにweb.xmlの

com.sun.jersey.api.client.UniformInterfaceException 
Message: GET http://localhost:8080/shumer/rest/employee/get returned a response status of 404 

サーブレット宣言を取得し、クライアントのアクションを呼び出すとき

<servlet> 
    <servlet-name>JAX-RS Servlet</servlet-name> 
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> 
    <init-param> 
     <param-name>spring.autowire</param-name> 
     <param-value>byName</param-value> 
    </init-param> 
    <load-on-startup>3</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>JAX-RS Servlet</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 

Serverリソース

@Path("employee") 
public class EmployeeResource { 

    @Autowired 
    EmpDao empDao; 

    @GET 
    @Produces(MediaType.APPLICATION_JSON) 
    public List<Employee> get(@QueryParam("empCode") String empCode) throws Exception { 

      EmpCriteria criteria = new EmpCriteria(); 
      criteria.setEmpCode(empCode); 


      return empDao.searchByCondition(criteria); 
     } 

} 

クライアントのアクション

public class EmployeeClientTestAction extends Action { 

    @Override 
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, 
     HttpServletResponse response) throws Exception { 

     Client client = Client.create(); 
     WebResource resource = client.resource("http://localhost:8080/shumer/rest/employee/get"); 

     String employees= resource.accept(MediaType.APPLICATION_JSON) 
     .get(String.class); 

     System.out.println(employees); 

     request.setAttribute("employees", employees); 

     return mapping.findForward("successful"); 
    } 

} 

私は/getとリソースURLの末尾、および末尾に/の有無にかかわらず、これをEmployeeResource @Pathアノテーションに使用しました。私の推測では、Jerseyサーブレットがリソースを処理するためにリソースがどこにあるかを宣言しなければならない場所があると思いますが、わかりません。正しい方向のポイントが高く評価されます。私は、servlet要素に次のinit-のparamを追加して、それはまだ動作していない

EDITは、getメソッドの書き込みで

<init-param> 
    <param-name>com.sun.jersey.config.property.packages</param-name> 
    <param-value>shumer.rest.resource</param-value> 
</init-param> 
+0

あなたが使用しているジャージーのバージョンは? –

答えて

0

(私のリソースクラスがある場合、このパッケージです) @Path( "/ get")

関連する問題