top.osjf.sdk.spring.proxy.AbstractJdkProxySupport Maven / Gradle / Ivy
/*
* Copyright 2024-? the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.osjf.sdk.spring.proxy;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
/**
* Abstract jdk dynamic proxy method/Spring dynamic registration support class.
*
* The process is to first rely on the dynamic proxy {@link InvocationHandler} of
* JDK to create a proxy object,hand it over to Spring, and when Spring calls the proxy
* object, execute the {@link #invoke(Object, Method, Object[])} method,which performs
* unified logical processing and distribution within this method,
*
*
The method entrusted to Spring to create bean objects is to implement the
* {@link FactoryBean} interface and dynamically register beans through
* {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}
*
*
If you want to standardize processing, you can access {@link HierarchicalProxySupport}.
*
* @param The data type of the proxy class.
* @author zhangpengfei
* @since 1.0.0
*/
public abstract class AbstractJdkProxySupport extends FactoryProxyBeanSupport implements InvocationHandler {
/**
* Constructor for a {@code Class} type.
*
* @param type a {@code Class} type
*/
public AbstractJdkProxySupport(@NonNull Class type) {
super(type);
}
@Override
@Nullable
protected T getObject0() {
return ProxyUtils.createJdkProxy(getType(), this);
}
}