我有以下问题。使用控制器的资源登录方面始终为null。这是因为我把'#34; final"控制器方法。如何在不删除" final"?
的情况下修复它我的代码:
应用背景:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
....
<cache:annotation-driven />
<mvc:annotation-driven />
<!-- AOP -->
<aop:aspectj-autoproxy />
<bean id="logAspect" class="es.xxx.xxx.xxx.aop.LoggingAspect" />
<!-- Scan de paquetes por anotaciones Spring -->
<context:component-scan base-package="es.xxx" />
....
</beans>
控制器:
@Controller("documentController")
@RequestMapping(value = "/documentation")
public class DocumentController {
@Resource
private FileService fileService;
@Resource
private FooService fooService;
@Resource
private MessageSource messageSource;
@RequestMapping("/foo.html")
public final String foo(Params...) {
...
//here are null and throw null pointer exception
fileService.fooMethod();
fooService.fooMethod();
messageResource.fooMethod();
...
return view;
}
...
}
Aspect日志:
@Aspect
public class LoggingAspect {
@Around("execution(* es.xxx.xxx.xxx.controller.*.*(..))")
public Object aroundController(ProceedingJoinPoint joinPoint) throws Throwable {
Logger logger = LogManager.getLogger(joinPoint.getTarget().getClass().getName());
logger.debug("...");
return joinPoint.proceed();
}
@AfterReturning(pointcut="execution(* es.xxx.xxx.xxx.controller.*.*(..))", returning="retVal")
public void afterReturningController(JoinPoint joinPoint, Object retVal) {
Logger logger = LogManager.getLogger(joinPoint.getTarget().getClass().getName());
logger.debug("...");
}
@AfterThrowing(pointcut="execution(* es.xxx.xxx.xxx.controller.*.*(..))", throwing="exception")
public void afterThrowingController(JoinPoint joinPoint, Exception exception) {
Logger logger = LogManager.getLogger(joinPoint.getTarget().getClass().getName());
logger.debug("...", exception);
}
@Around("execution(* es.xxx.xxx.xxx.service.impl.*.*(..))")
public Object aroundService(ProceedingJoinPoint joinPoint) throws Throwable {
Logger logger = LogManager.getLogger(joinPoint.getTarget().getClass().getName());
logger.debug("...");
return joinPoint.proceed();
}
@AfterReturning(pointcut="execution(* es.xxx.xxx.xxx.xxx.impl.*.*(..))", returning="retVal")
public void afterReturningService(JoinPoint joinPoint, Object retVal) {
Logger logger = LogManager.getLogger(joinPoint.getTarget().getClass().getName());
logger.debug("...");
}
@AfterThrowing(pointcut="execution(* es.xxx.xxx.xxx.service.impl.*.*(..))", throwing="exception")
public void afterThrowingService(JoinPoint joinPoint, Exception exception) {
Logger logger = LogManager.getLogger(joinPoint.getTarget().getClass().getName());
logger.debug("...", exception);
}
}