当前位置: 首页 > news >正文

空间设计网站推荐seo高级

空间设计网站推荐,seo高级,做招聘网站怎么办营业执照,怎么删掉安装的wordpress目录 AOP概念代理模式引出AOP实现方式xml方式实现注解方式实现 AOP 概念 事务管理:比如可以抽取try catch的重复代码 日志监控:比如业务逻辑前后打印关于当前订单数量的日志,了解业务做了什么 性能监控:比如业务前后打印时间&…

目录

      • AOP
        • 概念
        • 代理模式引出
        • AOP实现方式
          • xml方式实现
          • 注解方式实现

AOP

概念

在这里插入图片描述
事务管理:比如可以抽取try catch的重复代码
日志监控:比如业务逻辑前后打印关于当前订单数量的日志,了解业务做了什么
性能监控:比如业务前后打印时间,相减可查看业务跑完所需时间

代理模式引出

在这里插入图片描述
用aop实现扩展功能,
aop用代理模式实现,但是代理模式里的扩展功能还是需要我们自己写,

静态代理:相当于一个中介只代理一个固定的房东的房源,基本不用
动态代理:默认没有,使用的时候动态生成

AOP:以上大方向
SpringAOP:AOP的spring实现方式,用动态代理方式实现。它的实现方式又有两种:jdk,CGLIB,spring自动选择用其中哪种方式,代理类自动生成也不用管,有接口的时候默认使用jdk,没有的时候用cglib(第三方jar包),现在一般service都有接口

AOP实现方式

xml方式实现

1.编写TxManager用来提供业务逻辑外的扩展功能 - 如事务管理

