cn.structured.rpc.configuration.AutoRpcConfiguration Maven / Gradle / Ivy
package cn.structured.rpc.configuration;
import cn.hutool.core.util.StrUtil;
import cn.structured.rpc.annotation.RpcClient;
import cn.structured.rpc.entity.RemoteService;
import cn.structured.rpc.handler.IRpcHandler;
import cn.structured.rpc.properties.RpcProperties;
import lombok.SneakyThrows;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.util.ClassUtils;
import java.util.Map;
import java.util.Optional;
/**
* rpc自动装配
*
* @author chuck
* @version 2024/07/17 下午4:01
* @since 1.8
*/
@Configuration
@ImportAutoConfiguration(RpcProperties.class)
@ConditionalOnClass(value = {RpcProperties.class})
public class AutoRpcConfiguration implements ApplicationListener, ResourceLoaderAware {
@javax.annotation.Resource
private RpcProperties rpcProperties;
private MetadataReaderFactory metadataReaderFactory;
@SneakyThrows
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
Map serviceList = rpcProperties.getServiceList();
//获取启动类注解
Map beansWithAnnotation = event.getApplicationContext().getBeansWithAnnotation(SpringBootApplication.class);
Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy