<< September 22, 2005 | Home | September 24, 2005 >>

Accessing a Spring bean from a servlet

I'm using Ajaxtags to implement an ajax-enabled form with dynamic dropdown fields. In order to access my DAO object (which is a Spring managed bean)  to get the dropdown options, I had to have access to the Application context from a regular Servlet.

The solution is very simple, but since I had some troubles finding it, I'm adding it here for future reference, and for anyone who's looking for the same. Basically, you use the WebApplicationContextUtils object from the spring framework to get a reference to your bean. Inside the doGet() method I have:
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
Object myDao = context.getBean("daoBeanName");

It's that easy... really.
Categories : Tips

Best Linux distribution for java

I've been using Gentoo on my laptop for a while, and while I find the features of Gentoo to be very powerful (compile from source to target your specific machine, central source repository, repository synchronization, etc), the fact that updating any major application takes a couple of days has really hit me. I've been looking for a distribution that is more end-user friendly, but that also supports all of my hardware (or most of it). Also, since my main focus is java development, I want a distribution that has good support for java, including support for the latest Eclipse release, 3.1.
My current candidates at the moment are:
  • Sun Java Desktop System 3. But it's Solaris, not Linux, and I'm not sure I want to move to Solaris at this point in time. Plus, it's mostly GNOME, while I prefer KDE.
  • Fedora Core 4. It looks to be the best choice, as many companies that provide Linux drivers (open or closed source) are at least doing it for Fedora. Plus, It seems to support most of my laptop's hardware.
  • Kubuntu 5.04. Debian with an attitude. But I haven't seen too much support for java from Ubuntu.
  • Mandirva 10.1. I used to run Mandrake a while ago, but I haven't checked Mandriva. But, it seems that they carry KDE 3.2, while the others are already carrying 3.4 and 3.5 is even in beta now.
Are you using a linux distribution that you think is better than the ones mentioned aboce? why? Are you using one of the distributions mentioned above? what are your experiences?
Categories : Java, Linux