Skip to content

TOMEE-4715 - Inject @Resource fields of the @Application descriptor and test instances in TomEEEmbeddedApplicationRunner (10.x) - #2959

Merged
rzo1 merged 1 commit into
tomee-10.xfrom
TOMEE-4715-10.x
Sep 28, 2026
Merged

rzo1 merged 1 commit into
tomee-10.xfrom
TOMEE-4715-10.x

Conversation

@rzo1

@rzo1 rzo1 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/TOMEE-4715

Problem

@Resource fields of the @Application descriptor and of the test instances are not injected if the application is started via TomEEEmbeddedApplicationRunner (@RunWithTomEEEmbedded, TomEEEmbeddedSingleRunner). They are not components of the deployed application, so there are no resource references for them. With the ApplicationComposer the same descriptor gets its DataSource.

This gets relevant with TOMEE-4707, as tests using @EnableServices("jaxrs") need to move to TomEE embedded.

Change

composerInject links container resources (openejb/Resource/<id>) for @Resource fields which are still null after the CDI injection:

  • lookup: JNDI lookup, then the container resource with that id.
  • name: the container resource with that name.
  • neither: the resource matching the name of the field, then the first resource matching the type (like the auto linking of AutoConfig).

An explicit lookup or name which can't be resolved is logged as warning and the field stays null, no other resource is injected instead.

Limitations

  • Fields only, no setter injection.
  • Container resources only. Other @Resource types (e.g. UserTransaction) are still not injected.

Tests

Two new surefire executions in tomee-embedded: single-server-resource-injection (name, lookup, unresolvable ones) and single-server-resource-by-type-injection. Both inject into the descriptor and the test instance and open a connection.

…nd test instances in TomEEEmbeddedApplicationRunner

The descriptor and the test instances are not components of the deployed application, so there are no resource references for them and the fields stayed null.

Container resources are now linked like AutoConfig does it: by the explicit lookup or name, otherwise by the name of the field and then by the type. An explicit lookup or name which can't be resolved is logged and the field is left untouched, no other resource is injected instead.
@rzo1
rzo1 merged commit a48bbf7 into tomee-10.x Sep 28, 2026
1 check passed
@rzo1
rzo1 deleted the TOMEE-4715-10.x branch September 28, 2026 18:40
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