Access JNDI lookup/simple bindings (Standalone.xml) on Backing Bean using Injection and Producer

Posted: August 7, 2013 in web

Standalone.xml

...
        <subsystem xmlns="urn:jboss:domain:naming:1.1">
            <bindings>
		...
                <simple name="java:/appUrl" value="http://localhost/app-4.0/"/>
		...
            </bindings>
        </subsystem>
...

ConfigBean.java

...
@Startup
@Singleton
@Lock(LockType.READ)
public class ConfigurationBean {
    @Resource(mappedName = "java:/appUrl")
    private String appUrl;

    @AUrl
    @Produces
    public String getAppUrl() {
        return appUrl;
    }



}

Qualifier (only need if you have multiple String producer, I just decided to add it)

@Qualifier
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
public @interface AUrl {

}

BackingBean

...
@AUrl
@Inject
String appUrlTest;
...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s