cloud_config学习_1

简单调了下,使用git作为配置文件管理工具,没调通(有时间再写),现在要学HBuilder作为开发App前端,头疼。

好了,开始继续瞅瞅

1.pom文件中配置

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

2.Application上配置

@SpringBootApplication
@EnableConfigServer

3.配置yml文件

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/tokeneros/spring-cloud-learning.git
          password:
          username:
          search-pats: /**
      label: master
server:
  port: 8771

这样就配置好了,接下来尝试看能不能通

http://localhost:8771/foo/local、

http://localhost:8771/address-dev.properties都可以瞅瞅

上面是服务端,我配置客户端时会出现问题,总是访问不到

下面是配置过程

1.配置pom

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

2.配置yml

spring:
  application:
    name: config-client
  cloud:
    config:
      label: master
      profile: dev
#     dev开发环境配置文件
#     test测试环境
#     pro正式环境
      uri: http://localhost:8771/
server:
  port: 8772

3.配置Application

@SpringBootApplication
@RestController
public class ConfigClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigClientApplication.class, args);
    }

    @Value("${foo}")
    String foo;

    /**
     * 会一直报Could not resolve placeholder 'foo' in value "${foo}"
     * @return
     */
//    @Bean
//    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
//        PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
//        c.setIgnoreUnresolvablePlaceholders(true);
//        return c;
//    }


    @RequestMapping(value = "/hi")
    public String hi(){return foo;}
}

然后就启动不了

最后在启动项中找到

Fetching config from server at : http://localhost:8888

发现他不去我配置的8771端口去查询,然后没办法,将server配置yml的端口号修改为8888,问题算是解决了,但是他不按照我们指定的思路来,还是存在着问题,不过目前不打算深究

转载于:https://www.cnblogs.com/kongkongFabian/p/9987173.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值