Spring学习(二十四)Spring实现AOP

温升试验详解 温升试验是电子设备可靠性验证的重要手段,用于评估器件在正常工作或极限条件下的热稳定性。试验通过测量器件表面或关键点温度与环境温度的差值(ΔT),判断是否存在过热风险。主要依据行业标准,采用热电偶、热像仪等设备测量稳态温度。热阻分析可建立温升与功耗的关系,指导器件选型、PCB热设计和散热结构优化。典型应用包括电源模块和LED电路测试。温升试验通过系统性热分析,能有效提升产品在高负载、高温环境下的可靠性和安全性,对现代小型化、高密度电子设备尤为重要。 阅读详情
Spring实现AOP主要有两种方式:
1.基于AspectJ注解
2.基于XML配置
接下来我们分别介绍如何使用这两种方式来实现AOP

一.使用注解方式实现AOP功能
利用Spring注解方式可以实现前置通知,后置通知,例外通知以及环绕通知等。
实现AOP功能步骤如下:
  1. 引入Jar文件
  2. 配置AOP命名空间
  3. 创建目标对象类
  4. 创建切面
  5. 在配置文件中配置切面
  6. 创建入口类进行测试
接下来我们在示例中演示一下
具体要求如下:
  • 创建一个Java Bean,例如PersonBean
  • PersonBean包含一些简单的业务逻辑,例如运动相关,包括走路,跑步,爬山,打球等。
  • 在每个运动的方法前,方法中,以及方法后输出相关的日志信息。

Step1:在classpath下的AspectJ类库:
spring-aspects.jar
aspectj.weaver.jar
aopalliance.jar

Step2:创建一个接口Person
public interface Person {
    public void work();
    public void run();
    public void playBasketball();
    public void swim();
}

Step3:定义Tager Object
import org.springframework.stereotype.Component;

/**
* Created by icarus on 2016/6/13.
* Person接口实现类
*/
@Component("personimpl1")
public class PersonImpl1 implements Person{
    public void work() {
        System.out.println("散步!");
    }
    public void run() {
        System.out.println("跑步!");
    }
    public void playBasketball() {
        System.out.println("打篮球!");
    }
    public void swim() {
        System.out.println("游泳!");
    }
}

Step4:定义Aspect和Advice
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component("loggingaspect")
public class  LoggingAspect {
    @Pointcut("execution(* cn.lovepi.chapter06.aop.test.PersonImpl1.*(..))")
    public void sport(){

    }

    /**
    * 方法执行前记录日志
    * @param jp 连接点
    */
    @Before("sport()")
    public void loggerBeforeAction(JoinPoint jp) {
        System.out.println(jp.getSignature().getName()+"执行开始");

    }

    /**
    * 方法执行过程中记录日志
    * @param pjp 只能在Around 的advice中使用
    * @throws Throwable
    */
    @Around("sport()")
    public void loggerAroundAction(ProceedingJoinPoint pjp) throws Throwable {
        pjp.proceed();//执行原方法
        System.out.println(pjp.getSignature().getName()+"执行过程中... ...");
    }

    /**
    * 方法执行完记录日志
    * @param jp 连接点
    * @throws Throwable
    */
    @After("sport()")
    public void loggerAfterAction(JoinPoint jp){
        System.out.println(jp.getSignature().getName()+"执行结束");

    }
}

Step5:进行Aop设置
<?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:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!--开启注解扫描-->
    <context:component-scan base-package="cn.lovepi.chapter06.aop.test"/>
    <!--开启Spring动态代理-->
    <aop:aspectj-autoproxy proxy-target-class="true"/>
</beans>

说明:必须在Spring IoC容器中启用AspectJ动态代理支持

Step6:测试
public class Main {
    public static void main(String[] args){
        ApplicationContext context=
                new FileSystemXmlApplicationContext("src/conf/conf-test.xml");
        cn.lovepi.chapter06.aop.test.PersonImpl1 person=context.getBean("personimpl1",cn.lovepi.chapter06.aop.test.PersonImpl1.class);
        person.run();
        person.work();
        person.playBasketball();
        person.swim();
    }
}

