动态代理AOP的配置
来源:互联网 发布:php正则$1 编辑:程序博客网 时间:2024/06/09 23:33
Common.Java
- package com.aspect;
- public class Common {
- public void fn()
- {
- System.out.println("****************");
- }
- public void tc()
- {
- System.out.println("|||||||||||||||||");
- }
- }
check.java
- package com.aspect;
- public class Check {
- public void check()
- {
- System.out.println("验证!!!!!!!!!!!");
- }
- }
web.xml配置文件如下
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.5"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
applicationContext.xml配置文件如下
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
- <bean id="common" class="com.aspect.Common"/>
- <bean id="check" class="com.aspect.Check"/>
- <aop:config>
- <aop:aspect id="deal" ref="check">
- <aop:pointcut id="target" expression="execution(* com.aspect.Common.*(..))"/>
- <aop:before method="check" pointcut-ref="target"/>
- </aop:aspect>
- </aop:config>
- </beans>
测试类Client.java
- package com.aspect;
- import org.springframework.beans.factory.BeanFactory;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import org.springframework.context.support.FileSystemXmlApplicationContext;
- public class Client {
- public static void main(String[] args) {
- ApplicationContext factory=new ClassPathXmlApplicationContext("applicationContext.xml");
- }
- }
- //下面这句也可以
- // BeanFactory factory=new ClassPathXmlApplicationContext("applicationContext.xml");
- Common c=(Common) factory.getBean("common");
- c.fn();
- c.tc();
- }
- }
结果如下:
- 验证!!!!!!!!!!!
- ****************
- 验证!!!!!!!!!!!
- |||||||||||||||||
导入的5个jar包如下:
aopalliance.jar
aspectjweaver.jar
cglib-nodep-2.2.3.jar
commons-logging-1.0.4.jar
org.springframework.aop-3.1.1.RELEASE.jar
org.springframework.asm-3.1.1.RELEASE.jar
org.springframework.beans-3.1.1.RELEASE.jar
org.springframework.context-3.1.1.RELEASE.jar
org.springframework.core-3.1.1.RELEASE.jar
org.springframework.expression-3.1.1.RELEASE.jar
0 0
- 动态代理AOP的配置
- Spring AOP配置 动态代理
- Spring AOP:静态代理、动态代理和几种常见的aop配置
- java的动态代理(AOP)
- Aop的jdk动态代理
- Java AOP 动态代理 配置表达式
- Aop 代理 动态代理
- aop代理类的配置
- AOP的底层实现--JDK动态代理,CGLIB动态代理
- java学习之路----静态代理---动态代理-----AOP的前奏(AOP也是动态代理)
- Spring 的 动态代理:AOP原理
- spring AOP的基础:动态代理
- Spring_AOP_Proxy AOP动态代理的实现
- Spring_AOP_Proxy AOP动态代理的实现 .
- Spring AOP 的实现原理----动态代理
- Java动态代理模拟spring的AOP
- AOP 动态代理 的 源码分析
- JAVA AOP 动态代理 的例子
- iOS网络框架AFNetworking3.1.0底层源码解读
- Nodejs https reqest by proxy(node通过代理进行https请求)
- 树形结构 数据库表设计
- Universal-第三方开源框架介绍
- 重复绑定mouseover和mouseout事件
- 动态代理AOP的配置
- L03HTML5学习视频CSS3基础
- [Mapbox GL]添加一张图片
- 应用的包名
- GO 语言错误处理
- 欢迎使用CSDN-markdown编辑器
- Outlook写邮件时插入表情符号
- AFNetworking之于https认证
- c++11中的using关键字