Spring, Flex, BlazeDS Full Stack is Back!
After trying for weeks to integrate Flex and BlazeDS into Grails, in vain, I’ve decided to come back to vanilla Spring/Hibernate for Conference Guide server. And I took the opportunity to upgrade my todolist sample application, the one featured in the article published both on this blog and on the Adobe Developer Connection.
Here are the improvements compared to the original version:
- I replaced the old SpringFactory by Spring BlazeDS Integration (spring-flex) library
- I’ve added basic security using Spring Security, based on Cristophe Coenraets’ article on DZone
- The domain now has 2 entities with a one-to-many relationship: you can manage several todolists, each having several items
- I’m now using proper DTO’s for data transfer between the client and the server, which is for me the cleaner way to do things
- Flexmojos Maven plugin has been upgraded to 3.4.2 (the latest stable version today).
I won’t go into detail about every aspect of this project because I think it can be much more useful to use it as a basis rather than try to reproduce it from scratch. Here is what you need to do to make it work:
- Download the project source code on GitHub
- Install Maven 2.2.0 if not already done
- Run “mvn install” at the root of your project until you get a BUILD SUCCESSFUL message
- Copy server/target/todolist.war to the webapps directory of your Tomcat server, or startup Tomcat and run “mvn org.codehaus.mojo:tomcat-maven-plugin:1.0-beta-1:redeploy” from within the server module
- Open your browser on http://localhost:8080/todolist and login as john/john
- Enjoy!
If you have any suggestion for improvements, of if you have any question, feel free to leave a comment here. Cheers!
This content is published under the Attribution-Noncommercial-Share Alike 3.0 Unported license.
Subscribe to the RSS feed and have all new posts delivered straight to you.


Have you tried to exchange data using JSON through asynchronous XHR using the same technology stack ? The backend exposes REST like web services. The frontend is completely decoupled from the backend implemention. It looks cleaner but it might not worth the trouble. What do you think ?
Whenever possible, I always prefer remoting protocols (hessian, burlap, AMF) to message-based protocols (REST, SOAP). Plus, AMF is highly optimized and supports native serialization/deserialization with Java.
Hi! Thank you for your post!
Everything works fine, but project couldn’t compile.
I commented 1 line in client/pom.xml.
and now dependency section for common part of actionscript is:
${project.groupId}
todolist-common-as
${project.version}
swc
<!–rsl–>
what is “rsl” scope for ?
And one more question:
After I login, sometimes (almost every request to todoListService) i get an error: An Authentication object was not found in the SecurityContext. Why is that? Do you get the same error?
Thank you!
You should leave it as RSL. RSL is a special scope. I think it means “remote shared library” or something like that. The idea is to make it possible for users of the app to cache this library in their Flash player and thus reduce the size of the SWF they have to download. What error did you have exactly?
Concerning the authentication error, yes, I get that too from time to time but it’s very inconsistent. I’m still looking into it, but if someone knows where this comes from, feel free to raise your hand.
I recompiled the project and the error is:
Error resolving artifacts org.epseelon:todolist-common-as:swf:2.0-SNAPSHOT
Embedded error: Unable to download the artifact from any repository …
I’ll try to find the answer to the question about security error.
You must have changed something in the POM somehow because it’s looking for a todolist-common-as.SWF whereas todolist-common-as is built as a SWC library.
Can you please send me your project at sebastien.arbogast@gmail.com and I’ll have a look at it.
OK, so thanks a lot to Velo, the lead developer of Flexmojos: if you have the same problem as Evgeny, just run “mvn clean install” and it should do the trick.
Now concerning authentication, it’s true that it behaves strangely. I’ve created an issue (http://github.com/sarbogast/todolist-spring/issues/#issue/1) for that and I’ll let you guys know when I find where this comes from.
In the meantime, if another BlazeDS fan wants to check out the project and help me figure out what’s wrong, you’re more than welcome.
Hello, I’m try download the project source code on GitHub and it´s down.
Can you give me another link to try download the code.
Thanks for all.
No no, it’s not down. It’s right there. Check your network or something.
I too am having problems downloading this. Can someone post it somewhere else? let me know where to get it from?
I was able to sole this by creating an account on GitHub, along with branching this code and then downloading that and deleting my branch.
I agree that githib’s download interface is not the most intuitive in the world, but github is not down.
Try watching the following video and if it still doesn’t work I’ll send you a package.
http://screenjel.ly/fo3wHLg2s8Y
Hi,
I tried it but I get the stack trace as:
-verify-digests=true -static-link-runtime-shared-libraries=false -load-config=
-metadata.language+=en_US
[INFO] ————————————————————————
[ERROR] FATAL ERROR
[INFO] ————————————————————————
[INFO] Java heap space
[INFO] ————————————————————————
[INFO] Trace
java.lang.OutOfMemoryError: Java heap space
at macromedia.abc.AbcParser.getQNameFromCPool(AbcParser.java:1322)
at macromedia.abc.AbcParser.methodTrait(AbcParser.java:649)
at macromedia.abc.AbcParser.classTrait(AbcParser.java:1071)
at macromedia.abc.AbcParser.parseTraits(AbcParser.java:1144)
at macromedia.abc.AbcParser.parseScript(AbcParser.java:1197)
at macromedia.abc.AbcParser.parseAbc(AbcParser.java:108)
at flex2.compiler.abc.Compiler.parse1(Compiler.java:179)
at flex2.compiler.API.parse1(API.java:2315)
at flex2.compiler.API.parse1(API.java:2268)
at flex2.compiler.API.batch2(API.java:369)
at flex2.compiler.API.batch(API.java:1117)
at flex2.compiler.API.compile(API.java:1290)
at flex2.tools.oem.Application.compile(Application.java:1077)
at flex2.tools.oem.Application.recompile(Application.java:1029)
at flex2.tools.oem.Application.compile(Application.java:681)
at flex2.tools.oem.Application.build(Application.java:428)
at org.sonatype.flexmojos.compiler.AbstractFlexCompilerMojo.build(AbstractFlexCompilerMojo.java:2437)
You have to increase the memory limit allocated to Maven. Try creating an environment vairable called MAVEN_OPTS and set its value to -XX:MaxPermSize=128m -Xmx512m
Hello, thx for the updated tutorial, compilation is fine, deployment fine as well, login OK, but when i try to do anything with todos, i have issues with mysql.
Could you please remind how to configure mysql or point the proper link ?
I think compared to first tutorial, we now have on more table for todolist, but i’ve no idea how to configure it.
Thx,
Jahz
Normally, you shouldn’t have to configure anything. Database tables are created automatically the first time when the application starts, thanks to JPA and Hibernate. If you started with the database from the previous version, I suggest you create another database for this version and put the right connection data in the profile at the end of the root pom.xml.
Thx for you answer, all working fine now.
Jahz
Sebastien,
Thanks for the sample app! I built it and got it going in tomcat, but whenever I try to load a todolist it gives me the ‘Could not create Todo List’. The tables are getting created in my database, but something is wrong… Here is my tomcat log:
DEBUG JDBCTransaction – begin
DEBUG ConnectionManager – opening JDBC connection
DEBUG DriverManagerDataSource – Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/bandaid]
DEBUG JDBCTransaction – current autocommit status: true
DEBUG JDBCTransaction – disabling autocommit
DEBUG JpaTransactionManager – Exposing JPA transaction as JDBC transaction [SimpleConnectionHandle: com.mysql.jdbc.ConnectionImpl@6d9e6c]
DEBUG AbstractSecurityInterceptor – Secure object: ReflectiveMethodInvocation: public abstract java.util.List org.epseelon.todolist.business.TodoListService.getAllLists(); target is of class [org.epseelon.todolist.business.impl.TodoListServiceImpl]; ConfigAttributes: [ROLE_USER]
DEBUG JpaTransactionManager – Initiating transaction rollback
DEBUG JpaTransactionManager – Rolling back JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@97a607]
DEBUG JDBCTransaction – rollback
DEBUG JDBCTransaction – re-enabling autocommit
DEBUG JDBCTransaction – rolled back JDBC Connection
DEBUG ConnectionManager – aggressively releasing JDBC connection
DEBUG ConnectionManager – releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG JpaTransactionManager – Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@97a607] after transaction
DEBUG EntityManagerFactoryUtils – Closing JPA EntityManager
DEBUG ThrowsAdviceInterceptor – Found handler for exception of type [java.lang.Throwable]: public void org.springframework.flex.core.ExceptionTranslationAdvice.afterThrowing(java.lang.Throwable) throws java.lang.Throwable
DEBUG DispatcherServlet – Null ModelAndView returned to DispatcherServlet with name ’spring-flex’: assuming HandlerAdapter completed request handling
DEBUG DispatcherServlet – Successfully completed request
DEBUG RequestContextListener – Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@df9cf4
I don’t see any error in your log. Are you sure that you set the privileges right for your database user?
I manually inserted a todo record and it is working fine via the ui now… Thanks, mark
I want to use command “mvn eclipse:eclipse” to turn it to a eclipse project (in the root directory),but it cannot work.Can someone tell me how do it?
sebastien,
I am digging into your code… I am assuming that you used Granite to generate the .as files from your java objects?
I have created a new getter/setter on an object and am not seeing it generated in the .as file.
I deleted the file, assuming that it would be recreated but I get a compilation error now from the other .as files.
I’m sure this is a simple thing, but I can’t figure it out…
Thanks!
mark
Hi,
I tried converting the application that you created to run against HSQLD (instead of mysql) and then I tried running it via tomcat:run-war.
However, I think it sometimes fails to communicate with the server (I’ve placed breakpoints all over the place and they don’t seem to get hit). But several restarts, and it will start to work properly. But after that, another restart would most probably bring it back to its unusable state…Any ideas?
(Btw, I tried it with your version 01 – I migrated it to use HSQLDB and to use jetty:run-war and it worked properly).
Thanks,
Franz
I figured out what my problem is. I simply forgot to comment out the mysql dependency and that was enough to cause the erratic behaviour (even if hibernate was configured to use hsqldb).
Thanks,
Franz
Hi,
I opened it in eclipse, but could not figure it out how to run it.
I have installed tomcat also, how to run it in eclipse on tomcat.
Thanks.
Kiran
Hi Sebastien,
I thought you’d be glad to know this (great!) sample performs pretty well – I’m running it on a poor machine (Pentium 4 2GHz, 2 GB RAM) but still ~400k todolists are loaded in 30secs. from localhost. I just had to change log4j level from ‘debug’ to ‘info’ as console output is a big bad performance eater. Another interesting point is that I ran it in Jetty, but I guess this doesn’t matter that much.
Once again, great job!
Kudos,
Misho
Hi Sebastien,
Im had seen a couple of sample projects at your blog and im very much impressed with your demos.I’m new bee to flex+spring+blazeds.Can you please send me tutorials on integrating flex+spring in flex builder. It will help me a lot for my career improvement.
Thanks & Regards
Uday
Thanks for the pleasant feedback. Unfortunately, I won’t be of much help concerning Flex Builder as I’m not a big Eclipse fan myself so I don’t use Flex Builder a lot.
Hi Sebastien,
first of all, great work! However, I am having problems with optimization and metadata in the RSL module. I am using Parsley (http://www.spicefactory.org/parsley/), which requires that metadata be kept in the artifacts, which the keepAs3Metadatas configuration option takes care of when compiling swfs or swcs, but seemingly not when optimizing! The flexmojos plugin documentation mentions nothing on this matter, so I’m wondering whether this is an issue, desired behavior, or whether I am doing something wrong (should I post code here?)
Thanks,
Rade
I loved your first version and would really like to try the upgraded one but I just can’t get it to download…when I click on download source nothing happens…Am I doing something wrong?
Thanks
Admir
….ok got it to work, used another browser.
that’s what i am getting too, but your advice didn’t help i still get the same no matter what i do…
Thank you for this great example!
Hello Sébastien,
Thanks for the great example!
One question – what is by you the best way to build/redeploy application during the development – during code changes? The one that reduces time to the possible minimum.
Thanks at advance!