@Autowired magic in SpringBoot

Disclosure: I’m quite an experienced developer (currently go/python/bit of rust, scala/c# in the past), but a newbie when it comes to Spring Boot.

Recently, I’ve had to use it in one of my projects and somewhere in the code, I’ve come across this int…


This content originally appeared on DEV Community and was authored by Mirek Sedzinski

Disclosure: I'm quite an experienced developer (currently go/python/bit of rust, scala/c# in the past), but a newbie when it comes to Spring Boot.

Recently, I've had to use it in one of my projects and somewhere in the code, I've come across this interesting annotation:
@Autowired

When I've read about it, I couldn't believe my eyes:

In Spring Boot, the @Autowired annotation is used for automatic dependency injection.
This means that Spring will automatically resolve and inject any beans that your object depends on.

I'm familiar with Dependency Injection, but I've never thought that anyone could use, or even propose to use, such an approach.

It's pure magic. I strongly believe that DI should be explicit, and the developer should be aware of what dependencies are injected into his/her class.

Here is, in my opinion, a much better approach to the problem:
https://github.com/google/wire

Wire is a compile-time dependency injection tool. Dependencies are defined in a separate file, and the developer is always aware of what is injected into his/her class.

I'm curious about your opinion on this topic. Do you think that @Autowired is a good approach to DI? Or maybe you prefer a more explicit approach like Wire? Or maybe you have your own way of doing DI? I'm looking forward to your answers.


This content originally appeared on DEV Community and was authored by Mirek Sedzinski


Print Share Comment Cite Upload Translate Updates
APA

Mirek Sedzinski | Sciencx (2024-06-16T10:01:26+00:00) @Autowired magic in SpringBoot. Retrieved from https://www.scien.cx/2024/06/16/autowired-magic-in-springboot/

MLA
" » @Autowired magic in SpringBoot." Mirek Sedzinski | Sciencx - Sunday June 16, 2024, https://www.scien.cx/2024/06/16/autowired-magic-in-springboot/
HARVARD
Mirek Sedzinski | Sciencx Sunday June 16, 2024 » @Autowired magic in SpringBoot., viewed ,<https://www.scien.cx/2024/06/16/autowired-magic-in-springboot/>
VANCOUVER
Mirek Sedzinski | Sciencx - » @Autowired magic in SpringBoot. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/16/autowired-magic-in-springboot/
CHICAGO
" » @Autowired magic in SpringBoot." Mirek Sedzinski | Sciencx - Accessed . https://www.scien.cx/2024/06/16/autowired-magic-in-springboot/
IEEE
" » @Autowired magic in SpringBoot." Mirek Sedzinski | Sciencx [Online]. Available: https://www.scien.cx/2024/06/16/autowired-magic-in-springboot/. [Accessed: ]
rf:citation
» @Autowired magic in SpringBoot | Mirek Sedzinski | Sciencx | https://www.scien.cx/2024/06/16/autowired-magic-in-springboot/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.