1

I tried using @Named annotation on methods that create a bean, but that doesn't seem to work. Couldn't find any question here or a blog that confirms this. Reading the description at jcp.org, I don't see any relationship b/w beans and dependency injection introduced by JSR-330 either: https://jcp.org/en/jsr/detail?id=330

goelakash
  • 2,502
  • 4
  • 40
  • 56

1 Answers1

6

No, JSR-330 does not have the equivalent of Spring's @Bean or Guice's @Provides annotations.

There are only 5 annotations in JSR-330, and they are equivalent to the following Spring1 / Guice2 annotations:

JSR-330      Spring                Guice
----------   -------------------   ------------------
@Inject      @Autowired            @Inject
@Named       @Component            @Named
@Qualifier   @Qualifier            @BindingAnnotation
@Scope       @Scope                @ScopeAnnotation
@Singleton   @Scope("singleton")   @Singleton
-            @Scope("prototype")   -

1) From Using JSR 330 Standard Annotations and Using JSR 330 Standard Annotations
2) From JSR-330 Integration

They do not match up exactly, so read the articles listed in the footnotes for full detail.

hisener
  • 1,431
  • 1
  • 17
  • 23
Andreas
  • 154,647
  • 11
  • 152
  • 247
  • While it unfortunately does not cover Guice, more information about the similarities and differences between CDI and Spring (and how to jump between them) can be found at; https://stackoverflow.com/questions/67132894/what-is-springboot-alternative-to-javaee-cdi/67154490#67154490. – Adam Waldenberg Aug 04 '22 at 10:26