[
https://issues.apache.org/jira/browse/TOMEE-4715?focusedWorklogId=1044325&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1044325
]
ASF GitHub Bot logged work on TOMEE-4715:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 28/Sep/26 08:15
Start Date: 28/Sep/26 08:15
Worklog Time Spent: 10m
Work Description: rzo1 opened a new pull request, #2959:
URL: https://github.com/apache/tomee/pull/2959
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.
Issue Time Tracking
-------------------
Worklog Id: (was: 1044325)
Time Spent: 20m (was: 10m)
> TomEE embedded application runner does not inject @Resource into the
> @Application descriptor
> --------------------------------------------------------------------------------------------
>
> Key: TOMEE-4715
> URL: https://issues.apache.org/jira/browse/TOMEE-4715
> Project: TomEE
> Issue Type: Bug
> Reporter: Richard Zowalla
> Priority: Major
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Fields annotated with {{@Resource}} in the {{@Application}} descriptor class
> are not injected if the application is started via
> {{TomEEEmbeddedApplicationRunner}} \({{@RunWithTomEEEmbedded}},
> {{TomEEEmbeddedSingleRunner}}\).
> {code:java}
> @Application
> @Classes\(cdi = true, context = "app"\)
> public class TheApp {{code}
> @Resource
> private DataSource dataSource; // stays null
> @Configuration
> public Properties config() {
> final Properties p = new Properties();
> p.put("db", "new://Resource?type=DataSource");
> p.put("db.JdbcDriver", "org.hsqldb.jdbcDriver");
> p.put("db.JdbcUrl", "jdbc:hsqldb:mem:test");
> return p;
> }
> {code}
> }
> {code}
> h3. Cause
> {{TomEEEmbeddedApplicationRunner#composerInject\(...\)}} only uses
> {{OWBInjector}} and handles the runner specific annotations
> \({{@RandomPort}}, {{@Application}}, {{@LifecycleTask}}, {{@Args}}\). Jakarta
> EE resource injection is not processed for the descriptor or test instance.
> h3. Expected behaviour
> The same descriptor works with {{ApplicationComposer}}
> \({{@RunWithApplicationComposer}}\), where {{@Resource}} is injected. As
> TOMEE\-4707 removes the embedded HTTP server, tests using
> {{@EnableServices\("jaxrs"\)}} need to move to TomEE embedded, so both
> runners should behave the same here.
> h3. Workaround
> Look up the resource via the container JNDI context:
> {code:java}
> SystemInstance.get\(\).getComponent\(ContainerSystem.class\).getJNDIContext\(\).lookup\("openejb/Resource/db"\);
> {code}
> Seen with 11.0.0\-SNAPSHOT.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)