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,问题算是解决了,但是他不按照我们指定的思路来,还是存在着问题,不过目前不打算深究