读取自定义字段

1.定义字段

application.properties

path.pictrue.brand=/home/abc/Pictures/brand/

application-prod.properties

path.pictrue.brand=/home/xyz/Pictures/brand/

2.读取字段

PropertiesConfig.java

@Component
public class PropertiesConfig {

    @Value("${path.pictrue.brand}")
    public String pathBrand;
}

3.在需要使用的类中:

@Autowired
private PropertiesConfig pConfig;


public void testPicture() {
        
    System.out.println(pConfig.pathBrand);
}

4.生产jar包后:

java -jar xxxxx.jar 使用的是application.properties

java -jar -Dspring.profiles.active=prod xxxxx.jar 则使用的是application-prod.properties

 

相关文章:

  • 2021-11-12
  • 2022-02-08
  • 2021-11-23
  • 2021-06-28
  • 2021-11-23
  • 2021-11-23
  • 2021-12-16
  • 2022-12-23
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-23
相关资源
相似解决方案