Can't locate import javax.inject.Inject package

前端 未结 5 1686
北海茫月
北海茫月 2020-12-15 04:11

I\'m trying to implement Dagger as a dependency injector in an IntelliJ project, but my code is failing on:

import javax.inject.Inject;

Int

相关标签:
5条回答
  • 2020-12-15 04:42

    add this to your pom.xml

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-15 04:44

    // dependency injection implementation "com.google.dagger:dagger:$rootProject.dagger2Version"

    // dependency injection
        implementation "com.google.dagger:dagger:$rootProject.dagger2Version"
        implementation {
            exclude(group: 'javax.inject', module: 'javax.inject')
        }

    0 讨论(0)
  • 2020-12-15 04:46

    Add the inject library directly from Maven like this:

    • File -> Project Structure -> Project Settings -> Libraries -> Add -> From Maven
    • Search for javax.inject:javax.inject:1
    • After it's been found click OK

    0 讨论(0)
  • 2020-12-15 04:53

    Dagger depends on JSR 330, the Java standard annotations which are used for dependency injection (think: @Inject, @Singleton, etc.).

    This is a separate jar that you have to include. If you were using a build system with integrated dependency management (Maven, Gradle, Ant+Ivy, sbt) you'd get this for free. If you're still copying around jars then you have to add it manually.

    You can download the latest jar from Maven central (at the bottom).

    0 讨论(0)
  • 2020-12-15 04:59

    In case if anyone using plain Java project not Maven or Gradle or e.t.c. You can download a separate Jar file from here Inject Jar file

    and then add to your external libraries, in IDEA you can do that as follows: File -> Project Structure -> Libraries -> New Project Library (+)

    Then find the path to library and job is done.

    0 讨论(0)
提交回复
热议问题