Service-Factory with EJB

Dieses Thema Service-Factory with EJB im Forum "Application Tier" wurde erstellt von hamtho, 20. Aug. 2014.

Thema: Service-Factory with EJB Hi, I wonder how I would implement a Service-Factory using EJB using an property as criteria to determine which...

  1. 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 (Text):

    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
     
  2. Vielleicht hilft dir das Java-Tutorial weiter. Hier klicken --> (Klick)