最后
金三银四马上就到了,希望大家能好好学习一下这些技术点
学习视频:
大厂面试真题:
- artifactId: productService
然后在pom.xml中添加如下代码:
<?xml version="1.0" encoding="UTF-8"?><project xmlns=“http://maven.apache.org/POM/4.0.0”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”>
4.0.0
cn.zxuqian
productService
1.0-SNAPSHOT
org.springframework.boot
spring-boot-starter-parent
2.0.1.RELEASE
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-starter-config
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
Finchley.M9
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-milestones
Spring Milestones
https://repo.spring.io/libs-milestone
false
我们继续使用了spring-cloud-starter-netflix-eureka-client
以使产品服务自动注册到eureka服务中。然后还使用了spring-cloud-starter-config
读取配置服务中心的配置文件。这个项目只是一个简单的spring web项目。
在src/main/resources
下创建bootstrap.yml
文件,添加如下内容:
spring:
application:
name: product-service
cloud:
config:
uri: http://localhost:8888
在配置中心的git仓库中创建product-service.yml
文件 添加如下配置并提交:
server:
port: 8081
此配置指定了产品服务的端口为8081。接着创建Application
类,添加如下代码:
package cn.zxuqian;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@EnableDiscoveryClient
注解将指示spring cloud自动把本服务注册到eureka。最后创建cn.zxuqian.controllers.ProductController
控制器,提供/products
API,返回示例数据:
package cn.zxuqian.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ProductController {
@RequestMapping(“/products”)
public String productList() {
return “外套,夹克,毛衣,T恤”;
}
}
配置Web客户端
打开我们之前创建的web
项目,在pom.xml
中新添Hystrix
依赖:
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
然后更新Application
类的代码:
package cn.zxuqian;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@EnableCircuitBreaker
@EnableDiscoveryClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
面试结束复盘查漏补缺
每次面试都是检验自己知识与技术实力的一次机会,面试结束后建议大家及时总结复盘,查漏补缺,然后有针对性地进行学习,既能提高下一场面试的成功概率,还能增加自己的技术知识栈储备,可谓是一举两得。
以下最新总结的阿里P6资深Java必考题范围和答案,包含最全MySQL、Redis、Java并发编程等等面试题和答案,用于参考~
重要的事说三遍,关注+关注+关注!
更多笔记分享
+关注!**
[外链图片转存中…(img-YK1gTEc1-1715324731412)]
[外链图片转存中…(img-KKbYmi6c-1715324731412)]
更多笔记分享
[外链图片转存中…(img-KWCgNvZt-1715324731413)]