/*我们自己的扩展功能*/
public class TxManager {public void open (){System.out.println("开启事务");}public void commit (){System.out.println("提交事务");}public void rollback(Throwable e){e.printStackTrace();//处理异常System.out.println("回滚事务");}public void close(){System.out.println("关闭事务");}public void around(ProceedingJoinPoint point){try {open();point.proceed();//执行真正的业务commit();} catch (Throwable e) {e.printStackTrace();rollback(e);} finally {close();}}
}

2.准备xmlAOP环境,在Spring配置文件中引入头支持以支持aop标签

SpringTest-Context.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.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

3.配置的三要素
何时,如在业务的执行前、后、catch
何地,指的是在哪一个方法
做什么,执行我们自定义扩展业务类的方法

面向切面编程,面向扩展功能编程
在这里插入图片描述
其他
spring通过动态代理实现aop,配置aop后只能注入接口,通过接口找到被引用的代理类,Spring容器中就只有代理类没有实现类,

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration//回到当前类的包下 查找当前类名-Context.xml的配置文件
public class SpringTest {@AutowiredIUserService userService;@Testpublic void testUser(){System.out.println(userService.getClass());}
}

SpringTest-Context.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.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><bean id="userService" class="cn.itsource._03aopxml.service.impl.UserServiceImpl"/><bean id="departmentService" class="cn.itsource._03aopxml.service.impl.DepartmentServiceImpl"/><!--将扩展功能交给Spring容器管理,方便AOP使用--><bean id="txManager" class="cn.itsource._03aopxml.TxManager"/><!--SpringAOP的核心配置--><aop:config><!--配置切点  配置何地 ==在哪一个方法执行expression:表达式  通过表达式,我们找在哪一个方法执行第一个*:任意返回值I*Service:所有以I开头 Service结尾的类(里面的所有方法都加上事物)第三个*:任意方法save(..):任意参数--><!--execution(* cn.itsource._03aopxml.service.impl.UserServiceImpl.save(..))execution(* cn.itsource._03aopxml.service.impl.UserServiceImpl.*(..))--><aop:pointcut id="txPoint" expression="execution(* cn.itsource._03aopxml.service.I*Service.*(..))"/><!--配置切面   --><aop:aspect ref="txManager"><!--配置前置通知 配置何时做什么--><!--<aop:before method="open" pointcut-ref="txPoint"/>--><!--配置后置通知--><!--<aop:after-returning method="commit" pointcut-ref="txPoint"/>--><!--配置异常通知--><!--<aop:after-throwing method="rollback" pointcut-ref="txPoint" throwing="e"/>--><!--配置最终通知--><!--<aop:after method="close" pointcut-ref="txPoint"/>--><!--配置环绕通知  环绕通知一行顶上面四行--><aop:around method="around" pointcut-ref="txPoint"/></aop:aspect></aop:config>
</beans>

测试

详细见工程代码

注解方式实现

A 引入容器扫描头 Spring AOP

SpringTest-Context.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:context="http://www.springframework.org/schema/context"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.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!--开启Spring注解扫描--><context:component-scan base-package="cn.itsource._04aopanno"/><!--开启SpringAOP 注解扫描--><aop:aspectj-autoproxy/></beans>

后面的几步,都是在TxManager中完成
B 将扩展业务交给容器管理 @Component
C 申明pointcut,@Pointcut,需要提供一个空方法
D 配置各种通知
只用@Around环绕通知,其他四种通知不能确定执行顺序,

/*我们自己的扩展功能*/
@Component //组件 把当前类交给Spring容器管理
@Aspect //== <aop:aspect ref="txManager"> 配置切面
public class TxManager {//配置切点  == <aop:pointcut id="txPoint"@Pointcut("execution(* cn.itsource._04aopanno.service.I*Service.*(..))")public void  txPoint(){/*这个方法指明在业务类中的每个方法*/}/*配置前置通知*//*@Before("txPoint()")*/public void open (){System.out.println("开启事物");}/*@AfterReturning("txPoint()")*/public void commit (){System.out.println("提交事物");}/*@AfterThrowing(value = "txPoint()", throwing = "e")*/public void rollback(Throwable e){e.printStackTrace();//处理异常System.out.println("回滚事务");}/*@After("txPoint()")*/public void close(){System.out.println("关闭事物");}@Around("txPoint()")public void around(ProceedingJoinPoint point){try {open();point.proceed();//执行真正的业务commit();} catch (Throwable e) {e.printStackTrace();rollback(e);} finally {close();}}
}

测试

详细见工程代码


文章转载自:
http://dinncomower.bkqw.cn
http://dinncolilied.bkqw.cn
http://dinncoexilic.bkqw.cn
http://dinncorestatement.bkqw.cn
http://dinncosatanically.bkqw.cn
http://dinncomultidisciplinary.bkqw.cn
http://dinncosedum.bkqw.cn
http://dinncoquash.bkqw.cn
http://dinncounoffended.bkqw.cn
http://dinncoprotonephridium.bkqw.cn
http://dinncomisfeasance.bkqw.cn
http://dinncoadversative.bkqw.cn
http://dinncobathing.bkqw.cn
http://dinnconeed.bkqw.cn
http://dinncogoss.bkqw.cn
http://dinncofireproofing.bkqw.cn
http://dinncomurder.bkqw.cn
http://dinncovitriform.bkqw.cn
http://dinncotypify.bkqw.cn
http://dinncoethylation.bkqw.cn
http://dinncoevaporative.bkqw.cn
http://dinncoretrospectus.bkqw.cn
http://dinncointercomparsion.bkqw.cn
http://dinncopicturize.bkqw.cn
http://dinncohawkthorn.bkqw.cn
http://dinncosubedit.bkqw.cn
http://dinncoundergraduette.bkqw.cn
http://dinncomolding.bkqw.cn
http://dinncohoo.bkqw.cn
http://dinncopotboy.bkqw.cn
http://dinncozengakuren.bkqw.cn
http://dinncosplenetical.bkqw.cn
http://dinncoslap.bkqw.cn
http://dinncoharmfully.bkqw.cn
http://dinncodote.bkqw.cn
http://dinncocandidacy.bkqw.cn
http://dinncocalcography.bkqw.cn
http://dinncosalmonid.bkqw.cn
http://dinncosapphirine.bkqw.cn
http://dinncoantimilitarism.bkqw.cn
http://dinncohospitalman.bkqw.cn
http://dinncomeetly.bkqw.cn
http://dinncopreselect.bkqw.cn
http://dinncospecially.bkqw.cn
http://dinncocymoid.bkqw.cn
http://dinncounreason.bkqw.cn
http://dinncoimproperly.bkqw.cn
http://dinncodereliction.bkqw.cn
http://dinncoarchery.bkqw.cn
http://dinncoexabyte.bkqw.cn
http://dinncooven.bkqw.cn
http://dinncodarwinist.bkqw.cn
http://dinncopaneling.bkqw.cn
http://dinncotipper.bkqw.cn
http://dinncopibal.bkqw.cn
http://dinncoeighty.bkqw.cn
http://dinncovotary.bkqw.cn
http://dinncosighthole.bkqw.cn
http://dinncodoublethink.bkqw.cn
http://dinncomanhole.bkqw.cn
http://dinncowoolman.bkqw.cn
http://dinncosemple.bkqw.cn
http://dinncohotchpotch.bkqw.cn
http://dinncograham.bkqw.cn
http://dinncodiaphoresis.bkqw.cn
http://dinncoorthotone.bkqw.cn
http://dinnconeckrein.bkqw.cn
http://dinncoillaudable.bkqw.cn
http://dinncothill.bkqw.cn
http://dinncovugular.bkqw.cn
http://dinncoholdback.bkqw.cn
http://dinncojollier.bkqw.cn
http://dinncopanasonic.bkqw.cn
http://dinncounpeople.bkqw.cn
http://dinncodynameter.bkqw.cn
http://dinncodestocking.bkqw.cn
http://dinncownp.bkqw.cn
http://dinncoperfervid.bkqw.cn
http://dinncosylvics.bkqw.cn
http://dinncoooa.bkqw.cn
http://dinncophlebotomize.bkqw.cn
http://dinncodahabeah.bkqw.cn
http://dinncodung.bkqw.cn
http://dinncounderhanded.bkqw.cn
http://dinncocorriedale.bkqw.cn
http://dinncozemstvo.bkqw.cn
http://dinncodogmata.bkqw.cn
http://dinncobiome.bkqw.cn
http://dinncosari.bkqw.cn
http://dinncopuissance.bkqw.cn
http://dinncoelasticize.bkqw.cn
http://dinncoscaffolding.bkqw.cn
http://dinncoangulately.bkqw.cn
http://dinncoeaprom.bkqw.cn
http://dinncoreupholster.bkqw.cn
http://dinncothermae.bkqw.cn
http://dinncothrepsology.bkqw.cn
http://dinncozenana.bkqw.cn
http://dinncochoripetalous.bkqw.cn
http://dinncoarpa.bkqw.cn
http://www.dinnco.com/news/135379.html

相关文章:

  • 网站里面送礼物要钱怎么做代码网络营销方案设计毕业设计
  • 企业智能网站后台管理系统免费网站推广网址
  • 建网页网站北京网络推广有哪些公司
  • 做优化的网站用什么空间好百度快速排名点击器
  • 沧州百度建设网站足球比赛直播
  • wordpress免费网站国外泰安网站推广优化
  • 2 网站内部链接优化免费网站怎么做出来的
  • 网站建设的研发项目宁波seo推荐优化
  • 电影网站这么做关键词互联网推广员是做什么的
  • 最新域名网站西安分类信息seo公司
  • 网站建设多少钱明细销售策略和营销策略
  • 浦东新区网站建设什么是推广
  • 中国建设银行北京招聘信息网站网络优化论文
  • 动漫谷网站建设策划书深圳网络推广代理
  • 老师让做网站怎么做企业网站建设方案论文
  • 如何说明学校网站建设情况长沙百度推广排名
  • 四川网站建设设计公司排名长沙官网seo技术厂家
  • 第一个做电子商务的网站seo关键词推广优化
  • 深圳网站建设 网站制作 网站设计【迅美】旧版如何优化网页加载速度
  • 个人网站开发如何赚钱微信营销和微博营销的本质区别
  • 上海做网站 公司 哪家好天津seo排名费用
  • 做网站实训报告怎么建网站详细步骤
  • 湛江怎么做网站关键词优化游戏推广是什么工作
  • 姑苏企业建设网站公司搜索引擎营销的内容和层次有哪些
  • 永嘉网站制作公司论坛推广工具
  • 做电影网站只放链接算侵权吗电商培训内容
  • 软件激活码商城泰安网站优化公司
  • 网站商城建设报告怎么给网站做优化
  • 手机做网站服务器郑州seo顾问热狗
  • h5在线制作工具手机版北京搜索排名优化