Initialization parameters for EJB

ぃ、小莉子 提交于 2019-12-13 07:32:43

问题


I have Singleton enterprise bean, which starts immediately after deploy. I packed EJB into jar and want to distribute it. I set several fields of Singleton like private final String initParam = "value";. How can I expose those init parameters to administrator who will be deploy my jar onto his own GlassFish server?


回答1:


You can use Environment Entries, these should fit your needs.

Such parameters must be described in ejb-jar.xml:

<enterprise-beans>
    <session>
        <ejb-name>YourBean</ejb-name>
        <env-entry>
            <description>Your description</description>
            <env-entry-name>yourParam</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>defaultValue</env-entry-value>
        </env-entry>
    </session>
</enterprise-beans>

The value of the env-entry could be injected into your bean like below:

@Resource(name = "yourParam")
private String initParam;

Env-entries could be modifed from the console of your container, normally it is a more convenient way for admins, comparing to property file modification or creating JVM parameters.

Here is some doc from Oracle: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/env_entry/env_entry.html



来源:https://stackoverflow.com/questions/47048941/initialization-parameters-for-ejb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!