Spring AOP 问题,如何引用DAO层的方法? 10
publicclassUserSerImplimplementsUserSer{UserMapperum;@OverridepublicvoidDeleteTest(St...
public class UserSerImpl implements UserSer {
UserMapper um;
@Override
public void DeleteTest(String uid) {
um.selectAll();
// System.out.println("删除成功");
}
<!--beans 如下-->
<bean id="userService" class="app.home.service.impl.UserSerImpl"/>
<bean id="logBeforeAdvice" class="app.home.service.LogBeforeAdvice"/>
<bean id="logAfterAdvice" class="app.home.service.LogAfterAdvice"/>
<bean id="factory" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="app.home.service.UserSer"/>
<property name="target" ref="userService"/>
<property name="interceptorNames">
<list>
<!--<value>logBeforeAdvice</value>-->
<value>logAfterAdvice</value>
</list>
</property>
</bean>
异常
Exception in thread "main" java.lang.NullPointerException
at app.home.service.impl.UserSerImpl.DeleteTest(UserSerImpl.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy0.DeleteTest(Unknown Source)
at app.home.test.TestAOP.main(TestAOP.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 1
问题解决了,确实没有引用到Dao方法,学习了Spring AOP,太棒了~ 展开
UserMapper um;
@Override
public void DeleteTest(String uid) {
um.selectAll();
// System.out.println("删除成功");
}
<!--beans 如下-->
<bean id="userService" class="app.home.service.impl.UserSerImpl"/>
<bean id="logBeforeAdvice" class="app.home.service.LogBeforeAdvice"/>
<bean id="logAfterAdvice" class="app.home.service.LogAfterAdvice"/>
<bean id="factory" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="app.home.service.UserSer"/>
<property name="target" ref="userService"/>
<property name="interceptorNames">
<list>
<!--<value>logBeforeAdvice</value>-->
<value>logAfterAdvice</value>
</list>
</property>
</bean>
异常
Exception in thread "main" java.lang.NullPointerException
at app.home.service.impl.UserSerImpl.DeleteTest(UserSerImpl.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy0.DeleteTest(Unknown Source)
at app.home.test.TestAOP.main(TestAOP.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 1
问题解决了,确实没有引用到Dao方法,学习了Spring AOP,太棒了~ 展开
推荐于2017-10-06
展开全部
<script type="text/javascript">
Leaf leaf = new Leaf("Leaf D");
root.Add(leaf);
root.Remove(leaf);
root.Display(1);
Console.Read();
}
Leaf leaf = new Leaf("Leaf D");
root.Add(leaf);
root.Remove(leaf);
root.Display(1);
Console.Read();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
貌似你的UserMapper um; 没有初始化没有实例..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
贴出你的main方法看看
追问
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring.xml");
UserSer userService=(UserSer)context.getBean("factory");
userService.DeleteTest("test");
追答
at app.home.service.impl.UserSerImpl.DeleteTest(UserSerImpl.java:13)
最好的办法,打断点
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询