OpenEJB ApplicationComposer and semi auto configuration


OpenEJB ApplicationComposer design is to let you build in memory JavaEE model of your application and then use it to really deploy the described application.

It is great when writing a microservice which aggregates several libraries (avoids to activate everything when you need just a subpart) but when you just write a single module it can seem a lot of work.

Since few days you can use @Default (openejb one) to ask to auto scan the module containing the main(String[]) for managed beans (CDI, EJB…) and descriptors (persistence.xml, …).

Here is a basic sample to write a simple jaxrs service:

@Default
@Classes(cdi = true)
@EnableServices("jaxrs")
public class MyApp {
    public static void main(String[] args) {
        ApplicationComposer.run(MyApp.class, args);
    }
}

Then if you have EJB, JAX-RS services, CDI beans then it will be activated automatically!

No need to define any @Module or list all CDI beans in @Classes(value).

For microservices or tests (since it works for tests as well) it allows quick activation of the “current” module without needing to be too explicit (ie listing all beans). With @Jars it allows to quickly setup its “EE-classpath” without much effort but keeping a full control on it.

This can be an interesting solution to run daemons or small internal webservices without needing a complicated packaging or loosing time and/or memory during boot.

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