<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”>
springcloud
edu.hpu.springcloud
1.0-SNAPSHOT
4.0.0
product-view-service-feign
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.cloud
spring-cloud-starter-zipkin
org.springframework.cloud
spring-cloud-starter-config
bootstrap.yml
与 Spring Cloud Config (配置)相关的属性必须配置在 bootstrap.yml 中,config 部分内容才能被正确加载。因为 config 的相关配置会先application.yml,而 bootstrap.yml 的加载也是先于 application.yml。
spring:
cloud:
config:
label: master
profile: dev
discovery:
enabled: true
serviceId: config-server
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
application.yml
变化不大,把注册中心交给了bootstrap.yml,
spring:
application:
name: product-view-service-feign
thymeleaf:
cache: false
prefix: classpath:/templates/
suffix: .html
encoding: UTF-8
content-type: text/html
mode: HTML5
zipkin:
base-url: http://localhost:9411
ProductController
用@Value获取配置中version的值,并放入Model,
package edu.hpu.springcloud.controller;
import edu.hpu.springcloud.pojo.Product;
import edu.hpu.springcloud.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
public class ProductController {
@Autowired
ProductService productService;
@Value(“${version}”)
String version;
@RequestMapping(“/products”)
public Object products(Model m){
List ps=productService.listProducts();
m.addAttribute(“version”, version);
m.addAttribute(“ps”,ps);
return “products”;
}
}
product.html
product.html添加对version的显示,
写在最后
为了这次面试,也收集了很多的面试题!
以下是部分面试题截图
ute(“version”, version);
m.addAttribute(“ps”,ps);
return “products”;
}
}
product.html
product.html添加对version的显示,
写在最后
为了这次面试,也收集了很多的面试题!
以下是部分面试题截图
[外链图片转存中…(img-LeYp7OLJ-1714468565251)]