Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
movie-service
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
springcloud
movie-service
Commits
675fe133
提交
675fe133
authored
7月 09, 2019
作者:
王健
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eager-load
上级
c81ef57f
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
9 行增加
和
5 行删除
+9
-5
WebConfig.java
...java/com/xcloud/galaxy/movieservice/config/WebConfig.java
+2
-0
MovieController.java
...cloud/galaxy/movieservice/controller/MovieController.java
+1
-5
application.yml
src/main/resources/application.yml
+6
-0
没有找到文件。
src/main/java/com/xcloud/galaxy/movieservice/config/WebConfig.java
浏览文件 @
675fe133
package
com
.
xcloud
.
galaxy
.
movieservice
.
config
;
package
com
.
xcloud
.
galaxy
.
movieservice
.
config
;
import
org.springframework.cloud.client.loadbalancer.LoadBalanced
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
...
@@ -14,6 +15,7 @@ public class WebConfig {
...
@@ -14,6 +15,7 @@ public class WebConfig {
@Bean
@Bean
@LoadBalanced
RestTemplate
restTemplate
()
{
RestTemplate
restTemplate
()
{
return
new
RestTemplate
();
return
new
RestTemplate
();
}
}
...
...
src/main/java/com/xcloud/galaxy/movieservice/controller/MovieController.java
浏览文件 @
675fe133
...
@@ -34,11 +34,7 @@ public class MovieController {
...
@@ -34,11 +34,7 @@ public class MovieController {
@GetMapping
(
value
=
"/index"
)
@GetMapping
(
value
=
"/index"
)
public
User
index
()
{
public
User
index
()
{
List
<
ServiceInstance
>
instances
=
discoveryClient
.
getInstances
(
"user-service"
);
User
user
=
restTemplate
.
getForObject
(
"http://user-service/users/1"
,
User
.
class
);
List
<
String
>
urls
=
instances
.
stream
().
map
(
instance
->
instance
.
getUri
().
toString
()).
collect
(
Collectors
.
toList
());
int
anInt
=
ThreadLocalRandom
.
current
().
nextInt
(
urls
.
size
());
String
url
=
urls
.
get
(
anInt
);
User
user
=
restTemplate
.
getForObject
(
url
+
"/users/1"
,
User
.
class
);
return
user
;
return
user
;
}
}
...
...
src/main/resources/application.yml
浏览文件 @
675fe133
...
@@ -7,3 +7,8 @@ spring:
...
@@ -7,3 +7,8 @@ spring:
server-addr
:
127.0.0.1:8848
server-addr
:
127.0.0.1:8848
application
:
application
:
name
:
movie-service
name
:
movie-service
# 饥饿加载
ribbon
:
eager-load
:
enabled
:
true
clients
:
user-service
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论