Question

I'm trying to replicate the loading of a property file of seam in javaee6 but still don't know where to start.

In seam we can load a property file as a seam component by defining it in the components.xml:

<component name="propertyBean" class="PropertyBean" scope="application" auto-create="true" startup="true">
    <property name="filename">myPropertyFile.properties</property>
    <property name="reload">true</property>
</component>

And then we can access it in code:

PropertyBean.getInstance().getProperty("myProperty");

Is there a javaee6 feature that will replicate this functionality? Or in spring it's called PropertyPlaceholder.

In c#, we can do it by adding configuration property in appsettings.xml. And access via ConfigurationManager.

Thanks,
czetsuya

Was it helpful?

Solution

Unfortunately, there's nothing like a property component manager from seam into javaee6, but I was able to find something similar, a property loader.

It works by having a qualifier:

@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface ConfiguredBy {
    @Nonbinding public String value();
}

With a parameter that serves as the name of the property file.

The whole approach is describe here: http://john-ament.blogspot.com/2010/03/writing-property-loader-in-java-ee-6.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top