javac编译AspectJ测试类,提示找不到jar包,但实际已经导入

ohlala 发布于 2019/11/22 12:29
阅读 33
收藏 0

win10 Eclipse 运行AspectJ的案例,提示找不到主类

javac编译了一下测试类,提示无法找到相关jar包,

这是已经导入的jar

aspectjrt.jar
aspectjtools.jar
aspectjweaver.jar
org.aspectj.matcher.jar
spring-aop-3.2.0.RELEASE.jar
spring-aspects-3.2.0.RELEASE.jar
spring-beans-3.2.0.RELEASE.jar
spring-context-3.2.0.RELEASE.jar
spring-context-support-3.2.0.RELEASE.jar
spring-core-3.2.0.RELEASE.jar

报错截图

-------以下是代码--------


*personServer.java*

public interface personServer {

        public void save(String uname,int age); 

}

*personServerImpl.java*

public class personServerImpl implements personServer{

    @Override
    public void save(String uname, int age) {
        // TODO Auto-generated method stub
         int a=0;
            age= age/a;//打开上面两行报错,可触发异常通知
            System.out.println("come in personServerImpl save method...");
    }

}

*AspectIntercepter.java*

import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

public class AspectIntercepter {

    @Pointcut(value="execution(*personServerImpl.*(...))")
    private void ponitCut() {   
    }

    //环绕通知
    @Around(value="pointCut()")
    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("Around进入环绕通知");
        Object object=pjp.proceed();
        System.out.println(pjp.getThis()+"操作结束,推出方法");
        return pjp;
    }
    @Before(value="pointCut()")
    public void doAcceseeCheck(JoinPoint joinPoint) {
        System.out.println("@before前置通知:"+Arrays.toString(joinPoint.getArgs()));
    }
    @AfterThrowing(value="pointCut()",throwing="ex")
    public void doAfterThrow(JoinPoint joinPoint,Throwable ex) {
        System.out.println("@AfterThrowing例外通知"+Arrays.toString(joinPoint.getArgs()));
        System.out.println("@AfterThrowing异常信息:"+ex);
    }
    @After(value="pointCut()")
    public void after() {
        System.out.println("@After后置通知");       
    }
    @AfterReturning(value="pointCut()")
    public void doAfter() {
        System.out.println("@AfterReturning最终通知...end");
    }


}

*aop.xml*
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

aop:aspectj-autoproxy/aop:aspectj-autoproxy

*SpringAopTest.java*


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringAopTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

         ApplicationContext context=new ClassPathXmlApplicationContext("cn/hxex/springcore/aop/aop.xml");
         personServer bean=(personServer)context.getBean("personServiceBean");
         bean.save("badMonkey", 23); 
     }

}
 

加载中
返回顶部
顶部