知其然不知其所以然,大厂常问面试技术如何复习?
1、热门面试题及答案大全
面试前做足功夫,让你面试成功率提升一截,这里一份热门350道一线互联网常问面试题及答案助你拿offer
2、多线程、高并发、缓存入门到实战项目pdf书籍
3、文中提到面试题答案整理
4、Java核心知识面试宝典
覆盖了JVM 、JAVA集合、JAVA多线程并发、JAVA基础、Spring原理、微服务、Netty与RPC、网络、日志、Zookeeper、Kafka、RabbitMQ、Hbase、MongoDB 、Cassandra、设计模式、负载均衡、数据库、一致性算法 、JAVA算法、数据结构、算法、分布式缓存、Hadoop、Spark、Storm的大量技术点且讲解的非常深入
server.port=7001
配置服务注册中心
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
git仓库配置
spring.cloud.config.server.git.uri=http://git.oschina.net/didispace/SpringCloud-Learning/
spring.cloud.config.server.git.searchPaths=Chapter1-1-8/config-repo
spring.cloud.config.server.git.username=username
spring.cloud.config.server.git.password=password
- 在应用主类中,新增
@EnableDiscoveryClient
注解,用来将config-server注册到上面配置的服务注册中心上去。
@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
- 启动该应用,并访问
http://localhost:1111/
,可以在Eureka Server的信息面板中看到config-server已经被注册了。
Paste_Image.png
config-client配置
- 同config-server一样,在
pom.xml
的dependencies节点中新增spring-cloud-starter-eureka
依赖,用来注册服务:
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-config
org.springframework.cloud
spring-cloud-starter-eureka
- 在
bootstrap.properties
中,按如下配置:
spring.application.name=didispace
server.port=7002
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server
spring.cloud.config.profile=dev
其中,通过eureka.client.serviceUrl.defaultZone
参数指定服务注册中心,用于服务的注册与发现,再将spring.cloud.config.discovery.enabled
参数设置为true,开启通过服务来访问Config Server的功能,最后利用spring.cloud.config.discovery.serviceId
参数来指定Config Server注册的服务名。这里的spring.application.name
和spring.cloud.config.profile
如之前通过URI的方式访问时候一样,用来定位Git中的资源。
- 在应用主类中,增加
@EnableDiscoveryClient
注解,用来发现config-server服务,利用其来加载应用配置
@EnableDiscoveryClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
- 沿用之前我们创建的Controller来加载Git中的配置信息
@RefreshScope
@RestController
public class TestController {
@Value(“${from}”)
private String from;
@RequestMapping(“/from”)
public String from() {
return this.from;
}
}
- 完成了上述配置之后,我们启动该客户端应用。若启动成功,访问
http://localhost:1111/
,可以在Eureka Server的信息面板中看到该应用已经被注册成功了。
Paste_Image.png
- 访问客户端应用提供的服务:
http://localhost:7002/from
,此时,我们会返回在Git仓库中didispace-dev.properties
文件配置的from属性内容:“git-dev-1.0”。
配置刷新
有时候,我们需要对配置内容做一些实时更新的场景,那么Spring Cloud Config是否可以实现呢?答案显然是可以的。下面,我们看看如何进行改造来实现配置内容的实时更新。
最后
俗话说,好学者临池学书,不过网络时代,对于大多数的我们来说,我倒是觉得学习意识的觉醒很重要,这是开始学习的转折点,比如看到对自己方向发展有用的信息,先收藏一波是一波,比如如果你觉得我这篇文章ok,先点赞收藏一波。这样,等真的沉下心来学习,不至于被找资料分散了心神。慢慢来,先从点赞收藏做起,加油吧!
另外,给大家安排了一波学习面试资料:
以上就是本文的全部内容,希望对大家的面试有所帮助,祝大家早日升职加薪迎娶白富美走上人生巅峰!
)]
以上就是本文的全部内容,希望对大家的面试有所帮助,祝大家早日升职加薪迎娶白富美走上人生巅峰!