Bistro!
Alexis Moussine-Pouchkine's Weblog
public enum Topic { Java, GlassFish, Tools, Sun, InFrenchInZeText, SDPY }

20091109 lundi novembre 09, 2009

La présentation du séminaire GlassFish

( nov. 09 2009, 03:02:00 PM CET ) Permalink Comments [0]

javax.annotation.ManagedBean

You might have hear or "managed beans" before, but chances are these will be new to you. These are not specific to JSF and not related to JMX in any way. Rather, Java EE 6 (well EJB 3.1 to be precise) specifies Managed Beans 1.0, or lightweight components.

Managed beans are plain old java objects whose life-cycle is governed by the container (allowing for creation and destruction callbacks) and supports resource injection (and of course can themselves be injected). To define a managed bean, you simply need to annotate a class with @java.annotation.ManagedBean. You can apply the existing (JSR 250) @PostConstruct and @PreDestroy annotations to methods in that bean and inject resources using @Resources (as well as with @EJB or @WebServiceRef). Here's a simple example :

@javax.annotation.ManagedBean
public class MessagesBean {
    @Resource
    TranslationBean localizer;

    @PostConstruct
    public void myInit() {
        System.out.println("*** Constructed!");
        // Do something useful
    }

    public String getTranslatedMessage(String message) {
        return localizer.translate(message);
    }
}

Such a class can then be deployed within a WAR, an EJB-JAR or an ACC-JAR and can be injected within another Managed Bean, a servlet, an EJB or a JSF Managed Bean using a simple @Resource MessagesBean bean; statement. Life-cycle and injection in itself is nice but it gets even better with interceptors which can also be applied to managed beans (no longer to just EJB's) :

@Interceptors(LogInterceptor.class)
@javax.annotation.ManagedBean
public class MessagesBean {
     ...
}

Whether Managed Beans will be used directly by application developers or mostly for building higher level abstractions such as EJB's (transactional managed beans in a sense), JAX-WS endpoints (SOAP-enabled managed beans) or JSR 299 is yet to be defined. You decide.

You can of course try all of the above in GlassFish v3.

( nov. 09 2009, 09:19:56 AM CET ) Permalink Comments [0]


GlassFish Podcast
Get GlassFish V3
Support GlassFish Enterprise

Today's Page Hits: 177




bea conference glassfish groovy ips java javaee javafx javaone javazone jug mysql netbeans openesb openoffice opensource paris performance podcast presentation sdpy spring sun swing techdays tips updatecenter v3 webservices wsit
Links