1

Eureka 配置是从配置服务器中完美提取的,但端点不是从配置服务器中提取的。如果我遗漏了什么,请告诉我。

@Service
@RefreshScope
public class OrderService {

    @Autowired
    private OrderRepo orderRepo;

    @Autowired
    @Lazy
    private RestTemplate restTemplate;

    @Value("${payment.endpoints}")
    private String DO_PAYMENT_URL;

    public TransactionResponse saveOrder(TransactionRequest request) {
        System.err.println(request);
        TransactionResponse response = new TransactionResponse();
        Order order = request.getOrder();
        Payment payment = request.getPayment();
        payment.setOrderId(order.getId());
        response.setOrder(orderRepo.save(order));
        // rest call
        Payment paymentResponse =
                // restTemplate.postForObject("http://localhost:8083/payment/doPayment",payment,
                // Payment.class);
                // restTemplate.postForObject("http://PAYMENT-SERVICE/payment/doPayment",payment,
                // Payment.class);
                restTemplate.postForObject(DO_PAYMENT_URL + "/doPayment", payment, Payment.class);
        response.setMessage(
                paymentResponse.getStatus().equalsIgnoreCase("success") ? "payment successful" : "payment failed");
        response.setTransactionId(paymentResponse.getTransactionId());
        return response;
    }
}

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.hk</groupId>
    <artifactId>order-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>order-service</name>
    <description>order service</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR11</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

git-config 文件: https ://gitlab.com/nickybesra/microservice-cloud-config/-/blob/main/application.yml

订购服务 bootstrap.yml:

spring:
  cloud:
    config:
      uri:
        - http://localhost:9196

微服务代码: https ://gitlab.com/nickybesra/microservice-2021

4

0 回答 0