From partme-ai-full-stack-skills
Guides Spring Cloud microservices development using Eureka for service discovery, Config Server for configuration, Gateway for API routing, load balancing, and circuit breakers.
npx claudepluginhub partme-ai/full-stack-skills --plugin t2ui-skillsThis skill uses the workspace's default tool permissions.
Spring Cloud 是一套完整的微服务解决方案,提供了服务注册与发现、配置管理、网关、负载均衡、熔断器等组件。
Creates isolated Git worktrees for feature branches with prioritized directory selection, gitignore safety checks, auto project setup for Node/Python/Rust/Go, and baseline verification.
Executes implementation plans in current session by dispatching fresh subagents per independent task, with two-stage reviews: spec compliance then code quality.
Dispatches parallel agents to independently tackle 2+ tasks like separate test failures or subsystems without shared state or dependencies.
Spring Cloud 是一套完整的微服务解决方案,提供了服务注册与发现、配置管理、网关、负载均衡、熔断器等组件。
Eureka Server:
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
application.yml:
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
Eureka Client:
@SpringBootApplication
@EnableEurekaClient
public class UserServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication.class, args);
}
}
application.yml:
spring:
application:
name: user-service
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
Config Server:
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
application.yml:
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/example/config-repo
search-paths: '{application}'
Config Client:
spring:
application:
name: user-service
cloud:
config:
uri: http://localhost:8888
name: user-service
profile: dev
Gateway 配置:
@SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
application.yml:
spring:
cloud:
gateway:
routes:
- id: user-service
uri: lb://user-service
predicates:
- Path=/api/users/**
filters:
- StripPrefix=1
- id: order-service
uri: lb://order-service
predicates:
- Path=/api/orders/**
filters:
- StripPrefix=1
路由配置类:
@Configuration
public class GatewayConfig {
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
return builder.routes()
.route("user-service", r -> r
.path("/api/users/**")
.uri("lb://user-service"))
.route("order-service", r -> r
.path("/api/orders/**")
.uri("lb://order-service"))
.build();
}
}
使用 RestTemplate:
@Configuration
public class RestTemplateConfig {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
使用 WebClient:
@Configuration
public class WebClientConfig {
@Bean
@LoadBalanced
public WebClient.Builder webClientBuilder() {
return WebClient.builder();
}
}
服务调用:
@Service
public class OrderService {
private final RestTemplate restTemplate;
public OrderService(@LoadBalanced RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public User getUser(Long userId) {
return restTemplate.getForObject(
"http://user-service/api/users/{id}",
User.class,
userId
);
}
}
依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
配置:
resilience4j:
circuitbreaker:
instances:
userService:
registerHealthIndicator: true
slidingWindowSize: 10
failureRateThreshold: 50
waitDurationInOpenState: 10000
使用:
@Service
public class OrderService {
private final CircuitBreaker circuitBreaker;
private final RestTemplate restTemplate;
public OrderService(
CircuitBreakerRegistry circuitBreakerRegistry,
RestTemplate restTemplate
) {
this.circuitBreaker = circuitBreakerRegistry.circuitBreaker("userService");
this.restTemplate = restTemplate;
}
public User getUser(Long userId) {
return circuitBreaker.executeSupplier(() ->
restTemplate.getForObject(
"http://user-service/api/users/{id}",
User.class,
userId
)
);
}
}
依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
启用 Feign:
@SpringBootApplication
@EnableFeignClients
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class, args);
}
}
定义 Feign Client:
@FeignClient(name = "user-service")
public interface UserServiceClient {
@GetMapping("/api/users/{id}")
User getUserById(@PathVariable Long id);
@PostMapping("/api/users")
User createUser(@RequestBody User user);
}
使用:
@Service
public class OrderService {
private final UserServiceClient userServiceClient;
public OrderService(UserServiceClient userServiceClient) {
this.userServiceClient = userServiceClient;
}
public Order createOrder(Long userId, Order order) {
User user = userServiceClient.getUserById(userId);
// 创建订单逻辑
return order;
}
}
依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
配置:
spring:
sleuth:
sampler:
probability: 1.0
microservices/
├── eureka-server/ # 服务注册中心
├── config-server/ # 配置中心
├── gateway/ # API 网关
├── user-service/ # 用户服务
├── order-service/ # 订单服务
└── product-service/ # 商品服务
同步调用(Feign):
@FeignClient(name = "user-service")
public interface UserServiceClient {
@GetMapping("/api/users/{id}")
User getUserById(@PathVariable Long id);
}
异步调用(消息队列):
@Service
public class OrderService {
private final RabbitTemplate rabbitTemplate;
public void publishOrderEvent(Order order) {
rabbitTemplate.convertAndSend("order.exchange", "order.created", order);
}
}
<!-- Eureka Client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- Gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- Feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- Circuit Breaker -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>