I have javax.inject in my pom.xml, will spring use it automatically?

I copied pom.xml when I was going through the spring mvc tutorial online and it had:

<!-- @Inject --> <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> 

From what I understand, spring has a built-in built-in injection for dependencies, will it override the default value and use javax.inject?

I also saw slf4j in pom, without further tweaking the code or xml.

How does this work under covers, spring checks the lib folder, and if any lib is found that is overridden, does it do this?

+6
source share
3 answers

Dependency in your pom for javax.inject

  <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> 

has nothing to do with Spring. This just leads to javax.inject dependency in the project. A jar named javax.inject-1.jar . This gang is necessary if you use the @Inject annotation, which is also supported by Spring.

You can use @ Autowired / @ Resource / @ Inject to suit your needs. See here for their difference, as well as a discussion on What is the difference between @Inject and @Autowired in the Spring Framework? Which one to use under what conditions? .

As with slf4j, this is just an abstraction over frameworks such as log4j, which allows you to connect to the logging system at runtime. Spring -OSGI, Hibernate all use this internally. That's why you find addiction in your room. Hope this clarifies the situation.

+10
source

inject allows the JSR 330 to support spring. Using application annotations makes the application not tied to spring - it can be switched to Java EE 6 or to guice or other providers that support the specification.

You can use injection or spring injection (or perhaps both).

+3
source

as @Aravind said javax.inject dependency has nothing to do with spring. and it was used to get the @Inject annotation, it is part of the Java CDI standard introduced in Java EE 6 (JSR-299)

Spring using @Inject synonymous with its @Autowired annotation.
@Autowired and @Inject , the two annotations work the same way Spring decided to support some JSR-299 annotations in addition to their own.

Simple Logging for Java (SLF4J):

A simple logical facade for Java or (SLF4J) serves as a simple facade or abstraction for various logging structures, for example. java.util.logging, log4j and logback, allowing the end user to connect to the desired logging structure during deployment.

+1
source

Source: https://habr.com/ru/post/905163/


All Articles