Java @inject空指针

时间:2017-03-30 06:36:08

标签: annotations jax-rs aop inject

我试图在我的方面类上注入一个对象,但该对象有一个空指针引用。

代码:

@Aspect
public aspect RestRequestsAspect {

  @Inject @LoggerAnnotation private Logger logger;

  @Before("execution(* com.living.commty.rest.endpoints.interfaces.*.* (..))")
  public void beforeCall () { 
      logger.info(" - INFO TEST BEFORE - ");    
  }

  @After("execution(* com.living.commty.rest.endpoints.interfaces.*.* (..))")
  public void afterCall () {
      logger.info(" - INFO TEST AFTER - ");
  }
}

public class LoggerProducer {  

  @Produces @LoggerAnnotation 
  public Logger produceLogger(InjectionPoint injectionPoint) {  
      return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
  }  
}  

@Qualifier 
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface LoggerAnnotation { }

调试器进入@Before和@After方法,但是logger对象有一个空指针引用。

我失踪了什么?

感谢。

0 个答案:

没有答案