如何将 Tomcat 的 context.xml 中的属性注入到 Seam 组件中? [英] How to inject a property from Tomcat's context.xml into a Seam component?

查看:51
本文介绍了如何将 Tomcat 的 context.xml 中的属性注入到 Seam 组件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Seam 文档会让你相信,如果你在 web.xml 中定义一个属性,或者通过 -D 参数,它会找到它并自动在你的 bean 上设置它.因此,如果您有一个名为 gateway 的 bean,它带有一个属性 login 和一个 setter,您可以在 seam.properties 中创建一个名为 gateway.login 的属性,但是如果您在 -D 中定义它,则必须使用 org.seam.properties.网关.登录.我让它工作(使用 -D),但我无法让它从 context.xml 中看到 &Parameter 或 &Environment 定义.

The Seam documentation would have you believe that if you define a property in web.xml, or through a -D argument, it will find it and automatically set it on your bean. So if you have a bean called gateway with a property login and a setter, you can make a property called gateway.login in seam.properties, but if you define it in a -D, you have to use org.seam.properties.gateway.login. I got that to work (with the -D that is), but I could not get it to see either &Parameter or &Environment definitions from in context.xml.

我这样做是因为我有一个商户网关的密钥,我在项目的文本文件中没有,而在 catalina.sh 中没有,因为它可能用于其他应用程序.context.xml 的好处在于它位于服务器上,并且可以限制在使用网关的一个应用程序中.

I am doing this because I have keys to a merchant gateway that I cannot have in a text file in the project, and would rather not have in catalina.sh, since that might be used for other apps. The nice thing about context.xml is that it's on the server and it can be confined to the one application that uses the gateway.

推荐答案

你应该使用 选项,而不是 (据我所知,Seam 不会在 JNDI 中搜索初始化参数).name 属性不应包含 org.jboss.seam.properties 前缀(它仅适用于 -D 条目),因此您应该使用:

You should use the <Parameter/> option, not <Environment/> (to the best of my knowledge Seam does not search initialization parameters in JNDI). The name property should not include the org.jboss.seam.properties prefix (it is only for -D entries), so you should use:

<Parameter name="gateway.login" value="yourvalue" override="false" />

override="false" 表示此处设置的值将优先于 web.xml<中的等效 <context-param/> 标签/code>,如果它们存在(如果您不使用 override 选项,web.xml 中定义的上下文参数优先于 context.xml 中的参数.xml).

override="false" means that the value set here will have priority over equivalent <context-param/> tags in web.xml, if they exist (if you don't use the override option, context parameters defined in web.xml have priority over the one in context.xml).

这篇关于如何将 Tomcat 的 context.xml 中的属性注入到 Seam 组件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