Reputation: 769
I'm learning about web services, and saw various examples. Some of them used @WebService
and/or @WebMethod
annotations while others don't. My question is; is it necessary to use these annotations, what is the drawback of not using?
Upvotes: 1
Views: 89
Reputation: 4702
Only usage of @WebService annotation is necessary. They are required for more flexibility when developing web services. Just look at javadocs of @WebService and @WebMethod. They have a lot of attributes which define how your service will be exposed because as a rule they are used to generate WSDL-file, so you are able to customize its different parts. Generally, I'd prefer to use annotation to have a higher flexibility with configuring how my service will look like for its clients. So these annotations are used to define and customize a contract between your service and its clients.
Upvotes: 0
Reputation: 2217
You should start by learning a bit about what annotations are. A useful starting point is the Oracle tutorial at http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html; an incomplete (but useful) summary is that annotations add metadata to the class file that can be examined at runtime.
Those annotations are for use by a an EJB container. The annotation tells the container that a method is to be exposed as a web service, and the container automagically exposes them as such, with a little additional configuration. The Spring container has its own set of annotations that accomplish the same thing.
There's no reason you can't skip the annotations and write web services from scratch as simple servlets, but it's usually cleaner, faster, and more useful to just focus on the business logic and let a container do the work of translating your code into a service for you.
Upvotes: 1