mardi 24 février 2015

Naming Spring Services when accessed by different client types

I am quite new to Spring and have a question related to Spring Service naming convention.


I have written a service, and used an annotation to define and name it.


@Service(value="CustomerService")


This service is implemented within a library that is used by a web app. Everything works fine and I can autowire my service into my client components.


Now I would also like to expose this service using http invoker. This works ok. I have define a /CustomerService http service which accesses CustomerService bean.


The issue I have is that one of my components, a client side component, that I used in my web app (CustomerDetailsValidator) can also be used in this new application.


In my CustomerDetailsValidator I have something like this:


@Autowired @Qualifier(name="CustomerService").


But if I want to reuse my CustomerDetailsValidator and use it in my new app, this time I need to wire it to the httpservice instead. Which means that the @Autowired and @Qualifier code is useless.


My question is what is the best practice in this case?


Should I still use @Service? I guess I cannot use Qualifier anymore.


My feeling is that I should define everything in xml in each application context.


The web app using the library directly would just use the CustomerService bean as a singleton. While my new client app would link the customer service id to the http service.


Is that a good approach? Do we have patterns for this?


Thanks and regards


Gilles


Aucun commentaire:

Enregistrer un commentaire