Java Proxy动态代理
先看个例子:
接口
package example;
public interface Basic {
public void hello();
}
接口的实现类
package example;
public class BasicService implements Basic {
public void hello() {
Sysytem.out.println("Hello, world");
}
}
实现了InvocationHandler接口的类
package example;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LogHandler implements InvocationHandler {
private Logger logger = Logger.getLogger(this.getClass().getName());
private Object delegate;
public Object bind(Object delegate) {
this.delegate = delegate;
return Proxy.newProxyInstance(delegate.getClass().getClassLoader(), delegate.getClass().getInterfaces(), this);
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Object result = null;
try {
log("method starts..." + method);
result = method.invoke(delegate, args);
log("method ends..." + method);
} catch (Exception e) {
log(e.toString());
}
&nb
相关文档:
Java学习从入门到精通
一、 JDK (Java Development Kit)
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......
一.获得控制台用户输入的信息
Java代码
/** */
/**获得控制台用户输入的信息
* @return
* @throws IOException
*/
public
  ......
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Vector;
/*虽然现在用APACHE COMMONS DBCP可以非常方便的建立数据库连接池, ......
Database
MySQL
PostgreSQL
Firebird(suitable for embedded database)
HSQLDB(160K)
DB Tie
Hibernate
Ibatis
JDO
OSCache
JBossCache
Business Tie
Spring
UI Tie
Structs
JSF
Tapestry
Webwork
Flex
DWR(Ajax
Framework)
ZK(Ajax
Framework)
Dojo(Ajax
Framework)
Development Tools
......
java exception 解决方案 - 我的异常网|异常|exception 730 - org.hibernate.LazyInitializationException:could not initialize proxy 731 - 警告: Error setting value 732 - override and commit 733 - Building workspace has encountered a problem. Errors during build 734 - Could not open the editor: An ......