Add Profile (properties) - Test of pile design based on spring-boot

When writing tests, some content can be placed in the configuration file.

 

The first step: the new configuration file conf.properties

 

 

 

 Step Two: Write a profile class MockConf

 

 

 1 package mock.mockdemo.conf;
 2 
 3 import lombok.Data;
 4 import org.springframework.beans.factory.annotation.Value;
 5 import org.springframework.context.annotation.PropertySource;
 6 import org.springframework.stereotype.Component;
 7 
 8 
 9 @Data
10 @Component
11 @PropertySource("classpath:config/conf.properties")
12 public class MockConf {
13     @Value("${user_num}")
14     public String userNum;
15 }

Step 3: Add the interface and implementation class

interface:

 

Implementing Classes:

 

 

 

 The fourth step: write controller

 

 

test:

 

 

 

 The results: You can get normal configuration file to content

 

 

 Source Address:

https://github.com/yuesest/mockdemo

Guess you like

Origin www.cnblogs.com/moonpool/p/11521109.html