$$ 和 <生成>在 Java 堆栈跟踪中是什么意思?

2022-09-01 17:33:25

我经常得到像这样的堆栈跟踪(请参阅箭头以获取令人困惑的行):

org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
                at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:164)
                at org.springframework.orm.hibernate5.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:741)
                at org.springframework.orm.hibernate5.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:589)
                at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
                at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
                at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485)
                at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
                at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
                at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
--------->      at com.panpwr.admin.services.detector.SimpleDetectorPersistenceService$$EnhancerBySpringCGLIB$$66303639.saveComplexRuleAndActionTemplates(<generated>)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
...
...
...

符号是什么意思,这行中的“生成”是什么?$$com.panpwr.admin.services.detector.SimpleDetectorPersistenceService$$EnhancerBySpringCGLIB$$66303639.saveComplexRuleAndActionTemplates(<generated>)

为什么它只说执行的方法,而不说其中的行号?


答案 1

$是类名中允许使用的字符。

这个名字暗示它是一个类,它是由Spring框架使用CGLIB在运行时动态生成的。SimpleDetectorPersistenceService$$EnhancerBySpringCGLIB$$66303639

它们使用和数字偏移量使此类名唯一,以避免与现有类发生冲突。$$

跟踪跟踪中的字符串也是由 CGLIB 生成的:
当 CGLIB 在运行时创建一个类时,它用作源文件名称的占位符。然后,堆栈跟踪仅打印此字符串,而不是实际的源文件和行号。(<generated>)<generated>


答案 2

推荐