Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Jersey web服务不返回任何内容 环境: 春季4.2.2 泽西1.19 说明: AOP配置 AOP类 结果:_Java_Spring_Jersey_Aop_Spring Aop - Fatal编程技术网

Java Jersey web服务不返回任何内容 环境: 春季4.2.2 泽西1.19 说明: AOP配置 AOP类 结果:

Java Jersey web服务不返回任何内容 环境: 春季4.2.2 泽西1.19 说明: AOP配置 AOP类 结果:,java,spring,jersey,aop,spring-aop,Java,Spring,Jersey,Aop,Spring Aop,如果使用AOP运行web服务,则不会出现错误,但客户端返回“204无内容”。如果我禁用AOP,一切正常。那为什么呢 非常感谢 问题在于,如果有一个around通知,您需要返回一个值;该值是实际建议的方法调用的返回值。原因是一个around通知允许您在需要时修改返回值 当前您正在返回void,这与资源方法调用返回null的效果相同。Jersey在返回nul时的默认行为是只发送一个没有数据的204 No内容,因为没有数据 对返回值的方法调用joinPoint.procedure()的结果将是该方法调

如果使用AOP运行web服务,则不会出现错误,但客户端返回“204无内容”。如果我禁用AOP,一切正常。那为什么呢


非常感谢

问题在于,如果有一个around通知,您需要返回一个值;该值是实际建议的方法调用的返回值。原因是一个around通知允许您在需要时修改返回值

当前您正在返回void,这与资源方法调用返回null的效果相同。Jersey在返回nul时的默认行为是只发送一个没有数据的204 No内容,因为没有数据

对返回值的方法调用
joinPoint.procedure()
的结果将是该方法调用的返回值。因此,只需获取对该值的引用并返回它

public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("1");
    Object retValue = joinPoint.proceed();
    System.out.println("2");
    return retValue;
}
另请参见:

<servlet>
    <servlet-name>REST-Servlet</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>xn.safephone.webapp.webservices</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>REST-Servlet</servlet-name>
    <url-pattern>/ws/*</url-pattern>
</servlet-mapping>
@GET
@Path("test")
@Produces("text/plain")
public String test() {
    return "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
}
public class AopWebServiceChecker {
    public void doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("1");
        joinPoint.proceed();
        System.out.println("2");
    }
}
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("1");
    Object retValue = joinPoint.proceed();
    System.out.println("2");
    return retValue;
}