/** * Application-scoped service returning "hello" sentence. * * @author Petr Bouda */ @ApplicationScoped public class HelloBean { public String hello(String name) { return "Hello " + name; } }
/** * Request-scoped counter. */ @RequestScoped public class RequestScopedCounter { private final AtomicInteger counter = new AtomicInteger(); public int getNumber() { return counter.incrementAndGet(); } }
/** * @author Arun Gupta * * This class represents a Session Scoped CDI bean. Once injected, the container will hold on to the instance of this bean until * the HTTP session expires. A new instance would be created with start of a fresh HTTP session */ @SessionScoped public class MySessionScopedBean implements Serializable { public String getID() { return this + ""; } }
public static Literal of(Class<? extends Annotation> value) { return new Literal(value); }
public static Literal of(Class<? extends Annotation> value) { return new Literal(value); }
public static Literal of(Class<? extends Annotation> value) { return new Literal(value); }
/** * Request counter. * * @author Petr Bouda */ @ApplicationScoped public class ApplicationCounterBean { private AtomicInteger counter = new AtomicInteger(); public int getNumber() { return counter.incrementAndGet(); } }
/** * @author Arun Gupta * * This class represents a Request Scoped CDI bean. The container will create a new instance of this bean for every single HTTP request. */ @RequestScoped public class MyRequestScopedBean { public String getID() { return this + ""; } }
/** * @author Radim Hanus */ @SessionScoped public class GreetingReceiver implements EventReceiver, Serializable { private String greet = "Willkommen"; void receive(@Observes(notifyObserver = Reception.IF_EXISTS) String greet) { this.greet = greet; } @Override public String getGreet() { return greet; } }
/** * Application-scoped counter. */ @ApplicationScoped public class ApplicationScopedCounter { private final AtomicInteger counter = new AtomicInteger(); public int getNumber() { return counter.incrementAndGet(); } }
/** * @author Arun Gupta */ @RequestScoped public class ScopedBean { public String sayHello(String name) { return "Hello " + name; } }
/** * @author Radim Hanus */ @SessionScoped public class GreetingReceiver implements EventReceiver, Serializable { private String greet = "Willkommen"; void receive(@Observes String greet) { this.greet = greet; } @Override public String getGreet() { return greet; } }
/** * Service returning the name. * * @author Petr Bouda */ @ApplicationScoped public class NameService { public static final String NAME = "James"; public String getName() { return NAME; } }
/** * @author Arun Gupta * @author Radim Hanus */ @RequestScoped public class SimpleGreeting implements Greeting { @Override public String greet(String name) { return "Hello " + name; } }
/** * @author Arun Gupta * * This class represents an Application Scoped CDI bean. Once injected, the container will hold on to the instance of this bean until * the application itself terminates (server restart/redeployment of the application). */ @ApplicationScoped public class MyApplicationScopedBean { public String getID() { return this + ""; } }
/** * @author Arun Gupta */ @RequestScoped public class SimpleGreeting implements Greeting { @Override public String greet(String name) { return "Hello " + name; } }
/** * Keeps current state of money. * * @author Petr Bouda */ @ApplicationScoped public class Account { private long current = 0; public void observeCredit(@Observes @Credit Long amount) { current += amount; } public void observeDebit(@Observes @Debit Long amount) { current -= amount; } public long getCurrent() { return current; } }
/** * @author Alexis Hassler */ @RequestScoped public class AnnotatedBean { public String sayHello(String name) { return "Hello " + name; } }
/** * @author Arun Gupta * @author Radim Hanus */ @RequestScoped public class FancyGreeting implements Greeting { @Override public String greet(String name) { return "Nice to meet you, hello" + name; } }
/** * Bean to be injected into another bean by CDI. * * The purpose is to test, that CDI and hk2 injections are working together so that one class be injected by * both CDI and Jersey/hk2. * * @author Adam Lindenthal (adam.lindenthal at oracle.com) */ @RequestScoped public class SecondBean { private String message = "Hello"; public String getMessage() { return message; } }