简体   繁体   中英

Call a spring @service from another project

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

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.

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 .

我不认为可以通过使用@service来调用它,而您需要使用@Webservice对该类进行注释以将其暴露给外界

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 @Service is 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM