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

长春住房和城乡建设部官方网站个人网站备案备注怎么写

长春住房和城乡建设部官方网站,个人网站备案备注怎么写,seo优化轻松seo优化排名,店铺设计平面图目录 一、简介二、代码示例2.1 接口类2.2 接口实现类2.3 AOP切面类2.4 启动类#xff08;测试#xff09;2.5 执行结果 一、简介 背景#xff1a; 在之前 Spring 的 AOP 用法中#xff0c;只有代理的类才会被切入。例如#xff1a;我们在 Controller 层调用 Service 的方式… 目录 一、简介二、代码示例2.1 接口类2.2 接口实现类2.3 AOP切面类2.4 启动类测试2.5 执行结果 一、简介 背景 在之前 Spring 的 AOP 用法中只有代理的类才会被切入。例如我们在 Controller 层调用 Service 的方式时是可以被切入的。但是如果我们在 Service 层 A 方法中调用 B 方法切点切的是 B 方法那么这时候是不会被切入的。 解决方案如标题所示可以使用 AopContext.currentProxy() 来解决。在 A 方法中使用如下方式来调用 B 方法这样一来就能切入了 import org.springframework.aop.framework.AopContext;((Service) AopContext.currentProxy()).B();二、代码示例 2.1 接口类 首先定义一个接口其中前两个方法内部通过不同方式调用了第三个方法。 SomeInterface.java public interface SomeInterface {/** 调用方普通调用 */void someMethod();/** 调用方获取代理调用 */void someMethodWithProxy();/** 被调用方 */void anotherMethod(); }2.2 接口实现类 然后我们按照上面描述的关系来编写实现类。 MyBean.java import com.demo.module.test.SomeInterface; import org.springframework.aop.framework.AopContext; import org.springframework.stereotype.Component;Component public class MyBean implements SomeInterface {Overridepublic void someMethod() {System.out.println(someMethod...);this.anotherMethod();}Overridepublic void someMethodWithProxy() {System.out.println(someMethodWithProxy...);MyBean myBean (MyBean) AopContext.currentProxy();myBean.anotherMethod();}Overridepublic void anotherMethod() {System.out.println(anotherMethod...);} }2.3 AOP切面类 这里实现了一个切面来增强被调用的方法 anotherMethod()。 SomeAspect.java import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component;Aspect Component public class SomeAspect {After(execution(* com.demo.impl.MyBean.anotherMethod(..)))public void afterAnotherMethod() {System.out.println(after anotherMethod);} }2.4 启动类测试 注意这里需要在启动类或者配置类中添加如下注解不然无法使用 AopContext.currentProxy() 方法来获取代理类。 EnableAspectJAutoProxy(exposeProxy true) // 开启 Spring 注解 AOP 配置的支持不添加会出现如下报错java.lang.IllegalStateException: Cannot find current proxy: Set ‘exposeProxy’ property on Advised to ‘true’ to make it available… Caused by: java.lang.IllegalStateException: Cannot find current proxy: Set exposeProxy property on Advised to true to make it available, and ensure that AopContext.currentProxy() is invoked in the same thread as the AOP invocation context.at org.springframework.aop.framework.AopContext.currentProxy(AopContext.java:69) ~[spring-aop-5.2.6.RELEASE.jar:5.2.6.RELEASE]at com.demo.module.test.impl.MyBean.someMethodWithProxy(MyBean.java:26) ~[classes/:na]此外我们在启动类中注入了一个 CommandLineRunner 类用于启动后立马执行测试代码。 DemoApplication.java import com.demo.module.test.SomeInterface; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.EnableAspectJAutoProxy;import javax.annotation.Resource;EnableAspectJAutoProxy(exposeProxy true) // 开启 Spring 注解 AOP 配置的支持 SpringBootApplication public class DemoApplication {Resourceprivate SomeInterface someInterface;public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}Beanpublic CommandLineRunner commandLineRunner() {return args - {System.out.println( someMethod );someInterface.someMethod();System.out.println( someMethodWithProxy );someInterface.someMethodWithProxy();System.out.println( end );};} }2.5 执行结果 执行结果如下可以看到通过 AopContext.currentProxy() 获取当前类的代理后再调用可以正常进行 AOP 增强。 整理完毕完结撒花~ 参考地址 1.AopContext.currentProxy()https://blog.csdn.net/qq_29860591/article/details/108728150
http://www.w-s-a.com/news/338649/

相关文章:

  • 省级网站 开发建设 资质在国外怎么做网站
  • 中商华兴建设有限公司网站我的世界查找建筑网站
  • 广东网站设计公司百度推广免费送网站
  • 高密做网站哪家好网站建设预算
  • 免费wordpress网站模板重庆如何做聚政网站
  • 人才网站app建设建议系统开发生命周期法的优点表现
  • 门户网站想要微信登录怎么做湖南网站seo推广
  • 襄阳 网站建设管理系统网站
  • 重庆工程建设招标投标交易信息网广州外贸seo优化
  • 一个一起做网站东莞设计兼职网站建设
  • 杭州网站程序开发公司在哪个公司建设网站好
  • 网店的网站设计方案济南手机建站价格
  • 网站做了301重定向域名会自动跳转吗唐山地方志网站建设
  • 学校网站建设说明书海南省建设执业资格注册管理中心网站
  • 东莞哪家网站建设好网站风格设定
  • 自驾游网站模板搭建wordpress步骤
  • wordpress视频网站上传视频提升学历是什么意思
  • 江西省城乡建设厅建设网站浙江建设
  • 网站联系我们页面临平做网站
  • 如何用网站做cpa交互比较好的网站
  • 一家只做特卖的网站wordpress修改模板教程
  • 与恶魔做交易的网站成都到西安高铁票价
  • 太原网站制作哪家便宜长春昆仑建设股份有限公司网站
  • 优质做网站价格设计手机商城网站建设
  • 高校网站建设制度无锡网站建设排名
  • 做网站的软件wd的叫啥无锡公司网站建设服务
  • 网站建设一般需要多久网站服务器基本要素有哪些
  • 大连开发区网站开发公司免费网站建设哪个好?
  • 关于建设门户网站的通知海曙区建设局网站
  • 韩国建设部网站温州企业网站制作