Results 1 to 4 of 4

Thread: @Inject doesn't work

  1. #1
    Join Date
    Dec 2010
    Posts
    7

    Default @Inject doesn't work

    Hello.
    In my application @Autowired works but @Inject doesn't.
    What could be the reasons for that?
    (@Inject is being recognised as a legal annotation. Dependencies were retrieved by maven).
    I use spring 3.0.0.RELEASE and javax.inject version 1 (in the pom.xml).

    Does it have anything to do with scope? Does JSR-330 have different scope than Spring?
    I would appreciate a simple and straight forward solution.
    Thanks in advance.
    Last edited by benma; Dec 20th, 2010 at 02:48 AM.

  2. #2

    Default

    Benma,

    I don't think the @Inject is a Spring type of annotation.

    I believe its a JEE type of annotation.

    If you want more info on Spring Annotation get this Refcard off Dzone.

    http://refcardz.dzone.com/refcardz/spring-annotations

    Please let me know if this helps.

  3. #3
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    I don't think the @Inject is a Spring type of annotation.
    No, it's not; it's JSR-330 annotation interfaces. But Spring 3 passed the TCK so it IS a recognized implementation of those interfaces.

    For the original poster: did you properly annotate the beans you want injected using @Inject with the @Named annotation? Because if you use @Component, they won't be picked up by scanning for @Inject purposes.
    You either use @Autowired and @Component, OR @Inject and @Named.

  4. #4
    Join Date
    Dec 2010
    Posts
    7

    Default Thanks

    No, I used @Component and @Inject. Thanks for clarifying this for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •