国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - 詳解Spring Boot加載properties和yml配置文件

詳解Spring Boot加載properties和yml配置文件

2020-09-10 14:15賽亞人之神 Java教程

本篇文章主要介紹了詳解Spring Boot加載properties和yml配置文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一、系統(tǒng)啟動(dòng)后注入配置

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.example.config;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
 
/**
 * @author: GrandKai
 * @create: 2016-09-01 11:24
 */
@Configuration
@PropertySource(ignoreResourceNotFound = true, value = {"classpath:/config/email.properties","classpath:/config/email.yml"}, name = "email")
public class Config {}

需要在ApplicationContext中注冊(cè)配置

?
1
2
AnnotationConfigEmbeddedWebApplicationContext context = (AnnotationConfigEmbeddedWebApplicationContext) app.run("參數(shù)1");
context.register(Config.class);

用以下方式取值

?
1
2
Environment env = context.getEnvironment();
System.out.println(env.getProperty("address"));

email.yml文件配置如下:

?
1
2
server:
 address: 127.0.0.1

二、在命令行傳入注入到程序中

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
public class Main {
  public static void main(String... args) {
    //initialize the command line parsing stuff
    OptionParser parser = new OptionParser();
    parser.accepts("greeting").withRequiredArg();
    OptionSet options = parser.parse(args);
 
    //create the actual Spring PropertySource
    PropertySource<?> ps = new JOptCommandLinePropertySource(options);
 
    //setup the Spring context
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.getEnvironment().getPropertySources().addLast(ps);
    //register the property source with the environment
 
    ctx.register(Greeter.class);
    ctx.refresh();
    Greeter greeter = ctx.getBean(Greeter.class);
    greeter.sayGreeting();
  }
}
 
@Component
class Greeter {
  @Inject private Environment env;
 
 
  //the following would also work
  //@Value("${greeting}")
  //private String greeting;   
 
  /**
   * Print out the 'greeting' property if it exists, and otherwise, "Welcome!".
   */
  public void sayGreeting() {
    System.out.println(env.getProperty("greeting", "Welcome!"));
  }
}
 
 
 
 
public static void main(String [] args) {
  SimpleCommandLinePropertySource ps = new SimpleCommandLinePropertySource(args);
  @SuppressWarnings("resource")
  AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  ctx.getEnvironment().getPropertySources().addFirst(ps);
  ctx.register(ApplicationConfig.class);
  ctx.refresh();
}
 
 
@Configuration
@EnableScheduling
@ComponentScan("com.mycompany.package")
@PropertySource(
    value = {"classpath:/application.properties", "file:${config.location}"},
    ignoreResourceNotFound = true
  )
class ApplicationConfig {
 
  @Bean
  public static PropertySourcesPlaceholderConfigurer propertyConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
  }
}
 
@Component
class MyComponent {
 
  @Value("${my.property.data}")
  private String myPropertyData;
 
 
  @Scheduled(fixedDelayString = "${schedule.delay.period}")
  public void run() {
     :
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://www.jianshu.com/p/eadfecea1f2d

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲电影第三页 | 成人免费在线 | 成人午夜视频免费 | 免费人成黄页网站在线一区二区 | 成人午夜免费视频 | 99这里只有精品视频 | 欧美日韩一二三区 | 亚洲第一区在线 | 国产一区久久 | 最新国产毛片 | 久久se精品一区精品二区 | 日本在线视频一区二区三区 | 精品无码三级在线观看视频 | 亚洲一区二区三区四区五区午夜 | 国产精品成人在线观看 | 国产欧美综合一区二区三区 | 午夜电影网址 | 福利在线播放 | 国产一区二区三区成人 | 成人精品| 国产一区二区三区免费看 | 亚洲国产精品久久人人爱 | 99精品欧美一区二区三区综合在线 | 人人爽人人爽人人片av | 在线观看国产 | 精品国产久 | 在线国产小视频 | 国产亚洲精品久久久久动 | 精品成人免费一区二区在线播放 | 国内精品视频在线观看 | 欧美国产日韩一区 | 五月婷婷激情 | 国产成人综合在线观看 | 欧美精品一区二区三区在线 | 国产精品久久久久久吹潮 | 亚洲欧美成人综合 | 色视频免费在线观看 | 含羞草www国产在线视频 | 亚洲八区| 精品视频在线播放 | 日韩中文字幕免费视频 |