2

I've been studying Spring MVC 4 and I understand that Spring have several annotations to develop faster. This question and answer explains very well the relation between @Component, @Service, @Repository and @Controller. My questions are:

  1. Can a @service class be called from another machine as a common wsdl service? For example, from a standalone app that is the client of the service.

  2. Or is @service annotation just to mark the use of a class?

Thanks

Community
  • 1
  • 1
Jessai
  • 947
  • 2
  • 15
  • 35

4 Answers4

3

The methods in class annotated with @Service cannot be called from outside, but it is common practice to add another layer generally called facade on top of the layer where you have your classes annotated with @Service(generally called as service layer). Using this facade you can expose your services in different ways like REST, SOAP etc.

varun
  • 684
  • 1
  • 11
  • 30
2

Annotation @Service is only a special version of @Component annotation and its purpose is not providing a remote access to implementation.

As mentioned in documentation, @Service annotation helps the class to be auto detected during the classpath scanning (see the JavaDoc) and processed by some tools. Also check the explanation on Spring's forum.

Jurica Krizanic
  • 1,072
  • 2
  • 11
  • 26
  • Can I put both annotations @service and @webservice? – Jessai Aug 28 '14 at 22:03
  • I'm not sure, but I would advice you to annotate service implementation with @Service annotation, and inject it into the endpoint implementation (check http://docs.spring.io/spring/docs/current/spring-framework-reference/html/remoting.html). In this way, you can expose your service implementation with different remoting technologies. – Jurica Krizanic Aug 29 '14 at 06:02
1

I don't think it can be called by using @service you need to annotate the class with @Webservice to expose it to the outside world

m b
  • 310
  • 1
  • 8
1

Don't confuse javax @WebService with Spring @Service which is defined here. Although both are called service. @Service's purpose is simply:

This annotation serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning.

So, since @WebService is for WSDLs (external access), a @Serviceis for Spring's internal use. If you want to access "Services" from other machines, you have to write a @WebService or use @RequestMapping with SpringMVC.

Thomas Junk
  • 5,588
  • 2
  • 30
  • 43