How to access deployment parameter from within EJB

前端 未结 1 746
野的像风
野的像风 2020-12-12 01:45

In a Java EE 6 Web application, I would like to access a deployment parameter (a string value) from within an EJB.

I know that I can define a Context Pa

相关标签:
1条回答
  • 2020-12-12 02:30

    After further research, I have found out the use of env-entry annotation in web.xml.:

    <env-entry>
        <env-entry-name>myEnvEntry</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>MyEnvEntryValue</env-entry-value>
    </env-entry>        
    

    The env-entry can be accessed in various ways from an EJB. The simplest is the use of @Resource annotation (requires CDI):

    @Resource(name="myEnvEntry")
    private String myEnvEntry;
    

    Links: Configure your EJB 3 with envirnoment entries using ENC

    0 讨论(0)
提交回复
热议问题