Spring boot @Value 获取配置文件中单一属性信息

1,配置文件

server:
  port: 6019

spring:
  datasource:
    username: bjfk_base
    password: bjfk_base
    url: jdbc:mysql://192.168.1.161:3306/ccp_bjfk?useUnicode=true&characterEncoding=utf-8&useSSL=false&zeroDateTimeBehavior=convertToNull
    driver-class-name: com.mysql.jdbc.Driver

mybatis:
  mapper-locations: classpath:mybatis/mapper/*Mapper.xml
  type-aliases-package: com.cn.ehong.cloud.border.prevention.control.receive.model

#showSql
logging:
  file : data-receive-surveillance.log
  level:
    root : info
    com:
      example:
        mapper : debug

surveillanceVehicleApiUrl: http://192.168.1.239:6015/dataCollect/doc/surveillanceVehicleMng
surveillanceMobileApiUrl: http://192.168.1.239:6015/dataCollect/doc/surveillanceMobileMng
#采集区域编号 1110:三河  1111:大厂  1112:固安  1113:开发区 1100: 所有
surveillanceArea: 1110
surveillanceAreaCommon: 1100


2.获取使用

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;;


@Configuration
public class SurveillanceDataSynchronization {


  @Value("${surveillanceVehicleApiUrl}")
  private String surveillanceVehicleApiUrl;

  @Value("${surveillanceMobileApiUrl}")
  private String surveillanceMobileApiUrl;

  @Value("${surveillanceArea}")
  private String surveillanceArea;

  @Value("${surveillanceAreaCommon}")
  private String surveillanceAreaCommon;



}

3.截图

Spring boot @Value 获取配置文件中单一属性信息_第1张图片

你可能感兴趣的:(Java)