[ 
https://issues.apache.org/jira/browse/TOMEE-4715?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Richard Zowalla closed TOMEE-4715.
----------------------------------
      Assignee: Richard Zowalla
    Resolution: Fixed

> 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
>            Assignee: Richard Zowalla
>            Priority: Major
>             Fix For: 11.0.0, 10.3.0
>
>          Time Spent: 40m
>  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)

Reply via email to