简体   繁体   English

我的pom.xml中有javax.inject,会自动弹出吗?

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

I copied a pom.xml while I was going through a spring mvc tutorial online, and it had: 我在网上浏览一个春季mvc教程时复制了一个pom.xml,它有:

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

From what I understand spring has its own dependancy injection built-in, will this override the default and use javax.inject? 根据我的理解,spring有自己的内置依赖注入,这会覆盖默认值并使用javax.inject吗?

I have also seen slf4j in pom's, with no further setup in code or xml. 我也在pom中看过slf4j,没有在代码或xml中进一步设置。

How does this work under the covers, spring examines the lib's folder and if any lib is found that is overridable it does it? 这是如何工作的,spring检查lib的文件夹,如果找到任何可覆盖的lib,它会这样做吗?

The dependency in your pom for javax.inject 你的pom对javax.inject的依赖

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

has nothing to do with Spring . 与Spring无关。 It just brings in a javax.inject dependency into the project . 它只是将javax.inject依赖项引入项目中。 A jar with the name javax.inject-1.jar . 一个名为javax.inject-1.jar的jar This jar is needed if you use the @Inject annotation which is supported by Spring as well . 如果您使用Spring支持的@Inject注释,则需要此jar。

You could use @Autowired/@Resource/@Inject as per your needs . 您可以根据需要使用@Autowired / @ Resource / @Inject。 See here for their difference and also a discussion at What is the difference between @Inject and @Autowired in Spring Framework? 请看这里的差异,并讨论Spring Framework中@Inject和@Autowired之间的区别是什么? Which one to use under what condition? 在什么条件下使用哪一个? .

As for slf4j , it is just an abstraction over frameworks like log4j allowing run time plugging in of logging framework . 至于slf4j,它只是对log4j这样的框架的抽象,允许运行时插入日志框架。 Spring-OSGI , Hibernate all use this internally. Spring-OSGI,Hibernate都在内部使用它。 So this is why you find the dependency in your pom . 所以这就是你在pom中找到依赖的原因。 Hope this clears things out. 希望这可以解决问题。

inject enables JSR 330 support to spring. inject使JSR 330支持spring。 Using the inject annotations makes the application not tied to spring - it could be switched to Java EE 6 or guice or other providers which support the specification. 使用注入注释使应用程序不依赖于spring - 它可以切换到Java EE 6或guice或支持该规范的其他提供程序。

You could either use inject or spring injection (or perhaps both). 你可以使用注射或弹簧注射(或两者兼而有之)。

as @Aravind told javax.inject dependency has nothing to do with spring. 正如@Aravind告诉javax.inject依赖与spring无关。 and it's used to get annotation @Inject , it's is part of the Java CDI standard, introduced in Java EE 6 (JSR-299) 它用于获取注释@Inject ,它是Java CDI标准的一部分,在Java EE 6 (JSR-299)中引入

Spring using @Inject synonymously with their own @Autowired annotation. Spring使用@Inject与他们自己的@Autowired注释同义。
@Autowired and @Inject , two annotations works the same way as Spring has decided to support some JSR-299 annotations in addition to their own. @Autowired@Inject ,两个注释的工作方式与Spring决定支持除了自己的一些JSR-299注释相同。

comming to Simple Logging Facade for Java (SLF4J): 采用Simple Logging Facade for Java(SLF4J):

The Simple Logging Facade for Java or (SLF4J) serves as a simple facade or abstraction for various logging frameworks, eg java.util.logging, log4j and logback, allowing the end user to plug in the desired logging framework at deployment time. Java或(SLF4J)的简单日志外观用作各种日志框架的简单外观或抽象,例如java.util.logging,log4j和logback,允许最终用户在部署时插入所需的日志框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM