elidev


Diary of a coder.

Archive for April 8th, 2011

Posted by eli at 8 April , 2011

This week I decided to play around a little bit with Spring MVC. I am not a web programmer by occupation, but it is something I want to learn, and I decided to start with this tutorial. The choice of Spring was rather random, except for the fact that I wanted to use Java as a programming language since this is familiar territory for me.

To complicate matters, I decided to run the latest version of Spring, 3.1, instead of 2.x as suggested in the tutorial. With jar names changed I also quickly decided to abandon ant for Maven, which overall turned out to be a good choice. Maven can certainly be a little (or a lot) clunky, but the dependency management makes it all worthwhile. Luckily, I found another guide that comprehensively describes the Maven integration. For development environment I used Eclipse, which despite its various shortcomings is my first choice for Java development.

Setting up the Tomcat application server was more complicated. Keep in mind that I have only coded very basic web applications before, so it was a lot of work to get the debug environment up and running. While I am sure there must be an easier way to do it in Eclipse via a Server project, I ended up running a standalone Tomcat installation, redirecting via server.xml to my Maven target directory like so:

<Context docBase="C:\workspace\springapp\target\spring-mvc-trial-1.0" path="/spring-mvc-trial-1.0" reloadable="true"/>;

I then had to include all the Tomcat jars from the installation as external jars in my Eclipse project before I could finally start the server in debug mode by calling the startup class directly. Cumbersome as this may be it works for now, although I will probably have to revisit this in the future.

My general impression of Spring is mixed. On one hand, I suppose it is nice to have the code separated into Model/View/Controller with configuration in XML, but on the other hand it is easy to see how this whole approach could get completely out of hand. XML may be a good tool for many things (configuration, data specification etc), but it is crappy as a program language. Moving implementation into XML files via excessive use of beans seems like a terrible idea, yet I can easily imagine how one would end up in this situation in Spring when programming for “configurability”.

So does Spring speed up the process of getting a website up quickly? Well, not really. Of the limited options I have tried to get a website up in the quickest possible way PHP wins hands down. This is surprising to me, since I figured all the newer neat frameworks (Ruby on Rails, Grails, Spring etc) would help with this, but the reality is that they have a steep learning curve. In PHP, what you need to know from start basically boils down to the language itself and some basic SQL, while with these other frameworks you have to grasp the relationship between model, view and controller, and probably at least two different programming languages (one for templating and one for code) as well. Not to mention all the work you need to put in to get a test environment up and running, where in PHP you would just copy your files to a folder. PHP also seems to be supported more at inexpensive web hotels, at least in my limited experience. Having said this, PHP certainly has its drawbacks. It is a mess of black magic calls to global structures, and I suspect it fosters horrible programming habits when it comes to OOP concepts etc.

I think I will stick with Spring for now, mostly because it is based on something I have good knowledge of (Java). My next project will be to upgrade my code from the tutorial to use the Spring 3.1 features in full, by replacing all the calls to deprecated functions and take more advantage of the annotation based framework.

 

 

Tags: ,
Posted in: Uncategorized | No Comments »