代码拉取完成,页面将自动刷新
目前仅支持nacos作为服务发现
<dependencies>
<!--服务端依赖-->
<dependency>
<groupId>io.gitee.yswysw</groupId>
<artifactId>y-rpc-server-spring-boot-starter</artifactId>
<version>${y-rpc.version}</version>
</dependency>
<!--客户端依赖-->
<dependency>
<groupId>io.gitee.yswysw</groupId>
<artifactId>y-rpc-client-spring-boot-starter</artifactId>
<version>${y-rpc.version}</version>
</dependency>
</dependencies>
@RpcService
public class TestServiceImpl implements TestService {
@Override
public String sayHello(String name) {
return name + ": hello";
}
}
@RestController
public class ClientController {
@RpcClient
private TestService service;
@GetMapping("/{test}")
public String test(@PathVariable String test) {
return service.sayHello(test);
}
}
file -> new -> project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ysw.rpc</groupId>
<artifactId>create-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>2.7.10</spring-boot.version>
<y-rpc.version>1.0.0</y-rpc.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.gitee.yswysw</groupId>
<artifactId>y-rpc-client-spring-boot-starter</artifactId>
<version>${y-rpc.version}</version>
</dependency>
<dependency>
<groupId>io.gitee.yswysw</groupId>
<artifactId>y-rpc-server-spring-boot-starter</artifactId>
<version>${y-rpc.version}</version>
</dependency>
</dependencies>
</project>
public interface TestService {
String sayHello(String name);
}
@RpcService
public class TestServiceImpl implements TestService {
@Override
public String sayHello(String name) {
return name + ": hello";
}
}
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
application.yml
server:
port: 7878
spring:
application:
name: rpc-create-demo
cloud:
nacos:
discovery:
namespace: d2380f0c-b0bf-40bd-a4ea-b43d66576a1e
server-addr: localhost:8848
这里直接改造了启动类
@RestController
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
@RpcClient
private TestService service;
@GetMapping("test")
public String test(String name) {
return service.sayHello(name);
}
}
下图划线的就是启动成功的日志,因为这里是一个项目既做服务端又做客户端的原因是两条
可以看到已经注册成功
这里使用的是 ApiPost7 进行调试
请求成功!!教程到此结束,最后附上目录结构
└─main
├─java
│ └─com
│ └─ysw
│ └─rpc
│ └─create_demo
│ Application.java
│ TestService.java
│ TestServiceImpl.java
│
└─resources
application.yml
需要配置中央仓库才可以拉到依赖……
下面是setting.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>...</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers></servers>
<mirrors>
</mirrors>
<profiles>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>ali</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enable>true</enable>
</releases>
<snapshots>
<enable>true</enable>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>repo1</id>
<repositories>
<repository>
<id>repo1</id>
<url>https://repo1.maven.org/maven2/</url>
<releases>
<enable>true</enable>
</releases>
<snapshots>
<enable>true</enable>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>aliyun</activeProfile>
<activeProfile>repo1</activeProfile>
</activeProfiles>
</settings>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型