Repository navigation
Document @Resource injection pitfall for resources declared in an EAR - #3184
Merged
Merged
Conversation
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.
mawiesne
approved these changes
Nov 21, 2026
mawiesne
left a comment
Contributor
There was a problem hiding this comment.
Thx for the improvements of the docs. +1
mawiesne
approved these changes
Nov 21, 2026
mawiesne
left a comment
Contributor
There was a problem hiding this comment.
Thx for the improvements of the docs. +1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inside an EAR, the resources of the EAR's
META-INF/resources.xmlare registered under ids prefixed with the application name (myapp/myresource). A plain@Resourcethat relies on the field name does not match that id, soAutoConfig.getResourceIdfalls 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.adocdescribing 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.xmlgoes, and adds a short pointer inadmin/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@Resourcegets the first resource of the type, while both explicit forms get the right one.Lazymakes no difference.@mawiesne FYI, this is the cause of the filter resource issue in the EAR.