On Java, Python, Groovy, Grails, Spring, Node.js, Linux, Arduino, ARM, Embedded Devices & Web

Archive for the ‘Spring’ Category

Tomcat 6+: Infamous “SEVERE: Error listenerStart” message – How-To debug this error?

Posted by Venkatt Guhesan on July 1, 2011

I’m sure if you have been developing with Java and Tomcat for sometime, you are likely to run into the infamous debug error.

SEVERE: Error listenerStart

You will most likely start Googling it trying to find out what the heck is going on. And in trying to see the extended logging on what that “listenerStart” error means. After some lucky searches, you will see links asking you to drop a “” file under ‘/WEB-INF/classes’ directory inside your WAR to help debug which one of the listeners is throwing this crazy error.

Well, this advise will most likely work for you if you are developing under an earlier version of Tomcat. If you are using versions 6.0 or above then continue to read on…

In Tomcat 6 or above, the default logger is the”java.util.logging” logger and not Log4J. So if you are trying to add a “” file – this will NOT work. The Java utils logger looks for a file called “” as stated here:

So to get to the debugging details create a “” file under your”/WEB-INF/classes” folder of your WAR and you’re all set.

And now when you restart your Tomcat, you will see all of your debugging in it’s full glory!!!

Sample file:

org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler

and you will most likely see a “class-not-found” exception.😉

Look at the bright side, you’re now one step closer to the solution.

Happy coding!

Posted in Grails, Groovy, GWT, Java, Spring, Spring Framework, Tomcat, web development | Tagged: , , , , , | 25 Comments »

Spring Framework Samples and Reference Implementations online in svn

Posted by Venkatt Guhesan on April 19, 2010

Sometimes it’s good to look at the svn repository for the reference sample that Spring Framework provides.

Here’s a quick link for that URL:

You can traverse through it via a HTTP(s) browser or you can download the latest samples via tools like TortiseSVN.

Here is a list of some of the projects samples that are available today:

spring-samples – Revision 431: /

* configuration-basic/
* jpetstore/
* mvc-ajax/
* mvc-basic/
* petcare/
* petclinic/
* petclinic-groovy/
* spring-travel/
* task-basic/
* templates/
* tutorials/

Hopefully this article will be beneficial for someone who is trying to get familiar with Spring Framework.


Posted in Java, Programming, Spring, Spring Framework | Tagged: , , | Leave a Comment »

Spring 3.0 – Application Context – three ways to get the context

Posted by Venkatt Guhesan on March 22, 2010

In searching Google for “Spring ApplicationContextAware“, you come across a lot of recommendations and I also see a lot of folks continuing to complain saying that their setApplicationContext method does not get invoked. So to help clarify, I’m blogging a few notes in hope that it helps clarify a few things.

Two Ways to Get Application Context:

Method #1:  In your class you implement ApplicationContextAware class like this:

public class MyClass implements ApplicationContextAware {

    static final long serialVersionUID = 02L;

    ApplicationContext applicationContext = null;

    public void doSomething(){
        if (applicationContext != null && applicationContext.containsBean("accessKeys")){
            MyBean beanA = (MyBean) applicationContext.getBean("mybean");
            //Do something with this AccessBean

        return null;

    public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
        System.out.println("setting context");
        this.applicationContext = applicationContext;


Method #2: If you are in a Java Servlet, you can do the following:

public class gzservlet extends HttpServlet {
    static final long serialVersionUID = 02L;

    ApplicationContext applicationContext = null;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (applicationContext == null){
            System.out.println("setting context in get");
            applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        if (applicationContext != null && applicationContext.containsBean("accessKeys")){
            AccessBean thisAccessBean = (AccessBean) applicationContext.getBean("accessKeys");
            req.setAttribute("keys", thisAccessBean.toString());
            System.out.println("setting keys");



So the question one would ask is when to use what? And the answer is. Depends on how you are invoking Spring.

What works for Method #1: when you invoke Spring you are using the DispatcherServlet link this. Then Method #1 will resolve the implementation of ApplicationContextAware and call the setApplicationContext() method to set the context.

In web.xml.



If you are not using the DispatcherServlet and you are initializing Spring using a Listener and you have your own Servlet that’s driving the Request\Response scope then use Method #2. Below is an example of how the web.xml will look like in this case.




I hope this clarifies why sometimes even though you have implemented the ApplicationContextAware interface, your setter does not get invoked.

[09/12/2010] Here is a third way to get your context:

Create the following class with a static method to get your context:

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ApplicationContextProvider implements ApplicationContextAware{
 private static ApplicationContext ctx = null;
 public static ApplicationContext getApplicationContext() {
return ctx;
 public void setApplicationContext(ApplicationContext ctx) throws BeansException {
this.ctx = ctx;

and in your spring bean configuration xml file add the following:

<bean id="applicationContextProvider" class="ApplicationContextProvider"></bean>

And now in your classes, you can do the following:

ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();

That’s it!!!


If you find this article useful, consider signing up for my RSS feed or Email Newsletter. See links on the right side.

Posted in Programming, Spring | 31 Comments »