How to inject a property from Tomcat's context.xml into a Seam component?

萝らか妹 提交于 2019-12-12 20:53:23

问题


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.

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.


回答1:


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" 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).



来源:https://stackoverflow.com/questions/6104540/how-to-inject-a-property-from-tomcats-context-xml-into-a-seam-component

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