Spring boot read the configuration manner

Spring boot reads the configuration file for the main convention application files and named Road King profile.

Spring boot to read application file configurations to provide some convenient method, are the following.

We assumed that the content application files are:

wx.appKey=Test
wx.appSecret=abcdefghik

1.Value comment

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
@Component
public class appConfig{
 
   @Value("${app.appKey}")
   private String appKey;
 
   @Value("${app.appSecret}")
   private String appSecret;

 
    get和set方法...
}

2. @ ConfigurationProperties comment


@Component
@ConfigurationProperties(prefix = "wx")
public class appConfig{
 
   private String appKey;
   private String appSecret;
  
   get和set方法...
 
}

 

Guess you like

Origin blog.csdn.net/syilt/article/details/92206302