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. Linux系统查看本机ip地址

    1. 使用ifconfig命令查看inet对应的ip地址就是 2. 如果不能使用ifconfig命令,需要安装net-tools工具,使用yum install net-tools安装即可.

  2. linux进程虚拟地址空间

    转载源 在多任务操作系统中,每个进程都运行在属于自己的内存沙盘中.这个沙盘就是虚拟地址空间(Virtual Address Space),在32位模式下它是一个4GB的内存地址块.在Linux系统中, ...

  3. 《CSS世界》读书笔记(九)

    <!-- <CSS世界>张鑫旭著 --> content内容生成技术 1. content 辅助元素生成 清除浮动: .clear:after { content: ''; d ...

  4. oracle 误删除数据,回退表数据

    select * from sh_gonghuo_renyuan as of timestamp to_timestamp('2017-11-17 16:00:00','yyyy-mm-dd hh24 ...

  5. P3648 [APIO2014]序列分割(斜率优化dp)

    P3648 [APIO2014]序列分割 我们先证明,分块的顺序对结果没有影响. 我们有一个长度为3的序列$abc$ 现在我们将$a,b,c$分开来 随意枚举一种分块方法,如$(ab)(c)$,$(a ...

  6. Python3 pip命令报错:Fatal error in launcher: Unable to create process using '"'

    Python3 pip命令报错:Fatal error in launcher: Unable to create process using '"' 一.问题 环境:win7 同时安装py ...

  7. VS2013的x86汇编语言开发环境配置

    转载:https://blog.csdn.net/infoworld/article/details/45085415 转载:https://blog.csdn.net/u014792304/arti ...

  8. codeforce 955c --Sad powers 思路+二分查找

    这一题的题意是   定义一个数,该数特点是为a的p次方 (a>0,p>1) 再给你n个询问,每个询问给出一个区间,求区间内该数的数目. 由于给出的询问数极大(10e5) 所以,容易想到应该 ...

  9. C++类的大小计算汇总

    C++中类涉及到虚函数成员.静态成员.虚继承.多继承.空类等. 类,作为一种类型定义,是没有大小可言的. 类的大小,指的是类的对象所占的大小.因此,用sizeof对一个类型名操作,得到的是具有该类型实 ...

  10. Go 函数方法

    在 Go 语言中,函数和方法不太一样,有明确的概念区分.其他语言中,比如 PHP 函数就是方法,方法 就是函数,但在 Go 语言中,函数是不属于任何结构体.类型的方法,也就是说函数是没有接收者的:而方 ...