concept @resource in category java

appears as: @Resource
Portlets in Action

This is an excerpt from Manning's book Portlets in Action.

Portlet 2.0 supports the JSP 2.0 specification, so if you’re using JSP tags that use new features of JSP 2.1 (like the @Resource annotation to inject a database connection in your tag implementation class), the tags may not work.

In the first half of this chapter, we’ll look at Spring Portlet MVC annotations and discuss dependency injection using Spring’s @Autowired annotation, JSR 330’s @Inject annotation, and JSR 250’s @Resource annotation. As we go through the implementation of the Book Catalog portlet, you’ll see how Spring Portlet MVC annotations reduce the direct dependency of portlet request handlers on the portlet API.

8.3.4. Dependency injection using @Resource and @Inject

You can also autowire dependencies by name by simply using the @Resource annotation from JSR 250 (Common Annotations). The @Resource annotation can only be applied to a class, field, and setter method (as compared with the @Autowired annotation, which can also be used with a constructor).

The following code shows the @Resource annotation in use: