Which file-reading way should I choose in my Spring Boot Java project?

I am working on a Spring Boot Java project.
I’ll firstly explain how I handled a similar situation of my problem, and secondly, the problem itself.

A similar situation of my problem I correctly handled

I needed to get some API URLs which depends from the environment (test/prod), so I’ve decided to get these from (application-test/application-prod).properties files in combination with @Configuration @ConfigurationProperties annotations and ${spring.profiles.active} environment variable. I knew I could have the URLs in the application initialization, so, relying on Spring dependency management was the best idea to do the job (simply put, Spring Boot injects these properties before the application starts and that’s what I wanted).

The problem

I need to read some new parameters I can store in a .properties file (not the “older” ones application[-{env}].properties), but now, the difference is that I can only know which properties file I have to read after I read a request parameter, not before the application starts anymore. And most importantly, the class that should read this .properties file is not a Spring managed class. A MWE:

@Configuration
@ConfigurationProperties
@PropertySource("classpath:INAD/INAD-${spring.profiles.active}.properties")
public class MyInitializationConfig{
  private String var;
  // var getter/setter
}

@RestController
public class MyController{
  @Autowired
  MyService myService;

  @Autowired
  MyInitializationConfig myInitializationConfig;

  @PostMapping("/endpoint")
  public void endpoint(@RequestBody MyRequest myRequest){
    // here, I can get the initialized properties:
    myInitializationConfig.getProperties("configprop");

    myService.serviceMethod(myRequest);
  }
}

@Service
public class MyService{
  @Autowired
  MyInitializationConfig myInitializationConfig;

  public void serviceMethod(MyRequest myRequest){
    // here, I can get initialized properties, too:
    myInitializationConfig.getProperties("configprop");

    MyEntity myEntity = new MyEntity(myRequest);
    myEntity.entityMethod();
  }
}

// Has no Spring Boot annotations
public class MyEntity{
  private MyRequest myRequest;
  public MyEntity(MyRequest myRequest){
    this.myRequest = myRequest;
  }
  public void entityMethod(){
    // here, I would like to retrieve some .properties (not the initialized ones with MyInitializationConfig) values
  }
}

My solutions

Note that:

  1. (again) The problem is MyEntity (precisely, MyEntity.entitymethod()), while MyInitializationConfig is not the object of the problem, with that, I just wanted to show how I handled something similar to the problem I’m asking.
  2. MyEntity has not to be a singleton, it’s something I have to instantiate more times.
  3. MyEntity constructor should remain as I wrote, i.e. with only the MyRequest object parameter, by logic, and for testing purposes.

So: do you agree I can’t read these property values with Spring Boot injections (e.g. by using something like @Value in MyEntity) anymore, because, as it is currently written, MyEntity is a simply new Java object? If not, how can I use some Spring Boot injections that doesn’t require to inject something at the application initialization time, in your opinion?

Finally, I thought at two solutions:

  1. Using ordinary Java file-reading APIs, something like: new Properties().load(new FileInputStream("path/to/config.properties"))
  2. Using Spring Boot file-reading APIs, I’ve read classes such org.springframework.core.io.DefaultResourceLoader

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật