新增Spring-Cloud配置,新增Feign配置,新增nacos配置

This commit is contained in:
lhc
2021-02-25 14:47:38 +08:00
parent 1b114aa69b
commit ad3fbd5149
11 changed files with 109 additions and 8 deletions

View File

@@ -25,6 +25,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -5,6 +5,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@@ -14,8 +16,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
@ServletComponentScan
@EnableCaching
//@EnableDiscoveryClient
//@EnableFeignClients
@EnableDiscoveryClient
@EnableFeignClients
@ComponentScan(basePackages = {"com.hcframe.**"})
public class ConfigApplication {
public static void main(String[] args) {

View File

@@ -0,0 +1,13 @@
package com.hcframe.config.module.cloud;
import com.hcframe.base.common.ResultVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient("cloud-user")
public interface ManageService {
@GetMapping("/user/manage/{name}")
ResultVO<String> getName(@PathVariable("name")String name);
}

View File

@@ -0,0 +1,24 @@
package com.hcframe.config.module.cloud.controller;
import com.hcframe.base.common.ResultVO;
import com.hcframe.config.module.cloud.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CloudController {
final
ManageService manageService;
public CloudController(ManageService manageService) {
this.manageService = manageService;
}
@GetMapping("/{name}")
public ResultVO<String> getName(@PathVariable String name){
return manageService.getName(name);
}
}

View File

@@ -1,10 +1,14 @@
server:
port: 8080
port: 8081
servlet:
context-path: /config
pagehelper:
auto-runtime-dialect: true
spring:
cloud:
nacos:
discovery:
server-addr: 192.168.1.131:8848
application:
name: cloud-config
# 缓存设置