Service-Factory with EJB

hamtho

Neues Mitglied
Hi,

I wonder how I would implement a Service-Factory using EJB using an property as criteria to determine which implementation should be used.

In old-fashioned this looked like this:

Code:
public static Service getService(final ServiceType serviceType) {

        Service service = null;

        switch (serviceType) {
            case A:
                service = new ServiceA();
                break;
            case B:
                service = new ServiceB();
                break;
            default:
                throw new RuntimeException("No Service defined for ServiceType: " + serviceType);

        }

        return service ;
    }

But using this implementation does not give me the chance to use the dependency-injection in my subclasses (such as ServiceA or ServiceB). So there has to be another way.
A saw, that there is this Producer-Annotation. Would this be the way to go?

Would anyone point me to the right direction?

Thanks
 

Ähnliche Java Themen

Neue Themen


Oben