【发布时间】:2014-11-13 09:26:55
【问题描述】:
假设我在 spring 配置中指定了一个类,如下所示:
<bean id="playerAccountDao" class="com.prcj.db.dao.PlayerAccountDaoImpl" scope="prototype">
<property name="playerDao" ref="playerDao" />
</bean>
<bean id="commonPlayerDao" class="com.prcjcommons.db.dao.PlayerDaoImpl" scope="prototype">
<property name="sessionFactory" ref="siteSessionFactory" />
</bean>
在上面的配置中,我将该 bean 注入到 playerAccountDao 实例中,如果我尝试从 playerAccountDao 调用 playerDao bean 的方法,则会调用一些方法:
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 57
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43
Method.invoke(Object, Object...) line: 606
AopUtils.invokeJoinpointUsingReflection(Object, Method, Object[]) line: 310
ReflectiveMethodInvocation.invokeJoinpoint() line: 182
ReflectiveMethodInvocation.proceed() line: 149
TransactionInterceptor.invoke(MethodInvocation) line: 106
ReflectiveMethodInvocation.proceed() line: 171
JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 204
$Proxy151.selectRecordList(Long, Integer, PlayerStatus, UserCategory, Date, Date, int, int) line: not available
spring 为什么要这样做?为什么不直接调用DAO 方法呢?
【问题讨论】:
-
Spring 提供了 AOP 特性,这就是为什么你这样的堆栈跟踪