简体   繁体   中英

how to invoke spring mvc from pojo

I am new to spring world. I am trying to add to new functionality to an existing spring MVC based reporting project. The new functionality would give the user an ability to schedule a particular report to run every so often. I see that in current design, model and Controller sections of MVC is tightly coupled. Due to time constraints, I am not trying to separate Model and Controller instead want to use the existing infrastructure as is. My plan is to mimic the browsers request in a pojo and somehow call spring's MVC to handle my request. Am i going in right direction, if so how to I invoke the spring MVC from a POJO, if not, what would be the right approach. Please help........

If i understand you correctly, basically you would like to :

  • create a non-web application that makes requests to existing Spring MVC controllers
  • and that you have to reuse existing controllers
  • and NOT reusing the business model, because you dont have the time to separate the business model from the controller

Basically you are doing web services with this approach, where you make requests to the controllers via http using a http client library. And perhaps, get the response as json, which you can later map into a java bean, and continue your work from there.

You can have the controller to return the view's model as xml, or json, etc , or even directly return a bean as json or xml using spring's message converter .

If you are already using Spring 3, there is a RestTemplate that you can make use of to simplify this. You could also make use of Apache's HttpClient, whose interesting example that you can see in this REST template code. This related Q&A on java http clients could also be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM