简体   繁体   English

如何在 Glassfish 4.1 中设置 java:comp/env/foo JNDI 变量?

[英]How to set a java:comp/env/foo JNDI variable in Glassfish 4.1?

I'd like to use a ServletFilter that reads it configuration from the java:comp/env/ JNDI namespace.我想使用一个 ServletFilter 从 java:comp/env/ JNDI 命名空间读取它的配置。 As the value will be different on devel and production servers, it should not be hardcoded via in web.xml but instead be configured in the application server.由于该值在开发服务器和生产服务器上会有所不同,因此不应通过 web.xml 对其进行硬编码,而应在应用程序服务器中进行配置。

I already tried the following places but none seemed to be right:我已经尝试过以下地方,但似乎没有一个是正确的:

How can I set a custom JNDI variable in Glassfish 4.1?如何在 Glassfish 4.1 中设置自定义 JNDI 变量?

I installed only the Glassfish 4.1 Web Edition.我只安装了 Glassfish 4.1 网络版。 While it has JNDI support, the web GUI comlpetely lacked the Resources -> JNDI menu to configure own variables!虽然它有 JNDI 支持,但 Web GUI 完全缺乏资源 -> JNDI 菜单来配置自己的变量!

In the Web Profile Glassfish, custom JNDI variables can be written in the domain.xml, they seem to survive other changes via the Admin GUI:在 Web Profile Glassfish 中,可以在 domain.xml 中编写自定义 JNDI 变量,它们似乎可以通过管理 GUI 进行其他更改:

<resources>
  ...
  <custom-resource res-type="java.lang.String" jndi-name="cas/serverName" factory-class="org.glassfish.resources.custom.factory.PrimitivesAndStringFactory">
    <property name="value" value="https://sso.example.com/"></property>
  </custom-resource>
</resources>
...
<servers>
  <server name="server" config-ref="server-config">
    ...
    <resource-ref ref="cas/serverName"></resource-ref>
  </server>
</servers>

After adding a JNDI variable to Glassfish, it's only availble with InitialContext.doLookup("cas/serverName") though, not within the java:comp/env namespace.在向 Glassfish 添加 JNDI 变量后,它只能在 InitialContext.doLookup("cas/serverName") 中使用,而不是在 java:comp/env 命名空间中。 To get that, I had to add the following to my web.xml (it did not work in glassfish-web.xml!):为此,我必须将以下内容添加到我的 web.xml(它在 glassfish-web.xml 中不起作用!):

 <resource-ref>
   <res-ref-name>cas/serverName</res-ref-name> 
   <res-type>java.lang.String</res-type>
   <lookup-name>cas/serverName</lookup-name> 
 </resource-ref>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM