[
https://issues.apache.org/jira/browse/OPENEJB-2113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14396219#comment-14396219
]
Romain Manni-Bucau commented on OPENEJB-2113:
---------------------------------------------
Context.xml is a tomee only descriptor not an openejb one and java:comp/env is
a web prefix only so not openejb embedded one excepted usin
env-entries.properties or ejb-jar.xml.
> Embeddable EjbContainer - unable to set up environment variables
> ----------------------------------------------------------------
>
> Key: OPENEJB-2113
> URL: https://issues.apache.org/jira/browse/OPENEJB-2113
> Project: OpenEJB
> Issue Type: Bug
> Components: configuration
> Affects Versions: 4.7.1
> Environment: Tomee 1.7.1, Java 1.7.0_72 64bit, Windows 7
> Reporter: Apache Fan
>
> My singleton EJB pulls environment value resources from web.xml and Tomee's
> context.xml. It works fine when executed in Tomee, but it is not possible to
> initialize the bean by using Embeddable EJBContext, the references to the
> resource remain null.
> EJB:
> {noformat}
> @Resource(name = "serviceendpoint.url")
> private String serviceEndpointUrl;
> @Resource(lookup = "java:comp/env/serviceendpoint.url")
> private String serviceEndpointUrl2;
> {noformat}
> web.xml
> {noformat}
> <env-entry>
> <env-entry-name>serviceendpoint.url</env-entry-name>
> <env-entry-type>java.lang.String</env-entry-type>
> <env-entry-value>https://blabla.com/rest/</env-entry-value>
> </env-entry>
> {noformat}
> Tomee context.xml:
> {noformat}
> <Environment name="serviceendpoint.url" type="java.lang.String"
> value="https://blabla-bla-bla.com/api/" />
> {noformat}
> Use of EJBContext:
> {noformat}
> final Properties p = new Properties();
> p.put("serviceendpoint.url", "https://blahhhhhh.com/rest/");
> final Context context = EJBContainer.createEJBContainer(p).getContext();
> context.bind("java:comp/env/serviceendpoint.url",
> "https://blahhhhhh.com/rest/");
> MyBean bean = (MyBean) context.lookup("java:global/myApp/myBean");
> {noformat}
> As a result the serviceEndpointUrl and serviceEndpointUrl2 members remain
> null during the use of EJBContainer. In Tomee container they do fine.
> What could cause this problem?
> Workaround:
> {noformat}
> @PostConstruct
> public void getConnection() {
> if (serviceEndpointUrl == null) {
> // support for embedded EJB container for testing:
> serviceEndpointUrl = System.getProperty("serviceendpoint.url");
> if (serviceEndpointUrl == null) {
> throw new IllegalStateException("unable to determine the
> value of environment var: serviceendpoint.url");
> }
> }
> ....
> }
> {noformat}
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)