I don't understand spring dependency injection very well.

if you write your own class, you can understand how to inject it, but how to inject a class that comes with java, such as File
File file = new File (filePath)
like this?
and what if the filePath is calculated while the program is running?

this is just a layer
if it"s something like new OutputStreamWriter (new FileOutputStream (new File (filePath), how do you inject it?

Mar.10,2021

I don't know if I understand your problem. If File, doesn't need to be injected, just use it. If you have to inject, it usually encapsulates a business-level object that contains some of the File, you want to operate on, and then inject the business object into it. In a nutshell, what you usually inject is something like singleton, while for objects that are dynamically created and destroyed, injection is meaningless.

Menu