一、@Value读取application.properties配置文件中的值
application.properties配置文件
fileName=configName
PropertiesConfig类文件
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class PropertiesConfig {
//通过@Value注解读取fileName的值
@Value("${fileName}")
private String fileName;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
}
测试
import com.model.PropertiesConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class PropertiesConfigTest {
@Autowired
private PropertiesConfig propertiesConfig;
@Test
public void test(){
System.out.