使用@Around的奇怪行为 - Spring AOP

时间:2015-07-10 11:49:31

标签: java spring spring-mvc aop spring-aop

我创建了HelloController类,如下所示:

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/welcome")
public class HelloController {
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Spring MVC Hello World");
        return "hello";
    }
}

然后我使用LoggingAspect建议创建了@Before,效果很好,我的hello.jsp页面会在浏览器中打开http://localhost:8989/SpringApplication/welcome时显示。

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class LoggingAspect {

    @Before("execution(* com.controller.HelloController.printWelcome(..))")
    public void logBefore(JoinPoint joinPoint) {
        System.out.println("logBefore() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println("******");
    }
}

然后,我删除了@Before并添加了@Around的代码,如下所示:

import java.util.Arrays;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class LoggingAspect {

    @Around("execution(* com.controller.HelloController.printWelcome(..))")
    public void logAround(ProceedingJoinPoint pointroceedingJoinPoint)
            throws Throwable {

        System.out.println("logAround() is running!");
        System.out.println("hijacked method : "
                + pointroceedingJoinPoint.getSignature().getName());
        System.out.println("hijacked arguments : "
                + Arrays.toString(pointroceedingJoinPoint.getArgs()));

        System.out.println("Around before is running!");
        pointroceedingJoinPoint.proceed();

        System.out.println("Around after is running!");

        System.out.println("******");
    }
}

现在,在浏览器中打开http://localhost:8989/SpringApplication/welcome时, 它告诉我:

  

HTTP状态404 - /SpringApplication/pages/welcome.jsp

此外,我可以在控制台上看到@Around打印的语句如下:

logAround() is running!
hijacked method : printWelcome
hijacked arguments : [{}]
Around before is running!
Around after is running!
******

现在,我的问题是,当我返回时welcome.jsp正在搜索hellohello.jsp应该解析为UIImage

你能帮我解决这个问题吗?

0 个答案:

没有答案