建设银行网站上不去网络营销应该这样做
2026/3/27 1:52:19 网站建设 项目流程
建设银行网站上不去,网络营销应该这样做,销售网站开发,网站运营专员做六休一Spring对AOP的实现包括以下3种方式#xff1a; 第一种方式#xff1a;Spring框架结合AspectJ框架实现的AOP#xff0c;基于注解方式。第二种方式#xff1a;Spring框架结合AspectJ框架实现的AOP#xff0c;基于XML方式。第三种方式#xff1a;Spring框架自己实现的AOP第一种方式Spring框架结合AspectJ框架实现的AOP基于注解方式。第二种方式Spring框架结合AspectJ框架实现的AOP基于XML方式。第三种方式Spring框架自己实现的AOP基于XML配置方式。实际开发中都是SpringAspectJ来实现AOP。所以我们重点学习第一种和第二种方式。什么是AspectJEclipse组织的一个支持AOP的框架。AspectJ框架是独立于Spring框架之外的一个框架Spring框架用了AspectJAspectJ项目起源于帕洛阿尔托Palo Alto研究中心缩写为PARC。该中心由Xerox集团资助Gregor Kiczales领导从1997年开始致力于AspectJ的开发1998年第一次发布给外部用户2001年发布1.0 release。为了推动AspectJ技术和社团的发展PARC在2003年3月正式将AspectJ项目移交给了Eclipse组织因为AspectJ的发展和受关注程度大大超出了PARC的预期他们已经无力继续维持它的发展。15.4.1 准备工作使用SpringAspectJ的AOP需要引入的依赖如下!--spring context依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion6.0.0-M2/version/dependency!--spring aop依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-aop/artifactIdversion6.0.0-M2/version/dependency!--spring aspects依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-aspects/artifactIdversion6.0.0-M2/version/dependencySpring配置文件中添加context命名空间和aop命名空间?xml version1.0 encodingUTF-8?beansxmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd/beans15.4.2 基于AspectJ的AOP注解式开发实现步骤第一步定义目标类以及目标方法packagecom.powernode.spring6.service;// 目标类publicclassOrderService{// 目标方法publicvoidgenerate(){System.out.println(订单已生成);}}第二步定义切面类packagecom.powernode.spring6.service;importorg.aspectj.lang.annotation.Aspect;// 切面类AspectpublicclassMyAspect{}第三步目标类和切面类都纳入spring bean管理在目标类OrderService上添加**Component注解。在切面类MyAspect类上添加Component**注解。第四步在spring配置文件中添加组建扫描?xml version1.0 encodingUTF-8?beansxmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd!--开启组件扫描--context:component-scanbase-packagecom.powernode.spring6.service//beans第五步在切面类中添加通知packagecom.powernode.spring6.service;importorg.springframework.stereotype.Component;importorg.aspectj.lang.annotation.Aspect;// 切面类AspectComponentpublicclassMyAspect{// 这就是需要增强的代码通知publicvoidadvice(){System.out.println(我是一个通知);}}第六步在通知上添加切点表达式packagecom.powernode.spring6.service;importorg.aspectj.lang.annotation.Before;importorg.springframework.stereotype.Component;importorg.aspectj.lang.annotation.Aspect;// 切面类AspectComponentpublicclassMyAspect{// 切点表达式Before(execution(* com.powernode.spring6.service.OrderService.*(..)))// 这就是需要增强的代码通知publicvoidadvice(){System.out.println(我是一个通知);}}注解Before表示前置通知。第七步在spring配置文件中启用自动代理?xml version1.0 encodingUTF-8?beansxmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd!--开启组件扫描--context:component-scanbase-packagecom.powernode.spring6.service/!--开启自动代理--aop:aspectj-autoproxyproxy-target-classtrue//beansaop:aspectj-autoproxy proxy-target-class“true”/ 开启自动代理之后凡事被代理的目标类Target Class即那些被切点表达式匹配到的、需要增强的 Bean都会生成代理对象。proxy-target-class“true” 表示采用cglib动态代理。proxy-target-class“false” 表示采用jdk动态代理。默认值是false。即使写成false当没有接口的时候也会自动选择cglib生成代理类。测试程序packagecom.powernode.spring6.test;importcom.powernode.spring6.service.OrderService;importorg.junit.Test;importorg.springframework.context.ApplicationContext;importorg.springframework.context.support.ClassPathXmlApplicationContext;publicclassAOPTest{TestpublicvoidtestAOP(){ApplicationContextapplicationContextnewClassPathXmlApplicationContext(spring-aspectj-aop-annotation.xml);OrderServiceorderServiceapplicationContext.getBean(orderService,OrderService.class);orderService.generate();}}

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询