开发者

Is it possible to place custom values (properties) in ejb-jar.xml?

1) We are using OpenEJB (both embedded and standalone) with a few deployed EJBs. We would like to specify some simple static business rules and values (example: icon_size=200). Normally, we would put them in a regular properties file (example: rules.properties). Since we shouldn't access the file s开发者_JAVA技巧ystem directly while inside the application server, is is possible to place those key-value pairs somewhere inside the ejb-jar.xml?

2) If not, is there a standard mechanism to do this? What is it?

Thanks


Use env-entry. In XML:

<env-entry>
  <env-entry-name>icon_size</env-entry-name>
  <env-entry-type>java.lang.Integer</env-entry-type>
  <env-entry-value>200</env-entry-value>
</env-entry>

In annotation:

@Resource(name="icon_size")
int icon_size;


I personally just use a .properties file; well a TernarySearchTree which reads in .properties and .XML files and allows quick retrieval. These files are available at application level. However you can in EJB 3 inject env-entry elements into your EJB. This link explains it in good detail Injection of env entry


There are some OpenEJB extensions here that might be useful.

env-entries.properties

Check out the Custom Injection example which is basically allows the <env-entry> to be specified as plain properties in a META-INF/env-entries.properties file. Nice for collapsing all those name & value pairs into a simple properties file. Internally, we just generate the xml for you using those properties. The default type is always java.lang.String, which is good for this next part.

java.beans.PropertyEditor support

Any <env-entry> which is of <env-entry-type> java.lang.String will automatically have its type converted using the VM java.beans.PropertyEditor for the target type. That's also how Spring does the converting. There are few built-in converters, such as @Resource java.util.Date myDate and @Resource java.io.File myFile

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