aspose file tools*
The moose likes Spring and the fly likes can One webapp contain Spring MVC and Spring RESTFul services Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "can One webapp contain Spring MVC and Spring RESTFul services" Watch "can One webapp contain Spring MVC and Spring RESTFul services" New topic
Author

can One webapp contain Spring MVC and Spring RESTFul services

Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
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

Joined: Feb 05, 2001
Posts: 17259
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Anant Jagania
Ranch Hand

Joined: Oct 20, 2004
Posts: 49
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

Joined: Feb 05, 2001
Posts: 17259
    
    6

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

Joined: Oct 20, 2004
Posts: 49
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


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can One webapp contain Spring MVC and Spring RESTFul services