本人在java1.6环境下使用Struts2.2.3 + Spring 3.1 + hiberante 3.3搭建一系统,系统从dao层到业务逻辑层的配置都是用Annotation完成的,业务逻辑层使用Spring Annotatio如下:
@Service
@Scope("prototype")
@Transactional
public class UserManager extends EntityManager<User, Integer> {
}
在Spring实例化UserManager时回报如下异常:
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found finalize() method - using NO_OVERRIDE
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'equals' method: public boolean java.lang.Object.equals(java.lang.Object)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: public java.lang.String java.lang.Object.toString()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'hashCode' method: public native int java.lang.Object.hashCode()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.aopalliance.aop.Advice)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.springframework.aop.Advisor)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isFrozen()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.Advisor[] org.springframework.aop.framework.Advised.getAdvisors()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.TargetSource org.springframework.aop.framework.Advised.getTargetSource()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(int,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setTargetSource(org.springframework.aop.TargetSource)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setPreFiltered(boolean)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isProxyTargetClass()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setExposeProxy(boolean)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isExposeProxy()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isPreFiltered()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class[] org.springframework.aop.framework.Advised.getProxiedInterfaces()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advis2011-8-1 9:25:57 org.apache.catalina.startup.HostConfig deployDirectory
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.removeAdvisor(int) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvisor(org.springframework.aop.Advisor)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.replaceAdvisor(org.springframework.aop.Advisor,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(int,org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvice(org.aopalliance.aop.Advice)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.String org.springframework.aop.framework.Advised.toProxyConfigString()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class org.springframework.aop.TargetClassAware.getTargetClass()
[com.shj.order.utils.ReflectionUtils]-[WARN] MenuManager$$EnhancerByCGLIB$$93922635's superclass not ParameterizedType
所有业务逻辑层的实例化都会抱同样测异常,如果去掉@Transactional标签就不会报抱此异常,请Spring高手帮忙解决一下此问题。
@Service
@Scope("prototype")
@Transactional
public class UserManager extends EntityManager<User, Integer> {
}
在Spring实例化UserManager时回报如下异常:
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found finalize() method - using NO_OVERRIDE
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'equals' method: public boolean java.lang.Object.equals(java.lang.Object)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: public java.lang.String java.lang.Object.toString()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'hashCode' method: public native int java.lang.Object.hashCode()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.aopalliance.aop.Advice)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.springframework.aop.Advisor)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isFrozen()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.Advisor[] org.springframework.aop.framework.Advised.getAdvisors()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.TargetSource org.springframework.aop.framework.Advised.getTargetSource()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(int,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setTargetSource(org.springframework.aop.TargetSource)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setPreFiltered(boolean)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isProxyTargetClass()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setExposeProxy(boolean)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isExposeProxy()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isPreFiltered()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class[] org.springframework.aop.framework.Advised.getProxiedInterfaces()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advis2011-8-1 9:25:57 org.apache.catalina.startup.HostConfig deployDirectory
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.removeAdvisor(int) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvisor(org.springframework.aop.Advisor)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.replaceAdvisor(org.springframework.aop.Advisor,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(int,org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvice(org.aopalliance.aop.Advice)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.String org.springframework.aop.framework.Advised.toProxyConfigString()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class org.springframework.aop.TargetClassAware.getTargetClass()
[com.shj.order.utils.ReflectionUtils]-[WARN] MenuManager$$EnhancerByCGLIB$$93922635's superclass not ParameterizedType
所有业务逻辑层的实例化都会抱同样测异常,如果去掉@Transactional标签就不会报抱此异常,请Spring高手帮忙解决一下此问题。
x19881216 一定是个不咋地的开发人员
异常........没发现上面有出现log4j中debug报的Spring异常就不是系统异常吗??
我当你是不了解神马是异常和DUBUG而说出来的笨话x19881216 一定是个不咋地的开发人员
就算人家说得有什么不合理,需要这么说人家么?
至于这个异常
throws org.springframework.aop.framework.AopConfigException
取决于你用的是什么代理? JDK CGLIB 哪出的问题
getProxy(ClassLoader classLoader)方法
if (this.constructorArgs != null) {
proxy = enhancer.create(this.constructorArgTypes, this.constructorArgs);
}
else {
proxy = enhancer.create(); //执行这句是会开始抛出此异常
}
enhancer实例是cglib包中net.sf.cglib.proxy.Enhancer类的实例,create() 方法如下:
public Object create()
{
classOnly = false;
argumentTypes = null;
return createHelper(); //执行这句跑异常
}
createHelper() 方法如下:
private Object createHelper()
{
validate();
if(superclass != null)
setNamePrefix(superclass.getName());
else
if(interfaces != null)
setNamePrefix(interfaces[ReflectUtils.findPackageProtected(interfaces)].getName());
return super.create(KEY_FACTORY.newInstance(superclass == null ? null : superclass.getName(), ReflectUtils.getNames(interfaces), filter, callbackTypes, useFactory, interceptDuringConstruction, serialVersionUID));
}
我的能力就只能追踪到此了,希望那位高手,能帮我解决此问题,让我能对Spring框架更熟悉,谢谢
SPRING在实例化对象的时候,如果有@Transactional注解,就会生成代理了。所谓的代理,一般有两种,一个是JDK的动态代理,不过这个代理技术,局限于一定要是通过接口。
从你的DEBUG来看,你用的是一个叫CGLIB的代理方式,你可以去看下CGLIB的应用,是通过继承实现运行时动态代理的。其实代理技术,很多地方都用的到,你在HIBERNATE的延迟对象,也是同样的原理。
。
。才疏学浅,若有不对,请你纠正~
。
。楼主,既然你是来问的,就不要抱着群嘲的思想。CSDN是个学习社区,有高手,有新手。。
你说x19881216,是一个不咋地的开发人员。
你自己又如何呢?你为何不到SPRING的论坛上去问呢?(起码我开发遇到问题,多数会跑去官方上问,如果是BUG就上报)
extends NestedRuntimeException例外,那就是获取非法AOP配置参数抛出。
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
请问还需要在其中配置其他参数吗??
大家在喷之前还是应该自己先查找一下以上发言仅代表个人观点
throws org.springframework.aop.framework.AopConfigException
应该是和前面的public abstract ...连在一起的,属于方法签名的一部分,看来这个log是打出每一个被advise的方法的签名另外想说的是,有没有发生异常不是根据LOG级别来决定的,假如某天一时手误把catch块里本该写成log.error(e.getMessage())的写成了log.debug(e.getMessage()),或者不是手误,也许本意就是要忽略这个异常,所以采用debug级别,这种情况不能因为日志没记到debug就认为没有发生异常当然这个帖子算是个特例,那个throws Exception太具有迷惑性了
@Scope("prototype")
可以接受
@Transactional
无视
建议记录异常使用logger.warn(infoString, exceptionObj);
这样会输出exceptionObj的调用堆栈。不知楼主所云(就是楼主说的“异常”)
猜测如下:@Service
public class MenuManager {
@Autowired
private UserManager userManager;
}???现象的环境描述不清,浪费大家的时间和精力。
public class UserManager extends EntityManager<User, Integer> {
}
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'equals' method: public boolean java.lang.Object.equals(java.lang.Object)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: public java.lang.String java.lang.Object.toString()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Found 'hashCode' method: public native int java.lang.Object.hashCode()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Unable to apply any optimisations to advised method: protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.aopalliance.aop.Advice)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract int org.springframework.aop.framework.Advised.indexOf(org.springframework.aop.Advisor)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isFrozen()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.Advisor[] org.springframework.aop.framework.Advised.getAdvisors()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract org.springframework.aop.TargetSource org.springframework.aop.framework.Advised.getTargetSource()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException[/color[color=#FF0000]][org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvisor(int,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setTargetSource(org.springframework.aop.TargetSource)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setPreFiltered(boolean)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isProxyTargetClass()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.setExposeProxy(boolean)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isExposeProxy()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.isPreFiltered()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class[] org.springframework.aop.framework.Advised.getProxiedInterfaces()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advis2011-8-1 9:25:57 org.apache.catalina.startup.HostConfig deployDirectory
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.removeAdvisor(int) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvisor(org.springframework.aop.Advisor)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.replaceAdvisor(org.springframework.aop.Advisor,org.springframework.aop.Advisor) throws org.springframework.aop.framework.AopConfigException[/color[color=#FF0000]][org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(int,org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract void org.springframework.aop.framework.Advised.addAdvice(org.aopalliance.aop.Advice) throws org.springframework.aop.framework.AopConfigException
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract boolean org.springframework.aop.framework.Advised.removeAdvice(org.aopalliance.aop.Advice)
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.String org.springframework.aop.framework.Advised.toProxyConfigString()
[org.springframework.aop.framework.Cglib2AopProxy]-[DEBUG] Method is declared on Advised interface: public abstract java.lang.Class org.springframework.aop.TargetClassAware.getTargetClass()
看到异常在哪儿了吧,请没有仔细看过内容的,说这个是debug的在好好看看,我没标清异常是我的错,你没看清内容就干跳出来说话,就是你的错了
这个方法是生成一个代理。打印出的那些东西(你所谓的异常)就是spring使用反射机制生成代理过程中查找并优化方法的过程,最后那一个警告是因为你的EntityManager<User, Integer> 是个带参数化的类,而你继承了他却没有明确指定参数化类型
如果你还要继续鄙视我的话,我不介意
没人抛出,自己去看看API,那个只是一个方法的完整签名(包括修饰、返回值、参数、可能会抛的异常)看API
楼主是个专业的程序员,楼主的第一个程序是 holy shit !