Creating JSON REFS service by using Spring MVC

Creating JSON REFS service by using Spring MVC

In this post, I am going to explain how to create a JSON Webservice by using Spring MVC.

1. Eclipse/ Spring Tool Suite
2. Apache Tomcat 8

You have to create a maven project in Eclipse and define artifact id and group id.

Then, add all the dependencies in pom.xml, Here you can see the mandatory dependencies has to be included. 

I have been used jackson-core and jackson-databind dependencies. (It's available inside Maven artifact)


Then you have to add annotation-driven and component-scan in web.xml
Then you can define a method inside the controller class. Here @ResponseBody is used to generate the JSON response in the browser. The below method is responsible for creating a JSON web service.


Then Run your application in a web server (Tomcat) or Hit the below URL in the browser.

http://localhost:<port>/carservice

/carservice - It should be matched with controller method.

@RequestMapping(value="/carservice"). But in this example I am trying to redirect to root (/) directory to /carservice controller method, so once you ran your application you will be able to see the JSON output.

Other MVC features are like a CRUD operation which is also added in the controller class, based on the mapping URL you can hit appropriate mapping value (Eg: /car, /carservcie) in the browser and verify all operations.

GitHub: https://github.com/RanjithSubraman/SpringMVC-Webservice-Example






Comments

Popular posts from this blog

Programmatically turn ON/OFF NFC in Android

Sign-on by using Google OAuth2

Setup to execute Apache Spark in Cloudera