proxy Static方式
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方式的更多相关文章
- Java-HTTP连接时如何使用代理(二)—— Proxy类方式
阅读这篇文章之前,请先阅读 Java-HTTP连接时如何使用代理(一)——System.Property方式 除了使用 System.setProperty() 的方式之外,还可使用 Proxy 的方 ...
- RestTemplate proxy 设置方式
RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory() {{ setProxy(new ja ...
- 动态代理 Proxy InvocationHandler
前奏 代理模式 代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等. 代理类与委托类之间通常 ...
- [转]JAVA的动态代理机制及Spring的实现方式
JAVA 代理实现 代理的实现分动态代理和静态代理,静态代理的实现是对已经生成了的JAVA类进行封装. 动态代理则是在运行时生成了相关代理累,在JAVA中生成动态代理一般有两种方式. JDK自带实现方 ...
- Cglib动态代理实现方式
Cglib动态代理实现方式 我们先通过一个demo看一下Cglib是如何实现动态代理的. 首先定义个服务类,有两个方法并且其中一个方法用final来修饰. public class PersonSer ...
- 二进制方式部署Kubernetes 1.6.0集群(开启TLS)
本节内容: Kubernetes简介 环境信息 创建TLS加密通信的证书和密钥 下载和配置 kubectl(kubecontrol) 命令行工具 创建 kubeconfig 文件 创建高可用 etcd ...
- 面试官:你说你懂动态代理,那你知道为什么JDK中的代理类都要继承Proxy吗?
之前我已经写过了关于动态代理的两篇文章,本来以为这块应该没啥问题,没想到今天又被难住了- 太难了!!! 之前文章的链接: 动态代理学习(一)自己动手模拟JDK动态代理. 动态代理学习(二)JDK动态代 ...
- Java 动态代理原理图解 (附:2种实现方式详细对比)
动态代理在 Java 中有着广泛的应用,例如:Spring AOP 面向切面编程,Hibernate 数据查询.以及 RPC Dubbo 远程调用等,都有非常多的实际应用@mikechen 目录 ...
- htnl中的遮罩层以及定位方式
在页面显示遮罩层,例如:一个div的css样式: $msk.css({ "top":"0", "left":"0", & ...
随机推荐
- 家庭记账本之微信小程序(七)
最后成果 在经过对微信小程序的简单学习后,对于微信小程序也稍有理解,在浏览学习过别人的东西后自己也制作了一个,觉得就是有点low,在今后的学习中会继续完善这个微信小程序 //index.js //获取 ...
- 使用AMBER中遇到的一些问题
1.读取蛋白问题 读取无配体pdb文件(loadpdb complex.pdb)时,出现一堆 FATAL: Atom .R<ARG >.A<HD1 > does not hav ...
- cocos2d-x JS 富文本
var str1 = "兑换成功后,系统会生成“";var str2 = "红包兑换码";var str3 = "”,请复制该兑换码,并粘贴在&quo ...
- PHP on CentOS (LAMP) and wordpress
http://php.net/manual/zh/install.windows.php https://www.unixmen.com/install-wordpress-centos-7-linu ...
- C#设计模式(11)——外观模式(Facade Pattern)(转)
一.引言 在软件开发过程中,客户端程序经常会与复杂系统的内部子系统进行耦合,从而导致客户端程序随着子系统的变化而变化,然而为了将复杂系统的内部子系统与客户端之间的依赖解耦,从而就有了外观模式,也称作 ...
- 使用mybatis-generator插件自动生成代码的步骤
注意:首先你这个项目一定要是个maven项目 1.首先你需要在pom文件中导入相关的依赖,如下代码 <plugin> <groupId>org.mybatis.generato ...
- tomcat的jks的私钥导出nginx需要的key文件
方法一: 1.先用keytool导出pfx文件.第一个123456是jks密码,后边两个是新生成的pfx的密码 keytool -v -importkeystore -srckeystore D:\\ ...
- Html img 标签
Html img 标签 <html> <body> <!-- img 标签用于显示图片.src="xxx.jpg" 指定图片路径名称--> &l ...
- 剑指offer(55)链表中环的入口节点
题目描述 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null. 题目分析 1.一快一慢指针,先找到碰撞点. 2.然后碰撞点到入口节点的距离就是头结点到入口节点的距离. 具体原理可 ...
- Deep Dream 模型
本节的代码参考了TensorFlow 源码中的示例程序https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/ ...