This article shows you three different ways how to get to the Spring Framework Application Context in your code.
Summary (This is a repost of an older article I wrote in 2010). In searching Google for “Spring ApplicationContextAware”, you will 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 how the context works.
Most likely you’ve landed on this page because you’ve searched for the error in a search engine and it brought you here.
Symptom: When you run “grails” under an existing project that you previously had (either on a different PC or from a source-control like GIT or SVN and you’ve mistakenly included the “build” directory).
The associated error would have been one of the following:
Grails No profile found for name [web] or java.
If you’re implementing any projects with Spring and Gradle (for build), as your project grows you may run into this issue. Or you’ve landed on this page by searching on Google for “Unable to locate Spring NamespaceHandler for XML schema namespace” (your actual XML that it’s error-ing out may vary).
Either way, you’re in luck! Most likely, you’re using the fatjar gradle plugin to create a single JAR for executing as “java -jar one-big-bundle.
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 “log4j.
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.