SpringBoot之@Value与@ConfigurationProperties注解

1.@Value

1.本来想自己总结一下,查了一下发现这位同志写的真好,直接给链接吧 (点击跳转) ?

2.spring.profiles.active

1.有关于active 的,那篇文章有作解释,在此我再补充一下(点击跳转)?
在这里插入图片描述

还有一个注解 同样有获取配置的作用 @ConfigurationProperties

1.application.yml 文件
server:
  port: 9098

spring:
  application:
    name: order-service
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/shop?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    druid:
      initial-size: 5
      min-idle: 5
      max-active: 20
      max-wait: 1000
      test-on-borrow: true
  redis:
    host: 127.0.0.1
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:10086/eureka
  instance:
    prefer-ip-address: true
    ip-address: 127.0.0.1
    instance-id: ${eureka.instance.ip-address}.${server.port}
    lease-renewal-interval-in-seconds: 3
    lease-expiration-duration-in-seconds: 10
sc:
  jwt:
    pubKeyPath: D:/rsa/rsa.pub # 公钥地址
2.JavaBean中使用
@Configuration //声明为配置类  让其可以扫描到
@Data  //lombok
@ConfigurationProperties(prefix = "sc.jwt")  //映射application.yml
public class JwtProperties {

    private String pubKeyPath;// 公钥

    private PublicKey publicKey; // 公钥


    @PostConstruct
    public void init(){
        try {
            // 获取公钥和私钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            System.out.println("初始化公钥失败!");
            throw new RuntimeException();
        }
    }

}
3.图解

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值