建module(maven)

创建module的时候选择maven,不要使用springboot

1610803427892.png

工程名字叫:cloud-consumer-order80

改pom

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <parent>
  6. <artifactId>cloud2020</artifactId>
  7. <groupId>com.sgy.cloud2020</groupId>
  8. <version>1.0-SNAPSHOT</version>
  9. </parent>
  10. <modelVersion>4.0.0</modelVersion>
  11. <artifactId>cloud-consumer-order80</artifactId>
  12. <dependencies>
  13. <dependency>
  14. <groupId>org.springframework.boot</groupId>
  15. <artifactId>spring-boot-starter-web</artifactId>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework.boot</groupId>
  19. <artifactId>spring-boot-devtools</artifactId>
  20. <scope>runtime</scope>
  21. <optional>true</optional> <!-- 表示依赖不会传递 -->
  22. </dependency>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-test</artifactId>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.projectlombok</groupId>
  29. <artifactId>lombok</artifactId>
  30. <scope>provided</scope>
  31. </dependency>
  32. </dependencies>
  33. </project>

改YML

创建: application.yml

server:
  port: 80

添加启动类

package com.sgy.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Created by AaronShen on 2020/5/26
 */
@SpringBootApplication
public class OrderMain80 {
    public static void main(String[] args) {
        SpringApplication.run(OrderMain80.class,args);
    }
}

引入实体类

创建Payment

/**
 * Created by AaronShen on 2020/5/26
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Payment extends BaseEntities{
    /**
     * 主键
     */
    private String id;

    private String serial;
}

统一结果类,自行引入吧,在005-(cloud)中已经详细介绍了

创建controller

引入RestTemplate

springboot开发的http访问的客户端

创建ApplicationContextConfig,然后就可以直接注入使用了

package com.sgy.springcloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * Created by AaronShen on 2020/5/26
 */
@Configuration
public class ApplicationContextConfig {
    @Bean
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }
}

controller

package com.sgy.springcloud.controller;

import com.sgy.springcloud.entites.Payment;
import com.sgy.springcloud.entites.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * Created by AaronShen on 2020/5/26
 */
@Slf4j
@RestController
public class OrderController {
    private final static String PATMEMT_URL = "http://127.0.0.1:8090";
    @Resource
    RestTemplate restTemplate;

    @GetMapping("/consumer/payment/create")
    public R create(@RequestBody Payment payment) {
        return restTemplate.postForObject(PATMEMT_URL + "/payment/create",payment,R.class);
    }

    @GetMapping("/consumer/payment/find/{id}")
    public R find(@PathVariable(value = "id") String id) {
        return restTemplate.getForObject(PATMEMT_URL + "/payment/find/" + id,R.class);
    }
}

解决没有出现Services Tree

正常是出现如下

1610803427925.png

修改idea的workspace.xml的方式来快速打开Run Dasboard窗口

找到RunDashboard,添加如下

<option name="configurationTypes">
      <set>
        <option value="SpringBootApplicationConfigurationType" />
      </set>
    </option>

1610803427961.png

最后重启idea即可