只供参考:无需评论。spring2.0
1,定义自己的业务类。
接口:
public interface Test {
public void addMetgod();
}
实现:
public class Testimpl implements Test {
public void addMetgod() {
System.out.println("---addMethod方法的实现-----");
}
}
2,定义切面,也就是验证方法:
接口:
public interface MySecurityManager {
public void security();
}
实现:
public class MySecurityManagerImpl implements MySecurityManager {
public void security() {
System.out.println("-----调用security方法-------");
}
}
3配置:applicationContext-aop.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.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName" default-lazy-init="true">
<aop:aspectj-autoproxy/>
<bean id = "mySecurityManager" class = "<包名>.impl.MySecurityManagerImpl" ></bean >
<aop:config>
<aop:aspect ref="mySecurityManager">
<aop:before pointcut-ref="needse" method="security"/>
<aop:pointcut id="needse" expression="execution(* "<包名>.Test.add*(..))"/>
</aop:aspect>
</aop:config>
<bean id = "test" class = ""<包名>.impl.Testimpl" ></bean >
</beans>
4,测试:
public class TestAop {
private static Test test;
static {
ApplicationContext conn = new ClassPathXmlApplicationContext(
new String[] { "classpath:aop-applicationContext-aop.xml" });
test = (Test) conn.getBean("test");
}
public static void main(String[] args) {
test.addMetgod();
}
}
结果:
-----调用security方法-------
---addMethod方法的实现-----
end。。。
分享到:
相关推荐
spring-aop标签和配置文件两种方式实例,spring要求2.5及以上
spring实现aop、ioc,注入,拦截demo,包含spring所需的所有jar
最简单的SpringAOP入门案例,对于配置文件有详细的解释,适合初学者去理解AOP编程
在Spring1.2或之前的版本中,实现AOP的传统方式就是通过实现Spring的AOP API来定义Advice,并设置代理对象。Spring根据Adivce加入到业务流程的时机的不同,提供了四种不同的Advice:Before Advice、After Advice、...
一个机遇Spring3的入门小案例,里面主要简单演示了Spirng配置文件如何配置自动扫描包,控制类、服务类、Dao类如何加注解,被IOC扫描装入容器中。还有AOP例子的演示,有before after afterreturn afterthrow,还有...
J2EE_Spring之AOP与依赖注入例子, Spring包请自己添加。 注意下面两个配置文件: web.xml Spring配置文件applicationContext.xml
使用Spring配置文件实现AOP 20.aspectj的切入点语法定义细节 21.搭建和配置Spring与jdbc整合的环境 22.Spring集成的jdbc编码和事务管理 23.使用Spring注解方式管理事务与传播行为详解 24.使用Spring配置文件...
第2章:通过一个简单的例子展现开发Spring Web应用的整体过程,通过这个实例,读者可以快速跨入Spring Web应用的世界。 第3章:讲解Spring IoC容器的知识,通过具体的实例详细地讲解IoC概念。同时,对Spring框架...
1.5 使用配置文件配置容器 1.5.1 问题描述 1.5.2 解决方案 1.5.3 实现方法 1.6 小结 第2章 Spring简介 2.1 Spring Framework 2.1.1 Spring的模块介绍 2.1.2 ...
Spring MVC以'spring-webmvc.jar' 和'spring-webmvc-portlet.jar'文件形式在发行包的 lib/modules 目录中存在。 另外,对Struts 1.x的支持被独立成 'spring-webmvc-struts.jar'。 注意:经常被使用的的Spring的...
spring-2 演示了外部配置文件的引入(connection),spel(spring el)表达式 ,静态工厂方式及实例工厂方式及factorybean方式创建bean, spring的生命周期及BeanPostProcessor的使用,注解方式创建bean 及使用...
1.5 使用配置文件配置容器 1.5.1 问题描述 1.5.2 解决方案 1.5.3 实现方法 1.6 小结 第2章 Spring简介 2.1 Spring Framework 2.1.1 Spring的模块介绍 2.1.2 ...
二、 建立spring的配置文件 8 三、 引入spring的jar包 8 四、 测试代码: 8 五、 注意接口的使用: 8 第五课:IOC(DI)配置及应用 9 一、 什么是IOC、DI 9 二、 编辑xml文件时,没有提示 9 三、 注入类型(Injecting ...
2.2 Spring配置文件 7 2.3 Spring API 8 3 Spring基本功能详解 8 3.1 SpringIOC 8 3.2别名Alias 11 别名拓展: 11 3.3 Spring容器内部对象的创建 12 Spring容器内部对象创建拓展: 12 3.3.1使用类构造器实例化(默认...
1.5 使用配置文件配置容器 1.5.1 问题描述 1.5.2 解决方案 1.5.3 实现方法 1.6 小结 第2章 Spring简介 2.1 Spring Framework 2.1.1 Spring的模块介绍 2.1.2 Spring的...
几乎全部涵盖了spring框架的整个使用,包括配置文件、IOC、AOP、jdbc、事务管理、注解等,注释也比较多,简单明了。
Hibernate: 第一课:第一个hibernate项目 第二课:测试实体对象的生命周期 第三课:hibernate基本映射 第四课:hibernate多对一关联映射 ...................... ...第五课:spring对AOP的只是(采用配置文件的方式)
2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的支持 2.4. 中间层 2.4.1. 在XML里更为简单的声明性事务配置 2.4.2. JPA 2.4.3. 异步的JMS 2.4.4. JDBC 2.5. Web层 2.5.1. Spring MVC的表单标签库 ...