rest with jersey struts2 spring3 not working

2019-08-28 01:11发布

I am trying to expose webservice using jersey for a struts2 spring3 web application

my web.xml

    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.vxl.appanalytix.service.impl</param-value>
        </init-param>
       <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

In struts.xml i have added excludePattern

<constant name="struts.action.excludePattern" value="/rest/.*" />

service class

@Path("/requirement")
@Service("dimRequirementManager")
public class DimRequirementManagerImpl extends GenericManagerImpl<DimRequirement, Long> implements DimRequirementManager {
    @Autowired
    DimRequirementDao dimRequirementDao;
    @GET
    @Path("count")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public DimRequirement getDimRequirement(){
    DimRequirement dimRequirement = new DimRequirement();
    dimRequirement.setClientKey(123L);
    dimRequirement.setPriority("HIGH");

    return dimRequirement;
}}

dependency

<dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-spring</artifactId>
            <version>1.17.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

I am passing the below url in the restclient http://localhost:8080/app-web/rest/requirement/count its returning

Status Code: 404 Not Found
Content-Language: en
Content-Type: text/html;charset=utf-8
Date: Wed, 25 Sep 2013 05:47:27 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked

when debuging control is not going to the getDimRequirement()

1条回答
霸刀☆藐视天下
2楼-- · 2019-08-28 01:29

i have solved the problem. i had a url rewrite filter in my web.xml.

<filter>
    <filter-name>rewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
      <param-name>logLevel</param-name>
      <param-value>commons</param-value>
    </init-param>
    <init-param>
      <param-name>confReloadCheckInterval</param-name>
      <param-value>-1</param-value>
    </init-param>
  </filter>
 <filter-mapping>
    <filter-name>rewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

in the urlrewrite.xml i have added

<rule>
        <from>/rest/**</from>
        <to>/rest/$1</to>
    </rule>
查看更多
登录 后发表回答