This article is participating in the Java Theme Month – Java Debug Notes Event, see the event link for details

How do I use Java to save strings to text files?

I’m looking at some blogs on SpringSource, and in one of them the author is using @Inject, I think he could also use @AutoWired.

Here is the code:

@Inject private CustomerOrderService customerOrderService;
Copy the code

I don’t know the difference between @inject and @autowired, it would be appreciated if someone explained their difference, which one to use in what situation?

Answer:


A lot of knowledge points, really need to write out will master ! ! !   \color{purple} a lot of knowledge points, really need to write out just can master!! {~}

Suppose you mean javax.inject.Inject annotation here. Inject is part of the Java CDI (Context and Dependency Injection) standard introduced in Java EE 6 (JSR-299). More. Spring chooses to support the @inject annotation synonymous with its own annotation using @Autowired.

So, to answer your question, this @Autowired is Spring’s own annotation. Inject is part of Java technology (called CDI) that defines a spring-like dependency injection standard. In Spring applications, the way these two annotations work is related to Spring’s decision to support some JSR-299 annotations in addition to its own.

Answer:

The key difference (between the spring documentation when reading) between @Autowired and @Inject is that @Autowired has “necessary” attributes while @Inject no longer has “necessary” attributes.

The article translated from kgs4h5t57thfb6iyuz6dqtun5y ac4c6men2g7xr2a – stackoverflow – com. Translate. Goog/questions / 7…

** Author’s suggestion: Indeed, @inject ** is not used much in the author’s work


Welcome to my column S t a c k O v e r F l o w . I select the best questions and answers and test them frequently in interviews ! ! !   \color{red} Welcome to my column StackOverFlow, I will filter the quality of the interview test!! {~}


There are the latest and elegant ways to do this, and I will write my thoughts on this q&A at the end of the article \color{red} has the latest, elegant implementation, and I will also write my opinion on this question at the end of the article {~}

Thank you for reading this, if this article is well written and if you feel there is something to it

Ask for a thumbs up 👍 ask for attention ❤️ ask for share 👥 for 8 abs I really very useful!!

If there are any mistakes in this blog, please comment, thank you very much! ❤ ️ ❤ ️ ❤ ️ ❤ ️