程序执行结果:
run执行开始
跑步!
run执行过程中... ...
run执行结束
work执行开始
散步!
work执行过程中... ...
work执行结束
playBasketball执行开始
打篮球!
playBasketball执行过程中... ...
playBasketball执行结束
swim执行开始
游泳!
swim执行过程中... ...
swim执行结束


二.使用Spring XML配置方式实现AOP功能
实现AOP的主要步骤如下:
  1. 引入Jar文件
  2. 配置AOP命名空间
  3. 创建目标对象类
  4. 创建切面
  5. 在配置文件中配置
  6. 创建入口类进行测试
接下来我们在示例中演示一下
具体要求如下:
  • 创建一个Java Bean,例如PersonBean
  • PersonBean包含一些简单的业务逻辑,例如运动相关,包括走路,跑步,爬山,打球等。
  • 在每个运动的方法前,方法中,以及方法后输出相关的日志信息。

Step1:在classpath下的AspectJ类库:
spring-aspects.jar
aspectj.weaver.jar
aopalliance.jar

Step2:创建一个接口Person
public interface Person {
    public void work();
    public void run();
    public void playBasketball();
    public void swim();
}

Step3:定义Tager Object
public class PersonImplXml implements Person{
    public void work() {
        System.out.println("散步!");
    }

    public void run() {
        System.out.println("跑步!");
    }

    public void playBasketball() {
        System.out.println("打篮球!");
    }

    public void swim() {
        System.out.println("游泳!");
    }
}

Step4:定义Aspect和Advice
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/**
* Created by icarus on 2016/6/13.
*/
public class LoggingAspectXml {
    /**
    * 开始执行方法
    * @param jp
    */
    public void loggerBeforeAction(JoinPoint jp) {
        System.out.println(jp.getSignature().getName()+"执行开始");

    }

    /**
    * 方法执行中
    * @param pjp
    * @throws Throwable
    */
    public void loggerAroundAction(ProceedingJoinPoint pjp) throws Throwable {
        pjp.proceed();//执行原方法
        System.out.println(pjp.getSignature().getName()+"执行过程中... ...");
    }

    /**
    * 方法执行结束
    * @param jp
    */
    public void loggerAfterAction(JoinPoint jp){
        System.out.println(jp.getSignature().getName()+"执行结束");

    }
}

Step5:进行Aop设置
<?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: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/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    <!--开启Spring动态代理-->
    <aop:aspectj-autoproxy proxy-target-class="true"/>
    <!--bean 配置-->
    <bean id="personImplXml" class="cn.lovepi.chapter06.aop.test.PersonImplXml"/>
    <bean id="loggingAspectXml" class="cn.lovepi.chapter06.aop.test.LoggingAspectXml"/>
    <!--aop 配置-->
    <aop:config>
        <!--设置切点-->
        <aop:pointcut id="loggingAspect" expression="execution(* cn.lovepi.chapter06.aop.test.PersonImplXml.*(..))"/>
        <!--切面设置-->
        <aop:aspect id="loggingaspect" ref="loggingAspectXml">
            <aop:before method="loggerBeforeAction" pointcut-ref="loggingAspect"/>
            <aop:around method="loggerAroundAction" pointcut-ref="loggingAspect"/>
            <aop:after method="loggerAfterAction" pointcut-ref="loggingAspect"/>
        </aop:aspect>
    </aop:config>
</beans>

说明:必须在Spring IoC容器中启用AspectJ动态代理支持

Step6:测试
public class MainXml {
    public static void main(String[] args){
        ApplicationContext context=new FileSystemXmlApplicationContext("src/conf/conf-test-xml.xml");
        PersonImplXml person=context.getBean("personImplXml",PersonImplXml.class);
        person.work();
        person.run();
        person.playBasketball();
        person.swim();
    }
}

程序执行结果:
run执行开始
跑步!
run执行过程中... ...
run执行结束
work执行开始
散步!
work执行过程中... ...
work执行结束
playBasketball执行开始
打篮球!
playBasketball执行过程中... ...
playBasketball执行结束
swim执行开始
游泳!
swim执行过程中... ...
swim执行结束

