wuxw
2019-05-16 48cd77ef661d2bb3fb8b46ff795d382413112bb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.java110.core.proxy;
 
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;
 
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
 
 
/**
 * @ClassName ServiceProxyFactory
 * @Description TODO
 * @Author wuxw
 * @Date 2019/5/15 15:56
 * @Version 1.0
 * add by wuxw 2019/5/15
 **/
@Component
public class ServiceProxyFactory implements FactoryBean<ITestService> {
 
    @Override
    public ITestService getObject() throws Exception {
        Class<?> interfaceType = ITestService.class;
        InvocationHandler handler = new ServiceInvocationHandler(interfaceType);
        return (ITestService) Proxy.newProxyInstance(interfaceType.getClassLoader(),
                new Class[]{interfaceType}, handler);
    }
 
    @Override
    public Class<?> getObjectType() {
        return ITestService.class;
    }
 
    @Override
    public boolean isSingleton() {
        return true;
    }
 
}