zoukankan      html  css  js  c++  java
  • spring注解导入配置文件

    @Configuration
    @ImportResource("classpath:config.xml")
    public class StoreConfig {
     
        @Value("${jdbc.url}")
        private String url;
         
        @Value("${jdbc.username}")
        private String username;
         
        @Value("${jdbc.password}")
        private String password;
         
        @Bean
        public MyDriverManager myDriverManager(){
            return new MyDriverManager(url,username,password);
        }
    }
    

      @Value 不需要get、set方法

    ConfigurationProperties 注解,是需要的,他能帮你自动将配置文件的对应的  prefix开头的属性,注入。
    @ConfigurationProperties(locations = "classpath:mail.properties", 
                             ignoreUnknownFields = false, 
                             prefix = "mail")
    public class MailProperties { 
      public static class Smtp {  
        private boolean auth;  
        private boolean starttlsEnable;  
        // ... getters and setters 
      }
      @NotBlank private String host;
      private int port;  
      private String from; 
      private String username;
      private String password; 
      @NotNull private Smtp smtp; 
      // ... getters and setters
    }
    

      

    mail.host=localhost
    mail.port=25
    mail.smtp.auth=false
    mail.smtp.starttls-enable=false
    mail.from=me@localhost
    mail.username=
    mail.password=
    

      

      

  • 相关阅读:
    SCOI2020游记
    关于我
    WC2020游记
    CSP-S 2019 游记
    回文自动机学习笔记
    全自动数字论证机(迫真)
    树状数组上二分
    《伊豆的舞女》 读书小记
    雅礼集训2019 Day5
    雅礼集训2019 Day4
  • 原文地址:https://www.cnblogs.com/yanqin/p/6971531.html
Copyright © 2011-2022 走看看