总结:
通过最后结果相比较而言,AspectJ更值得推荐
基于STM32设计的掌上游戏机(运行NES游戏模拟器)详细开发过程 利用STM32单片机移植NES游戏模拟器,完成NES游戏开发,可以玩标准的NES游戏,已测试超级玛丽、魂斗罗之类的都可以正常运行。 阅读详情

相关推荐

手把手教你用CH582的USB0/1双接口玩转CherryUSB协议栈(附完整代码)

本文深入解析CH582双USB接口硬件架构,详细讲解如何通过CherryUSB协议栈实现双接口协同工作,包括中断处理设计、端点资源分配和复合设备描述符配置。提供HID+CDC复合设备实战案例,并分享高级调试技巧与性能优化方法,帮助开发者充分利用CH582的USB0/1双接口潜力。

weixin_42525637的博客 263

SpringAOP 处理通知中的参数(注解与xml配置)

上一篇文章讲的是springaop的最基本配置,没有任何参数,有参数的也就在环绕通知@Around 中使用了ProceedingJoinPoint 作为参数,要是切面所通知的方法确实有参数该怎么办?下面通过一个需求来实现aop处理参数的功能。 一个马戏团里有很多演员,编号分别为A、B、C…,老板要记录每个演员的演出次数作为年底发红包的依据。

纸上得来终觉浅,绝知此事要躬行 6273

12V转5V稳压电路详细分析(7805三端稳压,LM2596稳压)

7805线性三端稳压 DCDC的意思是直流变到直流(不同直流电源值的转换),只要符合这个定义都可以叫DCDC转换器,或称之为开关电源或开关调整器。 7805属于常用的线性三端稳压器,输入电压范围不大于35V,输入输出压差2V,最大输出电流1.5A,下图为原理图,其原理简单,使 用方便,深受很多用户的喜爱。但是其不足之处就是效率低,特别是压差越大时其效率越低。比如这里12V转5V的效率为 5V/12V≈41.7%。 如上电路是最经典的7805稳压5V电路,电路中有两个电容,电容的作用如下: ...

a2001444的博客 9万+

Spring中使用AspectJ实现AOP的五种通知

【1】AOP通知方法 通知方法可以简单理解为标注有某种注解的简单的 Java 方法,在目标方法执行时的某个位置(时机)进行执行。 AspectJ 支持 5 种类型的通知注解: @Before: 前置通知, 在方法执行之前执行 @After: 后置通知, 在方法执行之后执行 @AfterRunning:返回通知, 在方法返回结果之后执行 @AfterThrowing: 异常通知.........

小小默:进无止境 6601

Windows下MMdetection3D保姆级安装指南(含CUDA和PyTorch版本避坑)

本文提供Windows平台下MMdetection3D的完整安装指南,重点解决CUDA与PyTorch版本匹配问题。从环境准备到关键组件安装,详细介绍了CUDA Toolkit选择策略、PyTorch精准安装步骤,以及MM系列组件的安装顺序和常见错误解决方案,帮助用户顺利完成3D目标检测环境的配置。

weixin_42628941的博客 490

MS建模mmt

一、流程:1.定义好每个原子力场类型:Edit Sets(分组) 2.加H(一般是仅与Al-O八面体中的Al相连的O原子)、给H分组 3.“make P1”、校核化学式(正确与否) 4.扩成超晶胞(Na-mmt:4*1*1,Ca-mmt:4*2*1,illite:2*1*1,由化学式而定) 5.置换阳离子: mmt:模型中每 32 个 Si 4+有 1 个被 Al 3+ 取...

weixin_30721899的博客 2171

spring aop的五种通知类型

spring aop通知(advice)分成五类: 前置通知、正常返回通知、异常返回通知、返回通知、环绕通知

cqabl的专栏 4万+

GT-suite v2016的下载和安装

1 写在前面 GT-suite 是一款用来做内燃机仿真的软件。在安装过程中遇到很多问题,网上的安装教程也大都抄来抄去,试着安装了几遍都没有成功。最终在贴吧一个老哥的帖子里找到了解决办法,但是老哥的帖子也不是很详细,所以做了这个详细版本的教程。 GT-suite v2016安装包: 链接:https://pan.baidu.com/s/1JZPgJ8_-J-L8rV84-eHedQ 提取码:uj...

