-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRpcConfig.java
More file actions
93 lines (83 loc) · 3.01 KB
/
Copy pathRpcConfig.java
File metadata and controls
93 lines (83 loc) · 3.01 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.tlcsdm.gen.config;
import com.tlcsdm.gen.service.RpcService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
import org.springframework.remoting.rmi.RmiServiceExporter;
/**
* RMI远程调用配置
*
* <p>
* 客户端代码 <blockquote><pre>
* @Configuration
* public class RpcClient {
*
* @Bean
* public RmiProxyFactoryBean RmiRpcService() {
* RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
* rmiProxyFactoryBean.setServiceUrl("rmi://127.0.0.1:8769/rpcService");
* rmiProxyFactoryBean.setServiceInterface(RpcService.class);
* return rmiProxyFactoryBean;
* }
*
* //@Bean
* //public HttpInvokerProxyFactoryBean HttpInvokerRpcService() {
* // HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
* // httpInvokerProxyFactoryBean.setServiceUrl("http://127.0.0.1:8669/gen/invoker");
* // httpInvokerProxyFactoryBean.setServiceInterface(RpcService.class);
* // return httpInvokerProxyFactoryBean;
* //}
* }
*
*
* @SpringBootTest
* public class RpcTest {
* @Autowired
* private RpcService rpcService;
*
@Test
* public void excel() throws Exception {
* System.out.println(rpcService.getGitInfo());
* }
* }
* </pre></blockquote>
* </p>
* @author: TangLiang
* @date: 2021/12/13 13:46
* @since: 1.0
*/
@Configuration
@RequiredArgsConstructor
@ConditionalOnProperty(name = "gen.rpc.enabled", havingValue = "true")
public class RpcConfig {
private final RpcService rpcService;
@Value("${gen.rpc.rmiPort}")
private int rmiPort;
@Value("${gen.rpc.rmiServiceName}")
private String rmiServiceName;
@Bean
@ConditionalOnProperty(name = "gen.rpc.rmi", havingValue = "true")
public RmiServiceExporter getRmiServiceExporter() {
RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
rmiServiceExporter.setServiceName(rmiServiceName);
rmiServiceExporter.setService(rpcService);
rmiServiceExporter.setServiceInterface(RpcService.class);
rmiServiceExporter.setRegistryPort(rmiPort);
return rmiServiceExporter;
}
/**
* org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping 它的作用就是把Spring
* MVC上下文中以“/”开头的Bean进行对外提供服务
*/
@Bean("/invoker")
@ConditionalOnProperty(name = "gen.rpc.httpInvoker", havingValue = "true")
public HttpInvokerServiceExporter getHttpInvokerServiceExporter() {
HttpInvokerServiceExporter httpInvokerServiceExporter = new HttpInvokerServiceExporter();
httpInvokerServiceExporter.setService(rpcService);
httpInvokerServiceExporter.setServiceInterface(RpcService.class);
return httpInvokerServiceExporter;
}
}