Skip to content

[10.x] Document @Resource injection pitfall for resources declared in an EAR - #3185

Merged
rzo1 merged 1 commit into
tomee-10.xfrom
docs/ear-resource-injection-10.x
Nov 21, 2026
Merged

rzo1 merged 1 commit into
tomee-10.xfrom
docs/ear-resource-injection-10.x

Conversation

@rzo1

@rzo1 rzo1 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #3184 to tomee-10.x.

Inside an EAR, the resources of the EAR's META-INF/resources.xml are registered under ids prefixed with the application name (myapp/myresource). A plain @Resource that relies on the field name does not match that id, so AutoConfig.getResourceId falls back to the first resource of the requested type (firstMatching) and only logs it at DEBUG. With several resources of the same type, every field silently gets the same instance and deployment still succeeds.

This adds a section to application-resources.adoc describing the behavior and the two ways to name the resource explicitly:

  • @Resource(lookup = "openejb:Resource/<id>")
  • @Resource(name = "<app>/<id>")

It also mentions where the EAR-level resources.xml goes, and adds a short pointer in admin/configuration/application.adoc.

Verified on TomEE 10.3.0 (microprofile) with a small EAR, both deployed at startup from apps/ and at runtime via Arquillian: plain @Resource gets the first resource of the type, while both explicit forms get the right one. Lazy makes no difference.

@mawiesne FYI, this is the cause of the filter resource issue in the EAR.

Inside an EAR, the resources of the EAR's META-INF/resources.xml are
registered under ids prefixed with the application name. A plain
@resource relying on the field name does not match the prefixed id, so
TomEE falls back to the first resource of the requested type, logging
it at DEBUG only. With several resources of the same type every field
silently receives the same instance.

Documents the behavior and the two ways to name the resource explicitly
(lookup = "openejb:Resource/<id>" or name = "<app>/<id>"), and mentions
where the EAR-level resources.xml goes.

(cherry picked from commit d78d706)
@rzo1
rzo1 requested a review from jungm November 21, 2026 08:53

@mawiesne mawiesne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the improvements of the docs. +1

@rzo1
rzo1 merged commit 4f9bff5 into tomee-10.x Nov 21, 2026
1 check passed
@rzo1
rzo1 deleted the docs/ear-resource-injection-10.x branch November 21, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants