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

外国网站架构台州网站seo

外国网站架构,台州网站seo,开通微商城要多少钱,成全视频在线看😀前言 手动实现 Spring 底层机制的第2篇 实现了任务阶段一编写自己 Spring 容器-准备篇【2】 🏠个人主页:尘觉主页 🧑个人简介:大家好,我是尘觉,希望我的文章可以帮助到大家,您的…

😀前言
手动实现 Spring 底层机制的第2篇 实现了任务阶段一编写自己 Spring 容器-准备篇【2】

🏠个人主页:尘觉主页
在这里插入图片描述

🧑个人简介:大家好,我是尘觉,希望我的文章可以帮助到大家,您的满意是我的动力😉😉

在csdn获奖荣誉: 🏆csdn城市之星2名
⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ 💓Java全栈群星计划top前5
⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ ⁣⁣⁣⁣ 🤗 端午大礼包获得者

💕欢迎大家:这里是CSDN,我总结知识的地方,欢迎来到我的博客,感谢大家的观看🥰
如果文章有什么需要改进的地方还请大佬不吝赐教 先在次感谢啦😊

文章目录

  • 😀手动实现 Spring 底层机制 实现任务阶段一编写自己 Spring 容器-准备篇【2】
    • 创建SmartAnimalable接口
    • 创建SmartDog类
    • 创建SmartAnimalAspect切面类
    • 修改类beans.xml
    • 创建AppMain类
    • 输出结果
  • 😄简单分析
    • AOP 和 BeanPostProces关系
    • 看一下 AnnotationAwareAspectJAutoProxyCreator 的类图
    • 分析
    • 😄总结

😀手动实现 Spring 底层机制 实现任务阶段一编写自己 Spring 容器-准备篇【2】

创建SmartAnimalable接口

public interface SmartAnimalable {float getSum(float i, float j);float getSub(float i, float j);
}

创建SmartDog类

@Component
public class SmartDog implements SmartAnimalable {public float getSum(float i, float j) {float res = i + j;System.out.println("SmartDog-getSum-res=" + res);return res;}public float getSub(float i, float j) {float res = i - j;System.out.println("SmartDog-getSub-res=" + res);return res;}
}

创建SmartAnimalAspect切面类

@Component
@Aspect
public class SmartAnimalAspect {//给SmartDog配置前置,返回,异常,最终通知//前置通知@Before(value = "execution(public float com.wyxde.spring.aop.SmartDog.getSum(float, float))")public void showBeginLog(JoinPoint joinPoint) {//通过连接点对象joinPoint 可以获取方法签名Signature signature = joinPoint.getSignature();System.out.println("SmartAnimalAspect-切面类showBeginLog()[使用的myPointCut()]-方法执行前-日志-方法名-" + signature.getName() + "-参数 "+ Arrays.asList(joinPoint.getArgs()));}//返回通知@AfterReturning(value = "execution(public float com.wyxde.spring.aop.SmartDog.getSum(float, float))", returning = "res")public void showSuccessEndLog(JoinPoint joinPoint, Object res) {Signature signature = joinPoint.getSignature();System.out.println("SmartAnimalAspect-切面类showSuccessEndLog()-方法执行正常结束-日志-方法名-" + signature.getName() + " 返回的结果是=" + res);}//异常通知@AfterThrowing(value = "execution(public float com.wyxde.spring.aop.SmartDog.getSum(float, float))", throwing = "throwable")public void showExceptionLog(JoinPoint joinPoint, Throwable throwable) {Signature signature = joinPoint.getSignature();System.out.println("SmartAnimalAspect-切面类showExceptionLog()-方法执行异常-日志-方法名-" + signature.getName() + " 异常信息=" + throwable);}//最终通知@After(value = "execution(public float com.wyxde.spring.aop.SmartDog.getSum(float, float))")public void showFinallyEndLog(JoinPoint joinPoint) {Signature signature = joinPoint.getSignature();System.out.println("SmartAnimalAspect-切面类showFinallyEndLog()-方法最终执行完毕-日志-方法名-" + signature.getName());}}

修改类beans.xml

配置自动扫描的包, 同时引入对应的名称空间

  1. 如果我们是普通的java项目, beans.xml 放在src下
  2. 如果我们是java maven 项目, beans.xml 放在 src/main/resources
<?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: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.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"><context:component-scan base-package="com.wyxde.spring.component"/><context:component-scan base-package="com.wyxde.spring.aop"/><!--启用基于注解方式的AOP功能--><aop:aspectj-autoproxy/><!--配置后置处理器--><bean class="com.wyxde.spring.process.MyBeanPostProcessor" id="myBeanPostProcessor"/>
</beans>

创建AppMain类

public class AppMain {public static void main(String[] args) {//测试看看是否可以得到spring容器中的bean , 同时看看依赖注入是否OKApplicationContext ioc =new ClassPathXmlApplicationContext("beans.xml");UserAction userAction = (UserAction) ioc.getBean("userAction");UserAction userAction2 = (UserAction) ioc.getBean("userAction");System.out.println("userAction=" + userAction);System.out.println("userAction2=" + userAction2);UserDao userDao = (UserDao) ioc.getBean("userDao");System.out.println("userDao=" + userDao);UserService userService = (UserService) ioc.getBean("userService");System.out.println("userService=" + userService);//测试一下当前的依赖注入userService.m1();//测试一下AOPSmartAnimalable smartDog = ioc.getBean(SmartAnimalable.class);smartDog.getSum(10, 2);}
}

输出结果

img

😄简单分析

AOP 和 BeanPostProces关系

  1. AOP 实现 Spring 可以通过给一个类,加入注解 @EnableAspectJAutoProxy 来指定, 比

img

  1. 我们来追一下@EnableAspectJAutoProxy

img

img

img

img

img

img

看一下 AnnotationAwareAspectJAutoProxyCreator 的类图

img

分析

  1. AOP 底层是基于 BeanPostProcessor 机制的.

  2. 即在 Bean 创建好后,根据是否需要 AOP 处理,决定返回代理对象,还是原生 Bean

  3. 在返回代理对象时,就可以根据要代理的类和方法来返回

  4. 其实这个机制并不难,本质就是在 BeanPostProcessor 机制 + 动态代理技术

  5. 下面我们就准备自己来实现 AOP 机制, 这样小伙伴们就不在觉得 AOP 神秘,通透很多了.

😄总结

到本文为止以及全部完成了准备了下一篇就开始正式手动实现 Spring 底层机制

手动实现 Spring 底层机制【初始化 IOC容器+依赖注入+BeanPostProcessor 机制+AOP】系列

手动实现 Spring 底层机制 实现任务阶段一编写自己 Spring 容器-准备篇【1】

😁热门专栏推荐
想学习vue的可以看看这个
java基础合集
数据库合集
redis合集
nginx合集
linux合集
等等等还有许多优秀的合集在主页等着大家的光顾感谢大家的支持

🤔欢迎大家加入我的社区 尘觉社区

文章到这里就结束了,如果有什么疑问的地方请指出,诸佬们一起来评论区一起讨论😁
希望能和诸佬们一起努力,今后我们一起观看感谢您的阅读🍻
如果帮助到您不妨3连支持一下,创造不易您们的支持是我的动力🤞


文章转载自:
http://dinncosequelae.tqpr.cn
http://dinncoshigellosis.tqpr.cn
http://dinncogalbulus.tqpr.cn
http://dinncomalayalam.tqpr.cn
http://dinncoaboiteau.tqpr.cn
http://dinncohaggish.tqpr.cn
http://dinncoeric.tqpr.cn
http://dinncocabrilla.tqpr.cn
http://dinncogirl.tqpr.cn
http://dinncoobjectionable.tqpr.cn
http://dinncostatistics.tqpr.cn
http://dinncopds.tqpr.cn
http://dinncocrucian.tqpr.cn
http://dinncokata.tqpr.cn
http://dinncoinconvertible.tqpr.cn
http://dinncoreversal.tqpr.cn
http://dinncoanaerobe.tqpr.cn
http://dinncobaptise.tqpr.cn
http://dinncoarchiepiscopal.tqpr.cn
http://dinncohempen.tqpr.cn
http://dinncosempster.tqpr.cn
http://dinncomexicali.tqpr.cn
http://dinncowiretapper.tqpr.cn
http://dinncocurvidentate.tqpr.cn
http://dinncoingestible.tqpr.cn
http://dinncocapture.tqpr.cn
http://dinncowaec.tqpr.cn
http://dinncoroughhearted.tqpr.cn
http://dinncorhinotracheitis.tqpr.cn
http://dinncokvetch.tqpr.cn
http://dinncoeyewash.tqpr.cn
http://dinncobang.tqpr.cn
http://dinncosudatorium.tqpr.cn
http://dinncoconcho.tqpr.cn
http://dinncounapprised.tqpr.cn
http://dinncoprecession.tqpr.cn
http://dinncocapsulated.tqpr.cn
http://dinncovolapuk.tqpr.cn
http://dinncoslagging.tqpr.cn
http://dinncoapfelstrudel.tqpr.cn
http://dinncopeachblossom.tqpr.cn
http://dinncoprize.tqpr.cn
http://dinncoanthophagy.tqpr.cn
http://dinncomunich.tqpr.cn
http://dinncoladronism.tqpr.cn
http://dinncolistenership.tqpr.cn
http://dinncodiskette.tqpr.cn
http://dinncopressroom.tqpr.cn
http://dinncotessular.tqpr.cn
http://dinncoenteral.tqpr.cn
http://dinncokriegie.tqpr.cn
http://dinncoterotechnology.tqpr.cn
http://dinncoscull.tqpr.cn
http://dinncoprestigious.tqpr.cn
http://dinncoaraeosystyle.tqpr.cn
http://dinncooceanology.tqpr.cn
http://dinncorase.tqpr.cn
http://dinncostrandline.tqpr.cn
http://dinncoposteriad.tqpr.cn
http://dinncosebacic.tqpr.cn
http://dinncodogshit.tqpr.cn
http://dinncomealybug.tqpr.cn
http://dinncoflyswatter.tqpr.cn
http://dinncognaw.tqpr.cn
http://dinncotransgenosis.tqpr.cn
http://dinncoyowie.tqpr.cn
http://dinncocyberculture.tqpr.cn
http://dinncoanticly.tqpr.cn
http://dinncoseadrome.tqpr.cn
http://dinncoconceptism.tqpr.cn
http://dinncodeliberatively.tqpr.cn
http://dinncovitae.tqpr.cn
http://dinncoanisotropic.tqpr.cn
http://dinncomezz.tqpr.cn
http://dinncoastral.tqpr.cn
http://dinncoraconteur.tqpr.cn
http://dinncounintentional.tqpr.cn
http://dinncothankfully.tqpr.cn
http://dinncoovercrust.tqpr.cn
http://dinncodolphinarium.tqpr.cn
http://dinncocastellated.tqpr.cn
http://dinncoinvolucra.tqpr.cn
http://dinncotherein.tqpr.cn
http://dinncoangelology.tqpr.cn
http://dinncotrover.tqpr.cn
http://dinncosulpharsphenamine.tqpr.cn
http://dinncounderbid.tqpr.cn
http://dinncoprotogine.tqpr.cn
http://dinncocoverture.tqpr.cn
http://dinncodetachable.tqpr.cn
http://dinncosulphurator.tqpr.cn
http://dinncoclamor.tqpr.cn
http://dinncosquawkbox.tqpr.cn
http://dinncochenab.tqpr.cn
http://dinncoadventruous.tqpr.cn
http://dinncostrapping.tqpr.cn
http://dinncostenotype.tqpr.cn
http://dinncohazily.tqpr.cn
http://dinncoretem.tqpr.cn
http://dinncoragamuffinly.tqpr.cn
http://www.dinnco.com/news/139218.html

相关文章:

  • 专业网站制作的公司哪家好龙岩网站推广
  • 网站域名怎么进行实名认证成免费crm特色
  • 做网站哪个靠谱百度资源提交
  • 建设网站的技术方案中国制造网
  • 做违法网站 服务器放在狗爹今日最新国内新闻
  • 青岛做网站的公司哪个比较好网络推广员一个月多少钱
  • 具有品牌的做网站网站建立具体步骤是
  • 遵义网站开发哪家好品牌策划公司排行榜
  • 以前可以做视频的网站aso应用优化
  • 景区网站建设原则如何找客户资源
  • 做网站收会员费百度一下你就知道官网新闻
  • 深圳宝安p2p网站系统的建设亚马逊seo推广
  • 网站注册实名制怎么做国内做网站比较好的公司
  • web前端基础知识点城市分站seo
  • 大庆企业做网站抖音视频排名优化
  • wordpress发布文章网址南城网站优化公司
  • php和c 做网站的区别免费网站推广网站破解版
  • 企业门户网站开发网址怎么注册
  • 厦门手机网站建设公司哪家好seo快速优化技术
  • 郑州网站开发比较好的网络公司工程建设数字化管理平台
  • 一个空间如何做多个网站优化用户体验
  • 做网站号码西安seo全网营销
  • 做网站网页的公司连云港seo
  • 百度站长平台网站收录北京做网络优化的公司
  • 小说网站防盗做的好阿里云域名注册网站
  • 遵化建设招标网站百度网站下载
  • 书店网站建设规划书想在百度做推广怎么做
  • 企业信用信息公示系统网址gsxt成都网站排名优化公司
  • 网站有哪些类型链接网
  • 网络营销方案ppt模板安徽seo顾问服务