0

I found @Resource can also be applied at class level:

http://docs.oracle.com/javaee/5/tutorial/doc/bncjk.html

Class-Based Injection To use class-based injection, decorate the class with a @Resource annotation, and set the required name and type elements.

@Resource(name="myMessageQueue", type="javax.jms.ConnectionFactory") public class SomeMessageBean { ... }

Do you have any experience using @Resource this way?

jarosik
  • 4,136
  • 10
  • 36
  • 53
  • do you have a more specific question? – Phil Oct 14 '16 at 13:51
  • What does Resource do when applied at type level? I know you can autowire by name when you place Resource on a field or method level, but how about type? Can you combine it with other annotations (also Resource or other). There is a lot of information about @Resource, but I cant find any example of using it on a class level. I tried to examine this piece of code but I doesn't even compile. – jarosik Oct 14 '16 at 13:57

1 Answers1

0

From Resource javadoc

The Resource annotation marks a resource that is needed by the application. This annotation may be applied to an application component class, or to fields or methods of the component class. When the annotation is applied to a field or method, the container will inject an instance of the requested resource into the application component when the component is initialized. If the annotation is applied to the component class, the annotation declares a resource that the application will look up at runtime

This means that the class annotated with @Resource at class level will be considered as candidates for auto-detection when using annotation-based configuration and classpath scanning

Issam El-atif
  • 2,366
  • 2
  • 17
  • 22