SpringBoot客户端调用服务端的配置文件,启动后无法加载页面
2019-04-09 21:02
507 查看
如果你的客户端向服务端请求了git的配置文件,@value成功加载后,再通过页面进不去控制层,可能是因为客户端请求到了配置文件的同时,配置文件里配置了port端口号,把客户端的端口号覆盖掉了。代码如下
这是springboot的启动类
package com.new0409.new0409; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; @EnableDiscoveryClient @SpringBootApplication public class New0409Application { @Bean @LoadBalanced RestTemplate restTemplate(){ return new RestTemplate(); } public static void main(String[] args) { SpringApplication.run(New0409Application.class, args); } }
这是controller层
package com.a1824.demo.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * 当有请求/fresh节点的时候,会重新请求一次ConfigServer去拉取最新的配置文件 * 请求/fresh需要有几点要求:1.加actuator的依赖 2.SpringCloud1.5以上需要设置 management.security.enabled=false * 这个Controller的作用是查看from这个key的值 */ @RestController @RefreshScope //开启更新功能 @RequestMapping("/aa") public class TestController { @Value("${rmq.namesrv_addr}") private String fromValue; /** * 返回配置文件中的值 */ @GetMapping("/aa") public String returnFormValue(){ return fromValue; } }
这是bootstrap.xml
spring: application: name: hellxztest #指定了配置文件的应用名 cloud: config: uri: http://localhost:8888/ #Config server的uri profile: dev #指定的环境 label: master #指定分支 server: port: 7002
下面这行控制台提示信息提示了,端口号被修改,而修改后的端口号正是配置文件里的端口号。
2019-04-09 19:36:23.267 INFO 8868 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 10031
怎么恢复暂时不清楚,搞清楚了上传解决方案。
相关文章推荐
- SpringMVC异常总结:启动tomcat时出错,无法正取加载spring配置文件
- spring-boot 作为dubbo客户端 调用 dubbo 服务端 配置以及代码段
- springboot 修改启动时默认加载application.properties文件以及加载指定配置文件
- spring boot通过jar包启动时,配置文件的加载顺序
- spring boot启动时加载外部配置文件的方法
- SpringBoot学习二:application.porperties中的配置不生效导致改端口后不生效原因,无法加载resource下的资源文件
- spring-boot 加载本地静态资源文件路径配置
- tomcat启动时没有把spring配置文件定义的bean加载进来
- spring-boot 加载本地静态资源文件路径配置
- Spring Boot加载配置文件
- SpringCloud系列九:SpringCloudConfig 基础配置(SpringCloudConfig 的基本概念、配置 SpringCloudConfig 服务端、抓取配置文件信息、客户端使用 SpringCloudConfig 进行配置、单仓库目录匹配、应用仓库自动选择、仓库匹配模式)
- spring boot加载多个配置文件,yml或properties类型
- spring boot 加载本地静态资源文件路径配置
- dubbo服务端启动注册成功,客户端无法调用问题
- spring-boot 如何加载rsources下面的自定义配置文件
- [深入剖析Spring Boot]启动、事件通知与配置加载原理
- Spring Web项目spring配置文件随服务器启动时自动加载
- SpringBoot注解与启动与配置文件介绍(2)
- 两种SpringBoot加载YML配置文件的方法
- Spring配置文件xsi:schemaLocation无法解析导致启动失败的解决方案 转!classpath:/org/springframework/