SpringCloud学习笔记(九、配置客户端)

<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的显示,

写在最后

为了这次面试,也收集了很多的面试题!

以下是部分面试题截图

Java程序员秋招三面蚂蚁金服,我总结了所有面试题,也不过如此

ute(“version”, version);

m.addAttribute(“ps”,ps);

return “products”;

}

}

product.html

product.html添加对version的显示,

写在最后

为了这次面试,也收集了很多的面试题!

以下是部分面试题截图

[外链图片转存中…(img-LeYp7OLJ-1714468565251)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值