在练习 spring aop遇到“java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut myM

       遇到这个问题的时候是在, 使用 ssh 做spring aop 日志功能的时候遇到.

    转  原文地址

  在网上找了很多答案,都不知道再说什么,后来找到一个 跟我场景一样的,就是 在action中使用的baseAction

    在其中获取 运行时类的时候 报的错.  

          解决方法 

    加一个判断        替代以前直接获取的,

 if (getClass().getGenericSuperclass() instanceof ParameterizedType) {
			 this.clz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
			 .getActualTypeArguments()[0];
			 } else {
				 this.clz = (Class<T>) ((ParameterizedType) getClass().getSuperclass().getGenericSuperclass())
			 .getActualTypeArguments()[0];
			 }
public BaseAction() {
		// TODO Auto-generated constructor stub
		/* //获取 泛型
		 ParameterizedType type = (ParameterizedType)this.getClass().getGenericSuperclass();
		 //获取此类
		 this.clz = (Class)type.getActualTypeArguments()[0];*/
		 
		 if (getClass().getGenericSuperclass() instanceof ParameterizedType) {
			 this.clz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
			 .getActualTypeArguments()[0];
			 } else {
				 this.clz = (Class<T>) ((ParameterizedType) getClass().getSuperclass().getGenericSuperclass())
			 .getActualTypeArguments()[0];
			 }
		 
		 
		 try {
			 //为此类创建对象并赋值给 泛型t
			this.t = (T)this.clz.newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

猜你喜欢

转载自blog.csdn.net/bwddd/article/details/80670288