package com.xk.spring.kp04_aop.proxy.s1_static;

public interface IStudentService {
public void save(Student stu);
}
package com.xk.spring.kp04_aop.proxy.s1_static;

public class ImplStudentService implements IStudentService {
@Override
public void save(Student stu) {
// dao实现方法
System.out.println("保存...");
}
}

  

package com.xk.spring.kp04_aop.proxy.s1_static;

public class StudentServiceProoxy implements IStudentService {

    private ImplStudentService service;

    public StudentServiceProoxy(ImplStudentService service) {
this.service = service;
} @Override
public void save(Student stu) {
System.out.println("beginTranstation()");
service.save(stu);
System.out.println("commit()"); } }
package com.xk.spring.kp04_aop.proxy.s1_static;

public class Student {
private String name;
private Integer age; public Student() {
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Integer getAge() {
return age;
} public void setAge(Integer age) {
this.age = age;
} public Student(String name, Integer age) {
this.name = name;
this.age = age;
} @Override
public String toString() {
return "Student [name=" + name + ", age=" + age + "]";
} }
package com.xk.spring.kp04_aop.proxy.s1_static;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class StaticProxyTest {
@Autowired
@Qualifier("ProxyService")
private IStudentService transeriver; @Test
public void TestStaticProxy() throws Exception {
transeriver.save(new Student("张三", 18));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- id唯一标识
自动创建类的对象
-->
<bean id="StudentService"
class="com.xk.spring.kp04_aop.proxy.s1_static.ImplStudentService" />
<bean id="ProxyService"
class="com.xk.spring.kp04_aop.proxy.s1_static.StudentServiceProoxy">
<constructor-arg name="service" ref="StudentService"/>
</bean>
</beans>

proxy Static方式的更多相关文章

  1. Java-HTTP连接时如何使用代理(二)—— Proxy类方式

    阅读这篇文章之前,请先阅读 Java-HTTP连接时如何使用代理(一)——System.Property方式 除了使用 System.setProperty() 的方式之外,还可使用 Proxy 的方 ...

  2. RestTemplate proxy 设置方式

    RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory() {{ setProxy(new ja ...

  3. 动态代理 Proxy InvocationHandler

      前奏 代理模式 代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等. 代理类与委托类之间通常 ...

  4. [转]JAVA的动态代理机制及Spring的实现方式

    JAVA 代理实现 代理的实现分动态代理和静态代理,静态代理的实现是对已经生成了的JAVA类进行封装. 动态代理则是在运行时生成了相关代理累,在JAVA中生成动态代理一般有两种方式. JDK自带实现方 ...

  5. Cglib动态代理实现方式

    Cglib动态代理实现方式 我们先通过一个demo看一下Cglib是如何实现动态代理的. 首先定义个服务类,有两个方法并且其中一个方法用final来修饰. public class PersonSer ...

  6. 二进制方式部署Kubernetes 1.6.0集群(开启TLS)

    本节内容: Kubernetes简介 环境信息 创建TLS加密通信的证书和密钥 下载和配置 kubectl(kubecontrol) 命令行工具 创建 kubeconfig 文件 创建高可用 etcd ...

  7. 面试官:你说你懂动态代理,那你知道为什么JDK中的代理类都要继承Proxy吗?

    之前我已经写过了关于动态代理的两篇文章,本来以为这块应该没啥问题,没想到今天又被难住了- 太难了!!! 之前文章的链接: 动态代理学习(一)自己动手模拟JDK动态代理. 动态代理学习(二)JDK动态代 ...

  8. Java 动态代理原理图解 (附:2种实现方式详细对比)

    ​ 动态代理在 Java 中有着广泛的应用,例如:Spring AOP 面向切面编程,Hibernate 数据查询.以及 RPC Dubbo 远程调用等,都有非常多的实际应用@mikechen 目录 ...

  9. htnl中的遮罩层以及定位方式

    在页面显示遮罩层,例如:一个div的css样式: $msk.css({ "top":"0", "left":"0", & ...

随机推荐

  1. Python基础(七) python自带的三个装饰器

    说到装饰器,就不得不说python自带的三个装饰器: 1.@property   将某函数,做为属性使用 @property 修饰,就是将方法,变成一个属性来使用. class A(): @prope ...

  2. 框架——flask知识点回顾

    1. flask--轻量级Web开发框架 2. Flask 没有默认使用的数据库,你可以选择 MySQL,也可以用 NoSQL 3. Web程序框架的意义: 用于搭建Web应用程序 免去不同Web应用 ...

  3. Python记录14:面向对象编程 类和对象

    '''现在主流的编程思想有两种,一种是面向对象,一种是面向过程面向过程编程 核心是过程二字,过程指的是解决问题的步骤,即先干什么.再干什么.最后干什么... 基于该思想编写程序就好比再设计一条流水线, ...

  4. mybatis常见问题和错误

    1. jdbc java type 映射关系 1) mysql的text 在mybatis中使用varchar类型 2. mybatis常见的错误 3.There is no getter for p ...

  5. Mysql数据库优化之SQL及索引优化

    1. 如何发现有问题的SQL?  使用mysql慢查询日志对有效率问题的Sql进行监视 (1) show  variables like 'slow_query_log';     查看慢查询日志是否 ...

  6. 【运维技术】redis(一主两从三哨兵模式搭建)记录

    redis(一主两从三哨兵模式搭建)记录 目的: 让看看这篇文章的的人能够知道:软件架构.软件的安装.配置.基本运维的操作.高可用测试.也包含我自己,能够节省对应的时间. 软件架构: 生产环境使用三台 ...

  7. np.meshgrid()用法+ np.stack()用法

    A,B,C,D,E,F是6个网格点,坐标如图,如何用矩阵形式(坐标矩阵)来批量描述这些点的坐标呢?答案如下 这就是坐标矩阵——横坐标矩阵X XX中的每个元素,与纵坐标矩阵Y YY中对应位置元素,共同构 ...

  8. 0.3:Before We Start

    文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本系列原更新于作者的github博客,这里给出链接. 需要做的准备 首先肯定是需要安装Unity,我这里选择的版本是Unity ...

  9. K8S学习笔记之k8s日志收集实战

    0x00 简介 本文主要介绍在k8s中收集应用的日志方案,应用运行中日志,一般情况下都需要收集存储到一个集中的日志管理系统中,可以方便对日志进行分析统计,监控,甚至用于机器学习,智能分析应用系统问题, ...

  10. JAVASCRIPT 分层概念

    1)底层(框架提供): 封装DOM和Event相关操作,提供跨浏览器兼容的接口,扩展原生javascript语言本身不提供的但又特实用的接口,例如namespace; 2)抽象类层(框架提供 统一自定 ...