heart_coder
heart_coder

Reputation: 189

Do we need web.xml for REST services?

I'm little confused about the usage of web.xml when writing REST services in Spring say using Jersey framework. In my opinion, if I'm using annotations to define the path, why do we need web.xml? I just recently developed Spring Boot application using the reference documentation online, and they don't even mention web.xml. So, is it right to say that Spring has removed web.xml and replaced it with annotations?(e.g @Path, @Get, @Post). My second question on the same line is, if I don't have web.xml and is it a good practice to deploy REST service as jar?

Upvotes: 3

Views: 2208

Answers (2)

Matt
Matt

Reputation: 3662

Whether you need a web.xml or not doesn't depend on Spring, but on the version of the Java EE Servlet Spec you're using.

Since Servlet v3.0, web.xml is no longer required, and Spring Boot is by default compatible with Servlet 3+.

There are some tricks to make it run with Servlet 2.5, though.

Upvotes: 4

UserF40
UserF40

Reputation: 3611

Spring Boot helps simplify the workflow.

With Spring Boot you create a jar, not a war file as your artifact.

Usually the war file would be deployed to a webcontainer you need to run separately like (like Tomcat).

Spring Boot actually places an embedded Tomcat inside your jar so to run it so you don't need to start up your own Tomcat/web container elsewhere.

You run your Spring Boot web service like:

java -jar my-spring-boot-application-1.0.0.jar

Where my-spring-boot-application-1.0.0.jar is the name of the jar you make.

Upvotes: 2

Related Questions