为什么我的Aspect没有执行eventhough方面类是在弹簧容器加载时扫描的。
我的Aspect课程如下:
package com.qmp.aspect;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.qmp.data.addressstd.request.AddressStdRequest;
import com.qmp.data.autorate.request.AutoRateRequest;
import com.qmp.data.brightline.request.BrightLineRequest;
import com.qmp.data.email.request.SendEmailRequest;
import com.qmp.data.retrievequote.request.RetrieveQuoteRequest;
import com.qmp.data.savequote.request.SaveQuoteRequest;
import com.qmp.data.vin.request.VINRequest;
@Component
@Aspect
@EnableAspectJAutoProxy
public class QMPLoggingAspect {
private static final Log log = LogFactory.getLog(QMPLoggingAspect.class
.getName());
private static long vinrequestCount = 0;
private static long addresStdrequestCount = 0;
private static long saveQuoterequestCount = 0;
private static long retQuoterequestCount = 0;
private static long autoRaterequestCount = 0;
private static long brightLinerequestCount = 0;
private static long emailServicerequestCount = 0;
@Around("execution(* com.qmp.service.QMPService.sendEmail(..)) && args(emailRequest)")
public void logAroundEmailService(ProceedingJoinPoint joinPoint,
SendEmailRequest emailRequest) {
System.out.println("venkat======================>");
ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest req = t.getRequest();
HttpSession session = req.getSession();
long lStartTime = new Date().getTime();
log.debug("Email Service Execution Starts:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
try {
joinPoint.proceed();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long lEndTime = new Date().getTime();
log.debug("Email Service Execution Ends:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
log.debug("Email Service Elapsed milliseconds==>"
+ (lEndTime - lStartTime) + " :: SessionId:: - " + session != null ? session
.getId() : "" + " Request Number==>" + emailServicerequestCount);
emailServicerequestCount++;
}
@Around("execution(* com.qmp.service.QMPService.doVinLookUp(..)) && args(vinRequest)")
public void logAroundVinLookup(ProceedingJoinPoint joinPoint,
VINRequest vinRequest) {
ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest req = t.getRequest();
HttpSession session = req.getSession();
long lStartTime = new Date().getTime();
log.debug("VIN Look up Execution Starts:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
try {
joinPoint.proceed();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long lEndTime = new Date().getTime();
log.debug("VIN Look up Execution Ends:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
log.debug("VIN Look up Elapsed milliseconds==>"
+ (lEndTime - lStartTime) + " :: SessionId:: - " + session != null ? session
.getId() : "" + " Request Number==>" + vinrequestCount);
vinrequestCount++;
}
@Around("execution(* com.qmp.service.QMPService.doBrightLine(..)) && args(brightLineRequest)")
public void logAroundBrightline(ProceedingJoinPoint joinPoint,
BrightLineRequest brightLineRequest) {
ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest req = t.getRequest();
HttpSession session = req.getSession();
long lStartTime = new Date().getTime();
log.debug("Brightline Execution Starts:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
try {
joinPoint.proceed();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long lEndTime = new Date().getTime();
log.debug("Brightline Execution Ends:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
log.debug("Brightline Elapsed milliseconds==>"
+ (lEndTime - lStartTime) + " :: SessionId:: - " + session != null ? session
.getId() : "" + " Request Number==>" + brightLinerequestCount);
brightLinerequestCount++;
}
@Around("execution(* com.qmp.service.QMPService.performAutoRate(..)) && args(autoRateRequest)")
public void logAroundAutoRate(ProceedingJoinPoint joinPoint,
AutoRateRequest autoRateRequest) {
ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest req = t.getRequest();
HttpSession session = req.getSession();
long lStartTime = new Date().getTime();
log.debug("Auto rate Execution Starts:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
try {
joinPoint.proceed();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long lEndTime = new Date().getTime();
log.debug("Auto rate Execution Ends:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
log.debug("Auto rate Elapsed milliseconds==>" + (lEndTime - lStartTime)
+ " :: SessionId:: - " + session != null ? session.getId()
: "" + " Request Number==>" + autoRaterequestCount);
autoRaterequestCount++;
}
@Around("execution(* com.qmp.service.QMPService.performAddressStandardization(..)) && args(addressStdRequest)")
public void logAroundAddressStd(ProceedingJoinPoint joinPoint,
AddressStdRequest addressStdRequest) {
ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest req = t.getRequest();
HttpSession session = req.getSession();
long lStartTime = new Date().getTime();
log.debug("Address Std Execution Starts:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
try {
joinPoint.proceed();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long lEndTime = new Date().getTime();
log.debug("Address Std Execution Ends:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
log.debug("Address Std Elapsed milliseconds==>"
+ (lEndTime - lStartTime) + " :: SessionId:: - " + session != null ? session
.getId() : "" + " Request Number==>" + addresStdrequestCount);
addresStdrequestCount++;
}
@Around("execution(* com.qmp.service.QMPService.retrieveQuote(..)) && args(retrieveQuoteRequest)")
public void logAroundRetrieveQuote(ProceedingJoinPoint joinPoint,
RetrieveQuoteRequest retrieveQuoteRequest) {
ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest req = t.getRequest();
HttpSession session = req.getSession();
long lStartTime = new Date().getTime();
log.debug("Retrieve Quote Execution Starts:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
try {
joinPoint.proceed();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long lEndTime = new Date().getTime();
log.debug("Retrieve Quote Execution Ends:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
log.debug("Retrieve Quote Elapsed milliseconds==>"
+ (lEndTime - lStartTime) + " :: SessionId:: - " + session != null ? session
.getId() : "" + " Request Number==>" + retQuoterequestCount);
retQuoterequestCount++;
}
@Around("execution(* com.qmp.service.QMPService.saveQuote(..)) && args(saveQuoteRequest)")
public void logAroundSaveQuote(ProceedingJoinPoint joinPoint,
SaveQuoteRequest saveQuoteRequest) {
ServletRequestAttributes t = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest req = t.getRequest();
HttpSession session = req.getSession();
long lStartTime = new Date().getTime();
log.debug("Save Quote Execution Starts:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
try {
joinPoint.proceed();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long lEndTime = new Date().getTime();
log.debug("Save Quote Execution Ends:: SessionId:: - " + session != null ? session
.getId() : ""
+ " - "
+ "TimeStamp:::"
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
.format(new Date()));
log.debug("Save Quote Elapsed milliseconds==>"
+ (lEndTime - lStartTime) + " :: SessionId:: - " + session != null ? session
.getId() : "" + " Request Number==>" + saveQuoterequestCount);
saveQuoterequestCount++;
}
}
applicationContext.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:component-scan base-package="com.qmp.service" />
<context:component-scan base-package="com.qmp.service.email" />
<context:component-scan base-package="com.qmp.util" />
<context:component-scan base-package="com.qmp.service.brightline" />
<context:component-scan base-package="com.qmp.dao" />
<context:component-scan base-package="com.qmp.aspect" />
<aop:aspectj-autoproxy />
</beans>
接口:QMPService.java
package com.qmp.service;
import com.farmers.ffq.exceptions.BaseFFQ3Exception;
import com.farmers.pla.service.PlaServiceException;
import com.qmp.data.addressstd.request.AddressStdRequest;
import com.qmp.data.addressstd.response.AddressStdResponse;
import com.qmp.data.autorate.request.AutoRateRequest;
import com.qmp.data.autorate.response.AutoRateResponse;
import com.qmp.data.brightline.request.BrightLineRequest;
import com.qmp.data.brightline.response.BrightLineResponse;
import com.qmp.data.email.request.SendEmailRequest;
import com.qmp.data.email.response.SendEmailResp;
import com.qmp.data.retrievequote.request.RetrieveQuoteRequest;
import com.qmp.data.retrievequote.response.RetrieveQuoteResponse;
import com.qmp.data.savequote.request.SaveQuoteRequest;
import com.qmp.data.savequote.response.SaveQuoteResponse;
import com.qmp.data.vin.request.VINRequest;
import com.qmp.data.vin.response.VINResponse;
public interface QMPService {
public VINResponse doVinLookUp(VINRequest vinRequest);
public BrightLineResponse doBrightLine(BrightLineRequest brightLineRequest);
public AutoRateResponse performAutoRate(AutoRateRequest autoRateRequest);
public AddressStdResponse performAddressStandardization(
AddressStdRequest addressStdRequest) throws BaseFFQ3Exception,
PlaServiceException;
public RetrieveQuoteResponse retrieveQuote(
RetrieveQuoteRequest retrieveQuoteRequest)
throws BaseFFQ3Exception, PlaServiceException;
public SaveQuoteResponse saveQuote(SaveQuoteRequest saveQuoteRequest)
throws BaseFFQ3Exception, PlaServiceException;
public SendEmailResp sendEmail(SendEmailRequest emailRequest);
}
Implimentation class:
QMPServiceMgr.java //我已经在这个类中使用了所有方法。 控制器类:
package com.qmp.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.farmers.ffq.exceptions.BaseFFQ3Exception;
import com.farmers.pla.service.PlaServiceException;
import com.qmp.data.addressstd.request.AddressStdRequest;
import com.qmp.data.addressstd.response.AddressStdResponse;
import com.qmp.data.autorate.request.AutoRateRequest;
import com.qmp.data.autorate.response.AutoRateResponse;
import com.qmp.data.brightline.request.BrightLineRequest;
import com.qmp.data.brightline.response.BrightLineResponse;
import com.qmp.data.email.request.SendEmailRequest;
import com.qmp.data.email.response.SendEmailResp;
import com.qmp.data.retrievequote.request.RetrieveQuoteRequest;
import com.qmp.data.retrievequote.response.RetrieveQuoteResponse;
import com.qmp.data.savequote.request.SaveQuoteRequest;
import com.qmp.data.savequote.response.SaveQuoteResponse;
import com.qmp.data.vin.request.VINRequest;
import com.qmp.data.vin.response.VINResponse;
import com.qmp.service.QMPService;
@RestController
public class QMPController {
@Autowired
private QMPService qmpService;
@RequestMapping(value = "/vin", method = RequestMethod.POST)
public VINResponse doVinLookUp(@RequestBody VINRequest vinRequest) {
return qmpService.doVinLookUp(vinRequest);
}
@RequestMapping(value = "/brightline", method = RequestMethod.POST)
public BrightLineResponse performBrightLine(
@RequestBody BrightLineRequest brightLineRequest) {
return qmpService.doBrightLine(brightLineRequest);
}
@RequestMapping(value = "/autoRate", method = RequestMethod.POST)
public AutoRateResponse performAutoRate(
@RequestBody AutoRateRequest autoRateRequest) {
return qmpService.performAutoRate(autoRateRequest);
}
@RequestMapping(value = "/address", method = RequestMethod.POST)
public AddressStdResponse performAddrStandardization(
@RequestBody AddressStdRequest addressStdRequest)
throws PlaServiceException, BaseFFQ3Exception {
AddressStdResponse addressStdResponse = null;
return addressStdResponse = qmpService
.performAddressStandardization(addressStdRequest);
}
@RequestMapping(value = "/retQuote", method = RequestMethod.POST)
public RetrieveQuoteResponse retrieveQuote(
@RequestBody RetrieveQuoteRequest retrieveQuoteRequest)
throws PlaServiceException, BaseFFQ3Exception {
return qmpService.retrieveQuote(retrieveQuoteRequest);
}
@RequestMapping(value = "/saveQuote", method = RequestMethod.POST)
public SaveQuoteResponse saveQuote(
@RequestBody SaveQuoteRequest saveQuoteRequest)
throws PlaServiceException, BaseFFQ3Exception {
return qmpService.saveQuote(saveQuoteRequest);
}
@RequestMapping(value = "/comnms/v1/emailNotifications", method = RequestMethod.POST)
public SendEmailResp sendEmail(
@RequestBody SendEmailRequest sendEmailRequest) {
return qmpService.sendEmail(sendEmailRequest);
}
}
加载它时会验证所有语法并且运行良好,但不确定为什么在执行Rest Service时记录Aspect不注入。
任何帮助表示赞赏。
注意:我尝试使用Tomcat中相同配置的示例程序。但不确定为什么它没有在我在Project上运行的项目中运行。
谢谢, Venkat。