Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
SpringCloud-study
提交
a6a3112e
S
SpringCloud-study
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
SpringCloud-study
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SpringCloud-study
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
a6a3112e
编写于
1月 10, 2023
作者:
Q
qinyingjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:feign和hystrix单独一个模块
上级
be6f985f
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
312 addition
and
40 deletion
+312
-40
pom.xml
pom.xml
+2
-0
springcloud-service-config/pom.xml
springcloud-service-config/pom.xml
+54
-0
springcloud-service-config/src/main/java/com/kwan/springcloud/ConfigApplication.java
...src/main/java/com/kwan/springcloud/ConfigApplication.java
+18
-0
springcloud-service-config/src/main/resources/application.yaml
...gcloud-service-config/src/main/resources/application.yaml
+21
-0
springcloud-service-config/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
...est/java/com/kwan/springcloud/PortalApplicationTests.java
+13
-0
springcloud-service-feign/pom.xml
springcloud-service-feign/pom.xml
+62
-0
springcloud-service-feign/src/main/java/com/kwan/springcloud/FeignApplication.java
.../src/main/java/com/kwan/springcloud/FeignApplication.java
+20
-0
springcloud-service-feign/src/main/java/com/kwan/springcloud/api/ComputeClient.java
...src/main/java/com/kwan/springcloud/api/ComputeClient.java
+1
-1
springcloud-service-feign/src/main/java/com/kwan/springcloud/api/ComputeClientHystrix.java
...n/java/com/kwan/springcloud/api/ComputeClientHystrix.java
+15
-0
springcloud-service-feign/src/main/java/com/kwan/springcloud/controller/FeignController.java
...java/com/kwan/springcloud/controller/FeignController.java
+0
-0
springcloud-service-feign/src/main/java/com/kwan/springcloud/service/FeignService.java
.../main/java/com/kwan/springcloud/service/FeignService.java
+40
-0
springcloud-service-feign/src/main/resources/application.yaml
...ngcloud-service-feign/src/main/resources/application.yaml
+13
-0
springcloud-service-feign/src/test/java/com/kwan/springcloud/FeignApplicationTests.java
...test/java/com/kwan/springcloud/FeignApplicationTests.java
+13
-0
springcloud-service-portal/pom.xml
springcloud-service-portal/pom.xml
+1
-15
springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java
...src/main/java/com/kwan/springcloud/PortalApplication.java
+0
-2
springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java
...ava/com/kwan/springcloud/controller/PortalController.java
+5
-22
springcloud-service-portal/src/main/java/com/kwan/springcloud/service/PortalService.java
...main/java/com/kwan/springcloud/service/PortalService.java
+34
-0
未找到文件。
pom.xml
浏览文件 @
a6a3112e
...
...
@@ -30,6 +30,8 @@
<module>
springcloud-service-goods-9300
</module>
<module>
springcloud-service-common
</module>
<module>
springcloud-service-portal
</module>
<module>
springcloud-service-config
</module>
<module>
springcloud-service-feign
</module>
<module>
springcloud-service-eureka
</module>
</modules>
...
...
springcloud-service-config/pom.xml
0 → 100644
浏览文件 @
a6a3112e
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-parent
</artifactId>
<version>
1.0.0
</version>
</parent>
<artifactId>
springcloud-service-config
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
springcloud-service-config
</name>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-common
</artifactId>
<version>
1.0.0
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-server
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-config-server
</artifactId>
<version>
1.4.7.RELEASE
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
springcloud-service-config/src/main/java/com/kwan/springcloud/ConfigApplication.java
0 → 100644
浏览文件 @
a6a3112e
package
com.kwan.springcloud
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.config.server.EnableConfigServer
;
@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
public
class
ConfigApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ConfigApplication
.
class
,
args
);
}
}
springcloud-service-config/src/main/resources/application.yaml
0 → 100644
浏览文件 @
a6a3112e
#端口号
server
:
port
:
7001
spring
:
application
:
name
:
config-service
#服务名称
cloud
:
config
:
server
:
git
:
uri
:
http://gitcode.net/qyj19920704/springcloud-config
searchPaths
:
config-repo
username
:
13113691357
password
:
15671628341qwe
#服务提供者
eureka
:
client
:
service-url
:
defaultZone
:
http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/
\ No newline at end of file
springcloud-service-config/src/test/java/com/kwan/springcloud/PortalApplicationTests.java
0 → 100644
浏览文件 @
a6a3112e
package
com.kwan.springcloud
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
PortalApplicationTests
{
@Test
void
contextLoads
()
{
}
}
springcloud-service-feign/pom.xml
0 → 100644
浏览文件 @
a6a3112e
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-parent
</artifactId>
<version>
1.0.0
</version>
</parent>
<artifactId>
springcloud-service-feign
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
springcloud-service-feign
</name>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-common
</artifactId>
<version>
1.0.0
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-server
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-feign
</artifactId>
<version>
1.4.7.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-hystrix
</artifactId>
<version>
1.4.7.RELEASE
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
springcloud-service-feign/src/main/java/com/kwan/springcloud/FeignApplication.java
0 → 100644
浏览文件 @
a6a3112e
package
com.kwan.springcloud
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
@EnableCircuitBreaker
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
public
class
FeignApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
FeignApplication
.
class
,
args
);
}
}
springcloud-service-
portal
/src/main/java/com/kwan/springcloud/api/ComputeClient.java
→
springcloud-service-
feign
/src/main/java/com/kwan/springcloud/api/ComputeClient.java
浏览文件 @
a6a3112e
...
...
@@ -16,7 +16,7 @@ import java.io.Serializable;
* @version : 2.2.0
* @date : 2023/1/10 13:45
*/
@FeignClient
(
"goods-service/kwanGoodsInfo"
)
@FeignClient
(
value
=
"goods-service/kwanGoodsInfo"
,
fallback
=
ComputeClientHystrix
.
class
)
public
interface
ComputeClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
...
...
springcloud-service-feign/src/main/java/com/kwan/springcloud/api/ComputeClientHystrix.java
0 → 100644
浏览文件 @
a6a3112e
package
com.kwan.springcloud.api
;
import
com.kwan.springcloud.response.Result
;
import
org.springframework.stereotype.Component
;
import
java.io.Serializable
;
@Component
public
class
ComputeClientHystrix
implements
ComputeClient
{
@Override
public
Result
selectOne
(
Serializable
id
)
{
return
Result
.
error
(
"feign方式请求 服务不可用 请求失败"
);
}
}
springcloud-service-
portal
/src/main/java/com/kwan/springcloud/controller/FeignController.java
→
springcloud-service-
feign
/src/main/java/com/kwan/springcloud/controller/FeignController.java
浏览文件 @
a6a3112e
文件已移动
springcloud-service-feign/src/main/java/com/kwan/springcloud/service/FeignService.java
0 → 100644
浏览文件 @
a6a3112e
package
com.kwan.springcloud.service
;
import
com.kwan.springcloud.response.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
@Slf4j
@Service
public
class
FeignService
{
/**
* http直接访问
*/
private
static
final
String
GOODS_URL
=
"http://localhost:9100/kwanGoodsInfo/"
;
/**
* eureka访问
*/
private
static
final
String
GOODS_URL_2
=
"http://goods-service/kwanGoodsInfo/"
;
@Autowired
RestTemplate
restTemplate
;
// @HystrixCommand(fallbackMethod = "addServiceFallback")
public
Result
addService
(
String
id
)
{
//调用远程的controller
return
restTemplate
.
getForEntity
(
GOODS_URL_2
+
id
,
Result
.
class
).
getBody
();
}
public
Result
addServiceFallback
(
String
id
)
{
log
.
info
(
"失败id={}"
,
id
);
return
Result
.
error
(
"ribbon方式请求 服务不可用 请求失败"
);
}
}
springcloud-service-feign/src/main/resources/application.yaml
0 → 100644
浏览文件 @
a6a3112e
#端口号
server
:
port
:
8081
spring
:
application
:
name
:
feign-service
#服务名称
#服务提供者
eureka
:
client
:
service-url
:
defaultZone
:
http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/
\ No newline at end of file
springcloud-service-feign/src/test/java/com/kwan/springcloud/FeignApplicationTests.java
0 → 100644
浏览文件 @
a6a3112e
package
com.kwan.springcloud
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
PortalApplicationTests
{
@Test
void
contextLoads
()
{
}
}
springcloud-service-portal/pom.xml
浏览文件 @
a6a3112e
...
...
@@ -14,7 +14,6 @@
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.kwan.springcloud
</groupId>
<artifactId>
springcloud-service-common
</artifactId>
...
...
@@ -26,23 +25,11 @@
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-netflix-eureka-server
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-feign
</artifactId>
<version>
1.4.7.RELEASE
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
...
...
@@ -51,5 +38,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
\ No newline at end of file
springcloud-service-portal/src/main/java/com/kwan/springcloud/PortalApplication.java
浏览文件 @
a6a3112e
...
...
@@ -3,10 +3,8 @@ package com.kwan.springcloud;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
public
class
PortalApplication
{
...
...
springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java
浏览文件 @
a6a3112e
package
com.kwan.springcloud.controller
;
import
com.kwan.springcloud.response.Result
;
import
com.kwan.springcloud.service.PortalService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.Serializable
;
/**
...
...
@@ -21,23 +18,11 @@ import java.io.Serializable;
* @date : 2023/1/8 11:12
*/
@RestController
@RequestMapping
(
"portal"
)
@RequestMapping
(
"
/
portal"
)
public
class
PortalController
{
/**
* http直接访问
*/
private
static
final
String
GOODS_URL
=
"http://localhost:9100/kwanGoodsInfo/"
;
/**
* eureka访问
*/
private
static
final
String
GOODS_URL_2
=
"http://goods-service/kwanGoodsInfo/"
;
/**
* 服务对象
*/
@Autowired
private
RestTemplate
restTemplat
e
;
private
PortalService
portalServic
e
;
/**
* 通过主键查询单条数据
...
...
@@ -46,9 +31,7 @@ public class PortalController {
* @return 单条数据
*/
@GetMapping
(
value
=
"{id}"
,
produces
=
MediaType
.
APPLICATION_PROBLEM_JSON_VALUE
)
public
Result
selectOne
(
@PathVariable
Serializable
id
)
{
//调用远程的controller
ResponseEntity
<
Result
>
forEntity
=
restTemplate
.
getForEntity
(
GOODS_URL_2
+
id
,
Result
.
class
);
return
Result
.
ok
(
forEntity
);
public
Result
selectOne
(
@PathVariable
String
id
)
{
return
portalService
.
addService
(
id
);
}
}
\ No newline at end of file
springcloud-service-portal/src/main/java/com/kwan/springcloud/service/PortalService.java
0 → 100644
浏览文件 @
a6a3112e
package
com.kwan.springcloud.service
;
import
com.kwan.springcloud.response.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
@Slf4j
@Service
public
class
PortalService
{
/**
* http直接访问
*/
private
static
final
String
GOODS_URL
=
"http://localhost:9100/kwanGoodsInfo/"
;
/**
* eureka访问
*/
private
static
final
String
GOODS_URL_2
=
"http://goods-service/kwanGoodsInfo/"
;
@Autowired
RestTemplate
restTemplate
;
public
Result
addService
(
String
id
)
{
//调用远程的controller
return
restTemplate
.
getForEntity
(
GOODS_URL_2
+
id
,
Result
.
class
).
getBody
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录