Migration from @Stateless (BCE) to Quarkus

A typical BCE Jakarta EE application comprises a JAX-RS resource:

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
public class MessageResource {

    MessageFetcher messageFetcher;

    public String ping() {
        return "hello, " + this.messageFetcher.getMessage();

and a corresponding implementation in the boundary package:

package com.airhacks.ping.boundary;
import com.airhacks.ping.control.MessageConfigurator;
import javax.ejb.Stateless;
import javax.inject.Inject;

public class MessageFetcher {

    MessageConfigurator configurator;

    public String getMessage() {
        return this.configurator.message();


The boundary acts as a facade and usually coordinates multiple controls:

package com.airhacks.ping.control;

import javax.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;

public class MessageConfigurator {

    @ConfigProperty(name = "message")
    String message;

    public String message() {
        return this.message + " generated at: " + System.currentTimeMillis();

To run the code on quarkus you will have to replace @Stateless with @Transactional and @RequestScoped, or a stereotype which combines both:

public @interface Boundary {}    

Now the MessageFetcher looks like:

public class MessageFetcher {    }    

All controls have to annotated to be injectable on quarkus. A @Dependent (default) scope could be used for that purpose, or the following stereotype:

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Stereotype;

public @interface Control {}

The MessageConfigurator control has to be annotated with the @Control stereotype and looks like:

public class MessageConfigurator { }

Both stereotype are used in the Web Push gateway: gatelink.


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments