sách gpt4 ai đã đi

java - Spring AOP - 实现 spring aop 时不调用服务方法

In lại 作者:行者123 更新时间:2023-11-29 03:10:27 27 4
mua khóa gpt4 Nike

Aop配置已经在我的项目中完成了。为此添加了以下配置。问题是当下面的代码没有注释时,不会调用 formService 中的方法。因此我得到空指针异常。知道问题出在哪里吗?我附上了下面的代码..

AOP 配置:



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-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd ">














配置formService bean的Application-Context-service.xml:




com.radaptive.rdpv.runtime.service.FormService






























方面类:

public class AspectClass {

public void sequenceUpdateAfterReturning(JoinPoint joinPoint, Object result) throws RttException {
WebApplicationContext ctx = (WebApplicationContext) RadaptiveApplicationCache.getInstance().getAttribute("SPRING_CONTEXT");
Pat patientService = (Pat) ctx.getBean("pat");
patientService.updatePrefixStatus("Success");
}


public void sequenceUpdateAfterThrowing(JoinPoint joinPoint, Throwable error) throws RttException {
WebApplicationContext ctx = (WebApplicationContext) XXXApplicationCache.getInstance().getAttribute("SPRING_CONTEXT");
Pat patientService = (Pat) ctx.getBean("pat");
patientService.updatePrefixStatus("Failed");
}

public String getPrefixLogAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] paramValues = joinPoint.getArgs();
String prefixStatus = String.valueOf(PrefixStatus.Reserved.getValue());
//Get prefix method,waiting for till prefix status is reserved
long startTime = System.currentTimeMillis();
while(prefixStatus.equals(String.valueOf(PrefixStatus.Reserved.getValue()))){
WebApplicationContext ctx = (WebApplicationContext) XXXApplicationCache.getInstance().getAttribute("SPRING_CONTEXT");
Pat pat = (Pat) ctx.getBean("pat");
prefixStatus = pat.getPrefixAvailability(paramValues[0].toString(),paramValues[1].toString(),paramValues[2].toString(), paramValues[4].toString());

if(!prefixStatus.equals(String.valueOf(PrefixStatus.Reserved.getValue()))){
Object retVal = joinPoint.proceed();
prefixStatus = retVal.toString();
phá vỡ;
}
}
return prefixStatus;
}
}

下面代码遇到的问题:

每当我尝试在我的应用程序中保存表单时,都不会调用表单服务。在下面的代码中,我调用了 Formservice của createForm 方法,但它返回 null..

    public String saveForm() throws RException {
thử {
entityMap = ((FormService) services.get("formManager")).createForm(metaform.getFormName(), entityMap, userPrincipal, triggerContext);
return SUCCESS_INCLUDE_DATA;
} catch (Exception e) {

}
}

public final Map createForm(final String formName, final Map values,
final UserPrincipal userPrincipal, TriggerContext triggerContext) throws Exception {
System.out.println("========== FORM SERVICE ENTER =======");
return formmap;
}

createForm 中的 sys out 打印,我非常困惑为什么这个 spring aop 会阻止 formservice 方法的调用。当我评论 aop:config 时,一切正常。

1 Câu trả lời

你的方面是罪魁祸首,它正在有效地破坏电话。您既没有调用 proceed() 也没有将该调用的结果返回给调用者。因此,您的方法永远不会被调用,您现在实际上总是返回 vô giá trị.

你的方法应该是这样的。

public Object getPrefixLogAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("====333");
return joinPoint.proceed();
}

关于java - Spring AOP - 实现 spring aop 时不调用服务方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669247/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com