Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can One webapp contain Spring MVC and Spring RESTFul services

 
Anant Jagania
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I came to know that Spring RESTFul services can be developed using Spring MVC.

I have a situation where I have Spring webapp and Spring RESTFul service. They both use other modules in common.

Is it possible that I can have Spring webapp contain RESTFul service along with Spring MVC web app?

Do I need to have two DispatcherServlet with different URL pattern?

Thanks
Anant
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anant Jagania wrote:Hi,

I came to know that Spring RESTFul services can be developed using Spring MVC.

I have a situation where I have Spring webapp and Spring RESTFul service. They both use other modules in common.

Is it possible that I can have Spring webapp contain RESTFul service along with Spring MVC web app?

Do I need to have two DispatcherServlet with different URL pattern?

Thanks
Anant


Definitely, actually I think that would be the preferred route for all web apps. In some cases, people will make their entire Web App be RESTFul.

Anyway, the whole key is that the Controller code should not be "specific" in just Spring MVC or Spring RESTFul. It is both. The Controller code wouldn't change and a method in a controller can handle both a RESTFul and regular request.

I wrote a web app recently, not live, but al I had to do was change the URL by just adding a ".json" to go from a standard web URL request to a RESTFul request for a JSON representation of some data.

Mark
 
Anant Jagania
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

Thanks for the reply.

So I can have both types of requests go through the controller. Thats really great.

I couldn't understand about the changing the request to .json for sending it to RESTFul method of controller. I understand that you have the JSON representation.

I will have to use the object marshalling due to security reason.

Thanks
Anant
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anant Jagania wrote:Hi Mark,

Thanks for the reply.

So I can have both types of requests go through the controller. Thats really great.

I couldn't understand about the changing the request to .json for sending it to RESTFul method of controller. I understand that you have the JSON representation.

I will have to use the object marshalling due to security reason.

Thanks
Anant


There is a new "view resolver" This is for the new RESTful Web Services, and it can also contain a list of other view resolvers. So you can map by request type, and also extension. So if the URL is say www.mywebsite.com/MyApp/Account/list in the browser, then the returned view string will be used to resolve to say a jsp page. But if the url in the browser is www/mywebsite/MyApp/Account/list.json it will call the exact same Controller method, however the Model that is returned will be sent back as JSON representation instead of going to a jsp page.

When you read about Spring RESTful, you will see what I mean.

Hope that helps

Mark
 
Anant Jagania
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

This sounds really great. I will definitely look for the new view resolver.

When you read about Spring RESTful, you will see what I mean.


As of now i do not have any material which can explain well about Spring RESTFul. Please let me know if you have some links for it.

I am going to buy Spring in Action, Third Edition but its not available in store right now.

Thanks
Anant


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic