- 浏览: 519493 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
Zhouchenyu:
谢谢
1、junit学习之junit的基本介绍 -
wenjieyatou:
1、junit学习之junit的基本介绍 -
huabengao:
不错 很好
1、junit学习之junit的基本介绍 -
prayjourney:
写的不错,很有启发!
1、junit学习之junit的基本介绍 -
wangzhenyu1260:
assertEqualspublic static void ...
1、junit学习之junit的基本介绍
1、新建一个java的工程,导入spring需要的jar包与开发切面需要的jar包。
dist\spring.jar
lib\jakarta-commons\commons-logging.jar
如果使用了切面编程(AOP),还需要下列jar文件
lib/aspectj/aspectjweaver.jar和aspectjrt.jar
lib/cglib/cglib-nodep-2.1_3.jar
如果使用了JSR-250中的注解,如@Resource/@PostConstruct/@PreDestroy,还需要下列jar文件
lib\j2ee\common-annotations.jar
2、Person.java
2、PersonService.java 与PersonServiceBean.java
PersonService.java
PersonServiceBean.java
3、MyInterceptor.java
4 在src下对beans.xml进行配置
5、测试类
dist\spring.jar
lib\jakarta-commons\commons-logging.jar
如果使用了切面编程(AOP),还需要下列jar文件
lib/aspectj/aspectjweaver.jar和aspectjrt.jar
lib/cglib/cglib-nodep-2.1_3.jar
如果使用了JSR-250中的注解,如@Resource/@PostConstruct/@PreDestroy,还需要下列jar文件
lib\j2ee\common-annotations.jar
2、Person.java
package cn.ehoo.bean; /** * @author whp * @Email whp@ehoo.cn * @Jan 4, 2011 * */ public class Person { private Long id; private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
2、PersonService.java 与PersonServiceBean.java
PersonService.java
package cn.ehoo.service; import cn.ehoo.bean.Person; /** *@author whp *@Email whp@ehoo.cn *@Jan 4, 2011 * */ public interface PersonService { public void save(Person person); }
PersonServiceBean.java
package cn.ehoo.service.impl; import cn.ehoo.bean.Person; import cn.ehoo.service.PersonService; /** * @author whp * @Email whp@ehoo.cn * @Jan 4, 2011 * */ public class PersonServiceBean implements PersonService { private String user; public String getUser() { return user; } public void setUser(String user) { this.user = user; } public PersonServiceBean() { } public PersonServiceBean(String user) { super(); this.user = user; } public void save(Person person) { System.out.println("执行PerServiceBean的save方法"); //throw new RuntimeException("======"); } }
3、MyInterceptor.java
package cn.ehoo.service.impl; import org.aspectj.lang.ProceedingJoinPoint; /** * @author whp * @Email whp@ehoo.cn * @Jan 4, 2011 * */ public class MyInterceptor { private void anyMethod() { } public void doAccessCheck() { System.out.println("执行前置通知"); } public void doReturnCheck() { System.out.println("执行后置通知"); } public void doReleaseAction() { System.out.println("执行最终通知"); } public void doExceptionAction() { System.out.println("执行例外通知"); } public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { System.out.println("执行环绕通知"); Object retule = pjp.proceed(); System.out.println("退出环绕通知"); return retule; } }
4 在src下对beans.xml进行配置
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean name="personService" class="cn.ehoo.service.impl.PersonServiceBean" /> <bean name="myInterceptor" class="cn.ehoo.service.impl.MyInterceptor" /> <aop:config> <aop:aspect id="myaop" ref="myInterceptor"> <aop:pointcut id="mycut" expression="execution(* cn.ehoo.service.impl.PersonServiceBean.*(..))" /><!--切入点表达式 --> <aop:before pointcut-ref="mycut" method="doAccessCheck" /><!--前置通知 --> <aop:after-returning pointcut-ref="mycut" method="doReturnCheck" /><!--后置通知 --> <aop:after-throwing pointcut-ref="mycut" method="doExceptionAction" /><!--例外通知 --> <aop:after pointcut-ref="mycut" method="doReleaseAction" /><!--执行最终通知 --> <aop:around pointcut-ref="mycut" method="doBasicProfiling" /><!--执行环绕通知--> </aop:aspect> </aop:config> </beans>
5、测试类
package junit.test; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.ehoo.bean.Person; import cn.ehoo.service.PersonService; /** * @author whp * @Email whp@ehoo.cn * @Jan 4, 2011 * */ public class AOPTest { static PersonService personService; @BeforeClass public static void setUpBeforeClass() throws Exception { AbstractApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml"); personService = (PersonService) cxt.getBean("personService"); } /** * @author whp * @Email whp@ehoo.cn * @Jan 4, 2011 * */ public static void main(String[] args) { try { setUpBeforeClass(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Test public void saveTest() { personService.save(new Person()); } @AfterClass public static void tearDownAfterClass() throws Exception { } }
- springAopXML.rar (7.7 KB)
- 下载次数: 23
发表评论
-
Spring MVC控制器之SimpleFormController使用
2013-10-31 15:49 3400SimpleFormController已经 ... -
Spring MVC控制器之ParameterizableViewController使用
2013-10-30 15:36 1678这几天在看walker讲的Spring MVC视频教程,在网 ... -
spring 注解Autowired、service、Autowired 的使用
2013-05-30 16:43 6269在spring中可以通过service来把一个业务层的类交 ... -
spring配置文件名字问题
2011-04-27 09:48 15699在做java开发时,如果用到spring,那么在做j2ee开发 ... -
Spring MVC demo
2011-04-26 09:14 160411、新建一web项目 springmvc,并在lib目录中加入 ... -
Struts1.2+Spring2.5+Hibernate3.2 开发时不能用Spring的AOP对继承DispatchAcion的Action里的方法进行拦截
2011-02-12 17:08 1833使用SSH组合开发时,在把所有的Action都交给S ... -
struts1.3+spring2.5+hibernate3.3 组合开发 annotation实现
2011-01-06 14:55 1579在本例中用struts1.3+spring2.5+hibern ... -
spring+JdbcTemple+dbcp数据源 的xml实现
2011-01-06 11:21 1714在本例中使用spring为我们提供的jdbc的模版来对spri ... -
Spring中注解事务方面的问题
2011-01-06 10:26 3732我们可以在spring的配置 ... -
spring+JdbcTemple+dbcp数据源 的注解实现
2011-01-05 14:01 2147在本例中使用spring为我们提供的jdbc的模版来对spri ... -
Spring注解方式实现AOP demo
2011-01-04 15:39 64191、新建一个java的工程,导入spring需要的jar包与开 ... -
CGLIB实现代理demo
2011-01-04 11:43 2472在上片文章里说了如何用jdk自带的类Proxy来实现代理,但是 ... -
Proxy实现代理demo
2011-01-04 10:57 1233save、update、insert方法,只有在用户登录后才能 ... -
Spring是轻量级框架还是重量级框架
2010-12-31 09:56 5257主要看使用了多少服务.使用的服务越多.对于spring容器来说 ... -
使用spring的好处
2010-12-31 09:15 1017a. 降低组件之间的耦合度,实现软件各层之间的解耦。如我们的P ... -
Spring Bean 的作用域
2010-12-30 17:52 946在spring中bean一共有5个作用域。 1、single ... -
Spring 注解 方式配制的小demo
2010-12-30 17:24 13951、新建一个Web程序 在程序中引入Spring所需要的 ... -
Spring xml 方式配制的小demo
2010-12-30 17:19 10561、新建一个Web程序 在程序中引入Spring所需要的 ...
相关推荐
spring xml 实现aop切面编程 内附注释,希望对入门的新手有帮助
SpringAOP学习笔记以及四个可运行的Demo,涵盖经典代理模式、基于注解、基于xml配置这3方面的Demo
spring aop 采用注解定义以及xml定义,在java四层结构中无缝实现
详细讲解了aop的xml配置和注解的方式配置,和本人的博客想应
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/aop] Offending resource: class path resource [beans.xml] at org....
基于注解与 XML 配置文件两种形式的 AOP demo。 基于 xml 配置文件的 aop 管理 ```xml <!-- 配置切面的bean --> <bean id="loggingAspect" class="com.jas.aop.xml.LoggingAspect"/> <aop:config> <!...
Spring demo to demonstrate aop using aspectj with xml based configuration.
声明式事务管理也有两种常用的方式,一种是基于tx和aop名字空间的xml配置文件,另一种就是基于@Transactional注解。显然基于注解的方式更简单易用,更清爽。spring注解事务实现demo
压缩包中函数Spring AOP开发时使用注解和xml文件配置demo
基于 MethodBeforeAdvice、AfterReturningAdvice 利用 Spring Api 定义前、后置处理方法,并通过代理工厂类获取代理对象(代码或Xml配置实现) 2.ProxyFactoryBean 显式地设置 Advisors、Advice、Target等(基于代理...
jdkproxy-transaction,jdkproxy-salary,day02-itheima11-spring-08-cglibproxy,day02-itheima11-spring-09-aop.xml,day02-itheima11-spring-10-aop.xml.advice,day02-itheima11-spring-11-aop.xml.exception等Demo
资料包含day03-itheima11-spring-01-aop-xml-methodinvocation-count,day03-itheima11-spring-02-aop-xml-privilege,day03-itheima11-spring-03-aop-xml-salary,day03-itheima11-spring-04-aop-annotation,day03...
sring aop的方式有两种:(1)xml文件配置方式(2)注解的方式实现,我们可以先通过一个demo认识spring aop的实现,然后再对其进行详细的解释。
视频详细讲解,需要的小伙伴自行百度网盘下载,链接见附件,永久有效。...2、MyBatis的Dao层实现方式 3、MyBatis的映射文件深入 4、MyBatis的核心文件深入 5、MyBatis的多表操作 6、MyBatis的注解开发
ssh整合demo 整合, structs 附带了多个测试页面可以跳转,写了一个简单action,structs.xml 使用了模糊匹配, spring 注释方式 注入依赖,xml方式实现aop,hibernate 配置好数据库,可自动生成表,标准的model ,dao...
1.创建第一个 Spring 程序案例 2.Spring IoC案例 ...5.Spring xml 配置案例 6.Spring Annontation案例 7.Spring 泛型依赖注入案例 8.Spring AOP案例 9.Spring JDBCTemplate案例 10.Spring 事务案例
简易的spring demo,包含了bean自动装配,泛型依赖注入,Aop切面编程的实例
|哨兵||集群||Lettuce)、RocketMQ-demo(RocketMQ,实现消息的发送和接收)、RocketMQ-shop-project(RocketMQ模拟电商网站购物)、Spring Security(实现动态权限的实现||Spring Cloud Security OAuth2)、websocket...
spring demo,包含了bean的自动装配,aop以及泛型依赖注入的实现,jdbc和jdbc的xml配置以及注解两种实现方式。每个功能的程序入口为各自包里面的main方法