Skip to content

Running Grails on Tomcat 7 — nasty “SEVERE: Error listenerStart” error

PROBLEM:

Working through an integration project for a client we encountered an issue with Tomcat not being able to start our Grails application which housed our Apache Camel integration routes.

When we started tomcat it would throw a “SEVERE: Error listenerStart” error.

The problem was there was no way of narrowing down the error, as Tomcat wasn’t outputting the root cause of the exception.  

ENVIRONMENT:

  • Grails 2.0.4
  • Tomcat 7.0.34
  • Java 1.6.0_43

SOLUTION:

After tomcat explodes out the war file

  • stop tomcat
  • go into the following dir <tomcat dir>/webapps/<appname>/WEB-INF/classes 
  • add a file called logging.properties with the following content below
  • start tomcat
  • should see root cause in logs/<appname>.log

 

logging.properties (sample)

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler org.apache.juli.FileHandler.level = FINE

org.apache.juli.FileHandler.prefix = <appname>.

java.util.logging.ConsoleHandler.level = FINE

java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

Link

SpringOne 2GX in Washington 2012 VIDEOS

SpringOne 2GX in Washington 2012 VIDEOS

Attended the SpringOne 2GX conference this year in Washington.  Was a great time/experience — planning to attend in 2013 via Middleware360 Solutions Inc.

Here are the published Videos from 2012.

Java Date Formatting and Thread Safety

Real Time Saver… 

I was recently on a consulting engagement and requested to make modifications to a high volume JMS implementation (over 14 million messages per day).  One of the tasks was to onboard/integrate a legacy system to the enterprise messaging system.  One of the requirements was to attach two additional message headers as follows (in order to support an audit process already in place):

  1. Date in which the Message was published to the system (format “2013-01-20″ [String])
  2. Time in which the Message was published to the system (format “15:57:31″ [String])

The bridge to the messaging system is multi-threaded, so I needed to find a thread safe way of getting both the Date and Time formatted to the outlined requirement.  As most java developers are aware SimpleDateFormatter is NOT THREAD SAFE!  

After some quick looking and trying I ended up with the following:

Image

 

Worked Great!

 

Quick intro to Spring Framework StopWatch Utility

I recently worked on a Spring based project, and was tasked with identifying where the bottleneck was within a set of service calls.  So I utilized the Spring StopWatch implementation to help isolate the issue(s).

This blog entry will provide you with a high level understanding of what the Spring StopWatch utility has to offer.

Heres how I did it…

1. First off I create a Java Project

2. Next I add Spring and Groovy Support to the Project

I am adding the Groovy Language support, so I can keep my code as simple and clean as possible (no need for try/catch, semi-colons, etc…).  Note: you can implement this code in pure Java!

3. Next I make my new Groovy Class

5. Next write the implementation code

  • import org.springframework.util.StopWatch
  • setup the service calls I want to test (repeat as needed)

6. Run the Code and View the output

7. Now taking this to the next level would be to incorporate what I have demonstrated within this post with Spring AOP :-)

Thanks,
Derek Marley

When to Optimize your code?

Sometimes it is hard to just say it works and meets the requirements therefore it is done!  I always feel like I can do better, and improve the solution in some way.  In most cases we think we can optimize the code to make it better.  When you feel that way turn to Effective Java by Joshua Bloch, Item 37: Optimize judiciously

“There are three aphorisms concerning optimization that everyone should know.  They are perhaps beginning to suffer from overexposure, but in case you aren’t yet familiar with them, here they are:

More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason–including blind stupidity.

–William A. Wulf [Wulf72]

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

–Donald E. Knuth [Knuth74]

We follow two rules in the matter of optimization:

Rule 1. Don’t do it.

Rule 2 (for experts only).  Don’t do it yet–that is, not until you have a perfectly clear and unoptimized solution.

–M. A. Jackson [Jackson75]

All of these aphorisms predate the Java programming language by two decades.  They tell a deep truth about optimization: Its is easy to do more harm than good, especially if you optimize prematurely.  In the process, you may produce software that is neither fast nor correct and cannot easily be fixed.”

Groovy Methods Explained — (How they differ from Java Methods)

Over the past little while I have been writing my test scripts using Groovy and Geb (a web functional test framework). During this process I found myself writing more Groovy style methods, so I wanted to look at what the differences were between Java and Groovy methods.

So now my findings…

For the most part the differences are focused around eliminating as much code from your class definitions as possible (hopefully making your code more readable by eliminating the “noise”).

Essentially there are 4 major differences

  1. default visibility is Public
  2. return keyword is optional
  3. the method return type is optional
  4. parameter types are optional

I will now show a quick code snippet with a Java version followed by a Groovy version.  This way you can be the Judge!
Personally I am becoming a fan.

Imagine having 10,15, 20 plus methods – you will start to see the simplicity.

JAVA

    public String sayHello(String firstName, String lastName){
        return “Hello” + firstName + “ “ + lastName
    }

Groovy

    def sayHello(firstName, lastName){
        "Hello ${firstName}  ${lastName}"
    }

Another interesting feature(s)…

Positional Parameters and default parameter values

Groovy has the notion of positional parameters, and the ability to set default values if one of the parameters are not passed to the method.

Example

    def adder(arg1, arg2, arg3 = 5){
        arg1 + arg2 + arg3
    }

    assert adder(1,2,3) == 6
    assert adder(1,2) == 8

Grails BootStrap within the Grails Console

While in the initial stages of Grails application development you may find yourself wanting to run the BootStrap.groovy script within the Grails Console.

Paste the following code into the console and Voila…

new BootStrap().init(ctx.servletContext)

Follow

Get every new post delivered to your Inbox.