AspectJ和NoClassDefFoundError

时间:2009-11-09 16:39:26

标签: java

我对AspectJ有疑问。有没有人遇到类似的东西?我有上市:

  

../ SRC / JAVA / COM / WS /分贝/ Logging.aj

     

../ SRC / JAVA / COM / WS /分贝/ Db.java

方面:

  public aspect Logging {

      pointcut prepareCall(String statement): call(* java.sql.Connection.prepareCall(String)) && args(statement) &&
      within(com.ws.db.Db);

      before(String statement) : prepareCall(statement) {
        if(logger.isDebugEnabled())
          logger.debug("before prepareCall called: statement="+statement);
      }

      after(String statement) : prepareCall(statement) {
        if(logger.isDebugEnabled())
          logger.debug("after prepareCall called, "+statement);
      }
  }

一切正常,但是当我添加这个

   pointcut createStm(): call(* java.sql.Connection.createStatement()) &&
   within(com.ws.db.Db);

   before() : createStm()  {
     if(logger.isDebugEnabled())
       logger.debug("before called: "+thisJoinPoint);
   }

   after() : createStm() {
     if(logger.isDebugEnabled())
       logger.debug("after called: "+thisJoinPoint);
   }

我得到以下异常:

它无法找到com.ws.db.Db,就像类被更改一样,它无法检索它。

    > org.apache.axis.EXCEPTIONS 2009-11-09 16:06:39,748 -- INFO -- Exception:
    java.lang.NoClassDefFoundError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:242)
    at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:177)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:160)
    at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:142)
    at org.apache.axis.utils.cache.ClassCache.lookup(ClassCache.java:85)
    at org.apache.axis.providers.java.JavaProvider.getServiceClass(JavaProvider.java:428)
    at org.apache.axis.providers.java.JavaProvider.initServiceDesc(JavaProvider.java:461)
    at org.apache.axis.handlers.soap.SOAPService.getInitializedServiceDesc(SOAPService.java:286)
    at org.apache.axis.deployment.wsdd.WSDDService.makeNewInstance(WSDDService.java:500)
    at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getNewInstance(WSDDDeployableItem.java:274)
    at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getInstance(WSDDDeployableItem.java:260)
    at org.apache.axis.deployment.wsdd.WSDDDeployment.getService(WSDDDeployment.java:427)
    at org.apache.axis.configuration.FileProvider.getService(FileProvider.java:231)
    at org.apache.axis.AxisEngine.getService(AxisEngine.java:311)
    at org.apache.axis.MessageContext.setTargetService(MessageContext.java:756)
    at org.apache.axis.handlers.http.URLMapper.invoke(URLMapper.java:50)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.server.AxisServer.invoke(AxisServer.java:239)
    at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)

1 个答案:

答案 0 :(得分:1)

我在示例中看到的有趣区别是,在失败的那个中,您正在使用 thisJoinPoint 。实现该功能的类位于AspectJ运行时库(aspectjrt.jar)中。也许你没有在你的webapp的类路径上,并且第一个例子成功,因为它不需要它?