zoukankan      html  css  js  c++  java
  • Springboot配置文件映射

    添加类和配置文件的映射:

    1.定义映射类

    @Component

    @PropertySource("classpath:config/XX.properties")

    public class ConfigClass{

      @Value("$name")

      public String userName;

    ... ...

    }

    2. properties文件内容

    XX.properties:

    name=Lorry

    ... ...

    3使用如下:

    public class RestController{

      @Autowired

      ConfigClass config;

      public void method(){

        logger.info(config.userName);

      }

    }

    4. 说明

    即可,@Component作用是被spring发现,@PropertySource是指定映射文件,@Value指定映射字段。使用类只要声明为@Autowired即可。

  • 相关阅读:
    QT1 HelloWorld
    SDL2.0 播放YUV
    vim寄存器
    Makefile模板
    apue初学--DIR
    apue初学--平台的判断
    各种推导式
    文件操作
    list tuple dict set
    字符串和编码
  • 原文地址:https://www.cnblogs.com/xiashiwendao/p/9818485.html
Copyright © 2011-2022 走看看