新增远程调用Spring自动扫描注入功能
This commit is contained in:
parent
e816d87d81
commit
6cb3355bc9
@ -151,6 +151,11 @@
|
|||||||
<artifactId>basic-pojo</artifactId>
|
<artifactId>basic-pojo</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ink.wgink</groupId>
|
||||||
|
<artifactId>basic-properties</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<!-- wgink end -->
|
<!-- wgink end -->
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package ink.wgink.util.remote.rest.handler;
|
package ink.wgink.util.remote.rest.handler;
|
||||||
|
|
||||||
import ink.wgink.annotation.remote.RemoteServer;
|
import ink.wgink.annotation.remote.rest.params.RemoteServerParams;
|
||||||
import ink.wgink.annotation.remote.method.RemoteDeleteMethod;
|
import ink.wgink.annotation.remote.rest.method.RemoteDeleteMethod;
|
||||||
import ink.wgink.annotation.remote.method.RemoteGetMethod;
|
import ink.wgink.annotation.remote.rest.method.RemoteGetMethod;
|
||||||
import ink.wgink.annotation.remote.method.RemotePostMethod;
|
import ink.wgink.annotation.remote.rest.method.RemotePostMethod;
|
||||||
import ink.wgink.annotation.remote.method.RemotePutMethod;
|
import ink.wgink.annotation.remote.rest.method.RemotePutMethod;
|
||||||
import ink.wgink.annotation.remote.params.RemoteHeaderParams;
|
import ink.wgink.annotation.remote.rest.params.RemoteHeaderParams;
|
||||||
import ink.wgink.annotation.remote.params.RemoteJsonBodyParams;
|
import ink.wgink.annotation.remote.rest.params.RemoteJsonBodyParams;
|
||||||
import ink.wgink.annotation.remote.params.RemotePathParams;
|
import ink.wgink.annotation.remote.rest.params.RemotePathParams;
|
||||||
import ink.wgink.annotation.remote.params.RemoteQueryParams;
|
import ink.wgink.annotation.remote.rest.params.RemoteQueryParams;
|
||||||
import ink.wgink.exceptions.ParamsException;
|
import ink.wgink.exceptions.ParamsException;
|
||||||
import ink.wgink.exceptions.base.SystemException;
|
import ink.wgink.exceptions.base.SystemException;
|
||||||
import ink.wgink.util.RegexUtil;
|
import ink.wgink.util.RegexUtil;
|
||||||
@ -242,7 +242,7 @@ public class RestRemoteHandler implements InvocationHandler {
|
|||||||
private String getRemotePath(Parameter[] parameters, Object[] args) {
|
private String getRemotePath(Parameter[] parameters, Object[] args) {
|
||||||
for (int i = 0; i < parameters.length; i++) {
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
Parameter parameter = parameters[i];
|
Parameter parameter = parameters[i];
|
||||||
if (!parameter.isAnnotationPresent(RemoteServer.class)) {
|
if (!parameter.isAnnotationPresent(RemoteServerParams.class)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (args[i] == null) {
|
if (args[i] == null) {
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
package ink.wgink.util.remote.rest.scanner;
|
||||||
|
|
||||||
|
import ink.wgink.util.remote.rest.proxy.RestRemoteProxy;
|
||||||
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: RemoteRestFactoryBean
|
||||||
|
* @Description: 远程调用bean工厂
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2021/9/20 9:27 上午
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class RemoteRestFactoryBean<T> implements InitializingBean, FactoryBean<T> {
|
||||||
|
|
||||||
|
private String innerClassName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getObject() throws Exception {
|
||||||
|
return (T) RestRemoteProxy.getInstance(Class.forName(innerClassName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getObjectType() {
|
||||||
|
try {
|
||||||
|
return Class.forName(innerClassName);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSingleton() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInnerClassName(String innerClassName) {
|
||||||
|
this.innerClassName = innerClassName;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package ink.wgink.util.remote.rest.scanner;
|
||||||
|
|
||||||
|
import ink.wgink.annotation.remote.rest.RemoteService;
|
||||||
|
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||||
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
|
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||||
|
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||||
|
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: RemoteRestScanner
|
||||||
|
* @Description: Rest远程类扫描器
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2021/9/20 9:26 上午
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class RemoteRestScanner extends ClassPathBeanDefinitionScanner {
|
||||||
|
|
||||||
|
public RemoteRestScanner(BeanDefinitionRegistry registry) {
|
||||||
|
super(registry);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerDefaultFilters() {
|
||||||
|
this.addIncludeFilter(new AnnotationTypeFilter(RemoteService.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<BeanDefinitionHolder> doScan(String... basePackages) {
|
||||||
|
Set<BeanDefinitionHolder> beanDefinitions = super.doScan(basePackages);
|
||||||
|
for (BeanDefinitionHolder holder : beanDefinitions) {
|
||||||
|
GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
|
||||||
|
definition.getPropertyValues().add("innerClassName", definition.getBeanClassName());
|
||||||
|
definition.setBeanClass(RemoteRestFactoryBean.class);
|
||||||
|
}
|
||||||
|
return beanDefinitions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
|
||||||
|
return beanDefinition.getMetadata().hasAnnotation(RemoteService.class.getName());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package ink.wgink.util.remote.rest.scanner;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName: RemoteRestScanner
|
||||||
|
* @Description: Rest远程类扫描
|
||||||
|
* @Author: wanggeng
|
||||||
|
* @Date: 2021/9/19 11:49 下午
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class RemoteRestScannerConfiguration implements BeanFactoryPostProcessor, ApplicationContextAware {
|
||||||
|
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
|
||||||
|
RemoteRestScanner scanner = new RemoteRestScanner((BeanDefinitionRegistry) configurableListableBeanFactory);
|
||||||
|
scanner.setResourceLoader(this.applicationContext);
|
||||||
|
scanner.scan("**.remote");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
this.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
import ink.wgink.annotation.remote.RemoteServer;
|
import ink.wgink.annotation.remote.rest.params.RemoteServerParams;
|
||||||
import ink.wgink.annotation.remote.method.RemoteDeleteMethod;
|
import ink.wgink.annotation.remote.rest.method.RemoteDeleteMethod;
|
||||||
import ink.wgink.annotation.remote.method.RemoteGetMethod;
|
import ink.wgink.annotation.remote.rest.method.RemoteGetMethod;
|
||||||
import ink.wgink.annotation.remote.method.RemotePostMethod;
|
import ink.wgink.annotation.remote.rest.method.RemotePostMethod;
|
||||||
import ink.wgink.annotation.remote.method.RemotePutMethod;
|
import ink.wgink.annotation.remote.rest.method.RemotePutMethod;
|
||||||
import ink.wgink.annotation.remote.params.RemoteJsonBodyParams;
|
import ink.wgink.annotation.remote.rest.params.RemoteJsonBodyParams;
|
||||||
import ink.wgink.annotation.remote.params.RemotePathParams;
|
import ink.wgink.annotation.remote.rest.params.RemotePathParams;
|
||||||
import ink.wgink.annotation.remote.params.RemoteQueryParams;
|
import ink.wgink.annotation.remote.rest.params.RemoteQueryParams;
|
||||||
import ink.wgink.pojo.dtos.user.UserDTO;
|
import ink.wgink.pojo.dtos.user.UserDTO;
|
||||||
import ink.wgink.pojo.result.SuccessResult;
|
import ink.wgink.pojo.result.SuccessResult;
|
||||||
import ink.wgink.pojo.result.SuccessResultList;
|
import ink.wgink.pojo.result.SuccessResultList;
|
||||||
@ -27,25 +27,25 @@ public class RemoteTest {
|
|||||||
|
|
||||||
public interface IDemo {
|
public interface IDemo {
|
||||||
@RemoteGetMethod("/app/user-expand/get-user-release/{userId}")
|
@RemoteGetMethod("/app/user-expand/get-user-release/{userId}")
|
||||||
UserDTO getUser(@RemoteServer String remotePath, @RemotePathParams("userId") String userId);
|
UserDTO getUser(@RemoteServerParams String remotePath, @RemotePathParams("userId") String userId);
|
||||||
|
|
||||||
@RemoteGetMethod("/app/user-expand/list-user-release")
|
@RemoteGetMethod("/app/user-expand/list-user-release")
|
||||||
List<UserDTO> listUser(@RemoteServer String remotePath);
|
List<UserDTO> listUser(@RemoteServerParams String remotePath);
|
||||||
|
|
||||||
@RemoteGetMethod("/app/user-expand/listpage-user-release")
|
@RemoteGetMethod("/app/user-expand/listpage-user-release")
|
||||||
SuccessResultList<List<UserDTO>> listPageUser(@RemoteServer String remotePath, @RemoteQueryParams("page") Integer page, @RemoteQueryParams("size") Integer size);
|
SuccessResultList<List<UserDTO>> listPageUser(@RemoteServerParams String remotePath, @RemoteQueryParams("page") Integer page, @RemoteQueryParams("size") Integer size);
|
||||||
|
|
||||||
@RemotePostMethod("/app/user-expand/save-release")
|
@RemotePostMethod("/app/user-expand/save-release")
|
||||||
SuccessResult postRelease(@RemoteServer String remotePath, @RemoteJsonBodyParams Map<String, Object> params);
|
SuccessResult postRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams Map<String, Object> params);
|
||||||
|
|
||||||
@RemotePostMethod("/app/user-expand/save-list-release")
|
@RemotePostMethod("/app/user-expand/save-list-release")
|
||||||
SuccessResult postListRelease(@RemoteServer String remotePath, @RemoteJsonBodyParams List<Map<String, Object>> params);
|
SuccessResult postListRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams List<Map<String, Object>> params);
|
||||||
|
|
||||||
@RemotePutMethod("/app/user-expand/update-release")
|
@RemotePutMethod("/app/user-expand/update-release")
|
||||||
SuccessResult putRelease(@RemoteServer String remotePath, @RemoteJsonBodyParams Map<String, Object> params);
|
SuccessResult putRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams Map<String, Object> params);
|
||||||
|
|
||||||
@RemoteDeleteMethod("/app/user-expand/delete-release/{userIds}")
|
@RemoteDeleteMethod("/app/user-expand/delete-release/{userIds}")
|
||||||
SuccessResult deleteRelease(@RemoteServer String remotePath, @RemotePathParams("userIds") String userIds);
|
SuccessResult deleteRelease(@RemoteServerParams String remotePath, @RemotePathParams("userIds") String userIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
Loading…
Reference in New Issue
Block a user