Spring MVC Controllers vs. Webscripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2014 01:47 AM
<servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/springMVC/*</url-pattern> </servlet-mapping>
Added a springMVC-servlet.xml like this: (only important bits:
<context:annotation-config /> <context:component-scan base-package="org.xxx.alfresco.web"/> <mvc:annotation-driven />
and presto! SpringMVC Controllers in my Alfresco. I can even easily inject the registry, nodeservice, etc…. (Actually, the @Autowired annotation works so it's so easy and supercool.)
This seems A LOT simpler than the webscript framework. More powerfull/flexible, I can do views/templates. Yes I understand that I can do all of this in a webscript, but SpringMVC is SO much easier.
Now, I did a quick search on the internets and found nothing on this technique. Which makes me think one of 3 things: (in ascending order of likelihood)
1. I am a ground breaking genius.
2. This is obvious, been done many times, and so simple no tutorials are necessary.
3. There is something horribly wrong with this technique.
I assume that it is #3, but what do you think?
Any feedback would be greatly appreciated.
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2014 11:56 AM
You will need to handle your transactions and exceptions correctly ( with a retrying transaction helper ) so you will also need to reinvent some framework code to go on top of sping mvc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2014 01:01 PM
So if I inject, say, the node service into my web script, how is that different, transaction wise, from using it in a SpringMVC controller?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2014 02:54 AM
I've been a Java developer for many years and love Spring and its MVC implementation.
Having said that, I experimented webscripts with Alfresco and one of the main advantages I found was that I was able to modify my webscripts and test them simply refreshing the index page. This doesn't mean that I quit using Java and Spring, but this brought to me another point of view about developing.
And remember that Alfresco always runs Spring under the hood, giving you all its power.
Well your developers should get acquainted with Javascript and Freemarker templates, but might save a lot of time recompiling and redeploying the code.
Regards,
Andrea
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2014 05:52 AM
You can also have alfresco webscripts with Java implementations if the use of alfresco script is a concern.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2016 04:11 AM
Hi,
I am aware the thread is old, but wanted to let you know about GitHub - dgradecak/alfresco-mvc that is a project I developed and actually is the glue code between alfresco and spring MVC. I am also using it on the share side and expose spring-data-rest for instance. On the repository side I wrote another module that uses alfresco @mvc to expose something that I call spring-data-alfresco and is actually exposing spring data repositories to be used within alfresco with actually an implementation that access alfresco as a spring data repository resource.
But I highly recommend to check the original production ready and used in many projects (not by me only) Alfresco @MVC project.
The wrong approach with what you have in the original post is that you do not use the webscript framwork, so no authentication etc are taken in consideration by alfresco., The module I am talking about is actually a webscript that uses a DispatcherServlet under the hood and therfore all the alfresco advices etc are being applied to every request to a spring controllers. And the lasts thing it has a pretty useful annotation to annotate services @AlfrescoTransaction (and some more).
So you are not alone in this quest