kisssshot的博客 2万+

使用Spring的注解方式实现AOP

Spring对AOP的实现提供了很好的支持。下面我们就使用Spring的注解来完成AOP做一个例子。 首先,为了使用Spring的AOP注解功能,必须导入如下几个包。aspectjrt.jar,aspectjweaver.jar,cglib-nodep.jar. 然后我们写一个接口 package com.bird.service; public interface PersonServe...

web开发 628

Dataset - DeepFashion 服装数据集

Dataset - DeepFashion 服装数据集 [Dataset - DeepFashion] [Project - DeepFashion] 1. 服装类别和属性预测集 [Category - Attribute 下载] [百度网盘] 289,222 张服装图片 clothes images; 50 个服装类别 clothing categories 1,000 ...

长风破浪会有时,直挂云帆济沧海 2万+

一网打尽身份验证与授权:深入剖析ASP.NET Core Identity在C#中的全方位实战应用

ASP.NET Core Identity 是 Microsoft 提供的一个强大且可扩展的身份验证和授权框架,用于构建基于用户账户、角色和权限的Web应用程序。它提供了用户注册、登录、密码管理、多因素认证、角色分配、授权等功能,与ASP.NET Core框架深度集成,简化了安全相关的开发工作。通过上述代码示例和注释,展示了如何安装配置Identity、自定义用户实体与数据库上下文、实现用户注册登录、管理角色与用户角色关系,以及如何使用授权策略保护应用程序资源。,并指定用户和角色类型以及主键类型。

java专栏 1525

Spring---AOP基本概念以及Advice5种类型的通知注解应用实例

AOPAOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善。OOP引入封装、继承、多态等概念来建立一种对象层次结构,用于模拟公共行为的一个集合。不过OOP允许开发者定义纵向的关系,但并不适合定义横向的关系,例如日志功能。日志代码往往横向地散布在所有对象层次中,而与它对应的对

StubbornAccepted的博客 3299

服务器取证——服务器基础知识

服务器基础知识

记录并分享学习安全的知识点.. 2477

Spring的AOP实现原理

本学习笔记将尽可能的将AOP的知识讲解的通俗易懂,先从一个典型的问题出发,引入AOP这个概念,介绍AOP的基本概念,再到Spring中的AOP的实现方案,最后进行一个简单的总结归纳。本学习笔记中不考虑cglib、也不会太关注Spring AOP如何使用,而是尽可能的简单的说清楚AOP的工作原理。 笔记中贴出的源代码均是Spring 5.1.7-RELEASE 版本 问题提出 如下代码块,现在需要统计这个方法执行的耗时情况 public void runTask() { doSome

m0_57229961的博客 9666

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Spring的AOP实现例子

一、为什么需要AOP 假如我们应用中有n个业务逻辑组件,每个业务逻辑组件又有m个方法,那现在我们的应用就一共包含了n*m个方法,我会抱怨方法太多。。。现在,我有这样一个需求,每个方法都增加一个通用的功能,常见的如:事务处理,日志,权限控制。。。最容易想到的方法,先定义一个额外的方法,实现该功能,然后再每个需要实现这个功能的地方去调用这个额外的方法。这种做法的好处和坏处分别是。 好处:可以动态地添...

蔡小波的博客 6433

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Spring AOP 的实现过程

原文:Spring AOP 的实现过程aop 的作用是在书写上将辅助业务逻辑从主业务的逻辑中拆出来,实现主业务和辅助业务的,但在执行主业务逻辑的时候,辅助业逻辑业也会执行。从而保证拆前拆后功能不变。那辅助业务拆出来放在哪里?辅助业务封装在切面中,所以 。什么是切面?切面就是一个类,并且被 注释。辅助业务在切面的哪里?辅助业务封装在切面的方法里,不同的方法封装不同的辅助业务逻辑。切面中的方法是怎么触发的呢?给封装辅助业务逻辑所在的方法标注 其中一个或几个注解。这样当主业务方法执行时,辅助业务的逻辑所在的方法就

进击的豌豆的博客 4035

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Spring是如何实现AOP的

AOP即面向切面编程,是一种编程思想,作为面向对象思想的补充,目的是方便增强方法,处理一些具有横切性质的服务,比如日志记录,安全控制等,强大的Spring框架中亦运用了这种思想,那在探究了Spring实现AOP过程之后,在这里记录下自己的理解............

weixin_43953283的博客 1782

Spring AOP的实现

SpringAOP

qq_64183220的博客 749

Spring学习-AOP(AOP 的三种实现方式)

1、APO 简介   AOP为 Aspect Oriented Programming 的缩写,意思为: 面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP 是 Spring 框架中一个重要的部分,利用 AOP 可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。   我们现在做的一些非业务,如:日志...

李十八的博客 1219

Spring AOP 实现原理

什么是AOP AOP(Aspect-OrientedProgramming,面向方面编程),可以说是OOP(Object-Oriented Programing,面向对象编程)的补充和完善。OOP引入封装、继承和多态性等概念来建立一种对象层次结构,用以模拟公共行为的一个集合。当我们需要为分散的对象引入公共行为的时候,OOP则显得无能为力。也就是说,OOP允许你定义从上到下的关系,但并不适合定

The Best Or Nothing~ 1566

Spring中AOP的实现

1、概述 它最大的作用是什么? 在不更改源代码的情况下,对其原有功能进行增强。使得代码的重用率、开发效率、维护产生极大的方便。 运用场景 最常见的有:事务、日志、请求拦截等 2、使用 如何在Spring中使用AOP? 1、开启配置 @EnableAspectJAutoProxy 2、写代理类和被代理的类 @Component @Aspect public class AopConfig { @PostConstruct public void init(){ System.out.pri

苦行僧 847

Spring AOP(AOP概念、组成、Spring AOP实现及实现原理)

AOP ( Aspect-Oriented Programming :同调用的逻辑(例如事务处理、日志管理、权限控制等)封装抽取成一个可重用的模块,这个模块被命名为"切面"(Aspect),便于减少系统的重复代码,降低模块间的耦合度,并有利于未来的可拓展性和可维护性;.Spring AOP 基于动态代理实现, JDK 动态代理是 Java 自带的动态代理实现方式。CGLIB 代理是一个基于字节码操作的代理方式.

芯轴的博客 1067

Spring AOP学习

Spring AOP学习概述静态与动态Java的AOP实现机制AOP的几大角色基本实现适用案例 概述 软件开发的目的是为了解决各种真实场景的业务和系统需求。面向对象能对现实世界能够对代码结构进行地抽象与封装,让系统有很好地模块化,扩展性和可维护性。 需求与具体实现之间的关系上一对一,但是在系统开发过程中往往会存在一些切面,切面通常与系统逻辑无关,是面向多个或者所有的需求线的一个面。现在我们需要一...

qq_39665053的博客 345

spring aop的实现代码

跟踪spring aop的实现 aop核心概念介绍 什么是切面编程 在运行时,动态地将代码切入到类的指定方法、指定位置上的编程思想就是面向切面编程。 Aspect(切面) 什么是切面呢?切面这个词感觉还是挺抽象的,咱们可能知道点构成线,线构成面的数据话术。但是在编程语言中如何体现这个面呢?我的理解是“在程序中切面是由切入点和在切入点的表现的行为构成”。给个在spring中定义切面的例子如下...

jcw的博客 1238

Spring AOP、Spring AOP 实现原理

一、为什么会出现AOP 一个场景 把大象装进冰箱分三步: (1)、打开冰箱 (2)、把大象装进冰箱 (3)、关上冰箱 把老虎装进冰箱分三步: (1)、打开冰箱 (2)、把老虎装进冰箱 (3)、关上冰箱 如果把1000种动物装进冰箱,还需要计时怎么办?显然不能1000个类中都加代码 交叉业务逻辑,系统级的服务 类比 打开冰箱门,关闭冰箱门 主业务逻辑 类比 把动物放进冰箱,主...

m0_37531231的博客 1377

Spring AOP 的实现及原理

spring aop 的实现及原理

qq_71360748的博客 921
上一篇: 使用Java实现AOP
下一篇: Spring学习(二十五)Spring AOP之增强介绍
wangxin1248
博客等级 码龄11年 305粉丝 68原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值