나는 꽤 이상한 문제에 직면 해있다. 내 App에서 주석 기반 AspectJ를 사용한다. 내 방법을 진행하려고하면 autowired 필드에 null 포인터가 수신됩니다. (서비스 클래스에서 어떤 메소드가 인터셉터에서 호출되는지). AspectJ 사용 전에 스프링 컨텍스트가 잘 작동했다. 나는 어쩌면 내가 그냥 작은 실수 :(를 찾는 너무 많은 시간 소비가 표시되지 않습니다, 내 코드를 제공하고있어 :(봄 AOP 측면이 문맥을 망쳤다
다음은 화면 클래스를 진행됩니다.
@Aspect
@Component
public class SomeInterceptor{
private static final Logger LOGGER = LoggerFactory.getLogger(SomeInterceptor.class);
@Autowired
@Qualifier("webServiceResponseFactory")
protected WebServiceResponseFactory responseFactory;
@Autowired
@Qualifier("configBean")
protected ConfigBean configBean;
public SomeServiceInterceptor() {
LOGGER.info("Some service interceptor was created");
}
@Around("execution(public * pathToMyClassIsCorrect.*(..))")
public Object invoke(ProceedingJoinPoint pjp) throws Throwable {
String securityTokenForMethod = pjp.getArgs()[0].toString();
if (securityTokenForMethod != null) {
LOGGER.info("Proceeding the securityTokenCheck before calling method "
+ pjp.getSignature().getName());
if (validateAccessToken(securityTokenForMethod)) {
return responseFactory
.buildFailedResponse("securityAccessToken is invalid for this request");
}
} else {
throw new Throwable("There was an exception before calling method "
+ pjp.getSignature().getName());
}
try {
LOGGER.info("Calling method " + pjp.getSignature().getName());
Object methodToInvoke = pjp.proceed();
LOGGER.info("Method " + pjp.getSignature().getName()
+ " was called successfully");
return methodToInvoke;
} catch (Throwable e) {
LOGGER.info("Method " + pjp.getSignature().getName() + "threw an exception. ");
boolean verboseError = Boolean.parseBoolean(pjp.getArgs()[1].toString());
return responseFactory.buildErrorResponse(e, verboseError);
}
}
}
내 앱 컨텍스트를. XML은 compontent 스캔 패키지를 모두 포함하고있다 및 활성화.
어떤 도움은 매우 감사합니다.
편집
또한, 바로 호출 후 나는 그런받을 오류 :
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
편집 2.0 :
그냥 화면없이 서비스를 시작하려는 잘 작동합니다. 따라서 문제는 실제로 서비스 방법을 가로막는 측면에서 기인합니다. : \편집 3.0 :
나는 생성자에 로거를 추가했습니다. 따라서, 제가 보는 것처럼, 객체는 생성되지 않습니다. 이유가 무엇인지 모릅니다.
편집 4.0 : AspectJ를 구성 파일 :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE aspectj PUBLIC
"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver options="-verbose -showWeaveInfo -debug">
<!-- only weave classes in our application-specific packages -->
<include within="com.store.*"/>
<include within="com.store.services.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.store.services.StoreServiceAspect"/>
</aspects>
</aspectj>
<weaver options="-verbose">
<include within="javax.*" />
<include within="org.aspectj.*" />
<include
within="([email protected] com.store.services.*) AND com.bsro.storewebsrv.services.*" />
<dump within="com.store.services.*" />
</weaver>
AspectJ 또는 AspectJ 스타일의 Spring AOP를 사용합니까? 큰 차이가 있습니다! –
[Spring AOP or AspectJ?]를 참조하십시오. (http://static.springsource.org/spring/docs/current/spring-framework-reference/html/aop.html#aop-spring-or-aspectj) –
그 문서 전체에 압연 : ( – user