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=
    

      

      

  • 相关阅读:
    react 在IE9下input标签使用e.target.value取值失败
    mingw-w64 about
    Cygwin .a 转为 .lib .dll
    windows terminal
    ssh key authentication
    sshd_config 2
    sshd_config
    bash sudo redirect multiple lines to file
    计算几何
    vs cli
  • 原文地址:https://www.cnblogs.com/yanqin/p/6971531.html
Copyright © 2011-2022 走看看