求解!!简单AOP的实现

BestFIzz 2017-03-18 03:18:54
我就是想实现一个非常简单的AOP,但不知为什么运行一直报错,下面给出代码,求大神解惑一波啊~非常感谢!
User类:
package aop;
public class User{
public void login(){}
public void logout(){}
}

LoginServer类:
package aop;
public class LogService {
public void enter(){
System.out.println("Someone login---");
}
public void leave(){
System.out.println("Someone logout---");
}
}

主类UserApp:
package aop;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserApp {
public static void main(String[] args){

ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("Login.xml");
User user = (User) ctx.getBean("liming");
user.login();
user.logout();
}
}

XMl文件Login.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<bean id="liming" class="aop.User"/>
<bean id="log" class="aop.LogService"/>
<aop:config>
<aop:aspect ref="log">
<aop:before method="enter" pointcut="execution(* aop.User.login(..))" />
<aop:after method="leave" pointcut="execution(* aop.User.logout(..))" />
</aop:aspect>
</aop:config>

</beans>

就这么多代码,想通过AOP将enter和leave输出,但一直报错,错误指向引用XMl文件的那段代码ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("Login.xml");
求解~~~
...全文
135 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
BestFIzz 2017-03-18
  • 打赏
  • 举报
回复
都没有给力的兄弟吗

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