2008/09/03

Simple tip: Inject the nested class in Spring context

It's a simple tip and is not mentioned in Spring reference docs:

When you want create a bean in Spring which is a nested class of some owner class, use the "$" to separate the owner class name and the nested class name like following example:

<bean class="org.balah.OwnerClass$NestedClass"
.....

Don't use the convention like "org.balah.OwnerClass.NestedClass" that is used in the source code usually. Because the Spring will use Class.forName() similar mechanism to find the class specified in the bean definition. As you use the Class.forName() to load a nested class, always use "$" to let the classloader locate the exact class file from your classpathes. The "." sperated convention just confused the class resolver anf finally throw a ClassNotFoundException.

10 comments:

Bharathirajan said...

Hello, a short while ago I was looking out for a Java Interview Questions, a renewed path, and I found this awesome site, http://www.prepareinterview.com/tips/questionJavaFAQ.asp . They have some brilliant tips, and some interesting links additionally. In less than five weeks I got myself a job. I won't tell you what it is, but I do it at home and I like it!

manu said...

A new java/J2EE website develope by me please check it out
www.fabgabs.com and join the new social networking sensation with maps and videos

peterson said...

Your technical information related with java programming is very useful and interesting. Also share updated details about java in your website. Thanks for sharing this article.
Java training institute in chennai

jack wilson said...

The Information which you provided is very much useful for JAVA Training Learners Thank You for Sharing Valuable Information.i like this blog and this is very informative.

JAVA Training in Chennai

Roshini RS said...

JAVA Training in Chennai

I have read all the articles in your blog; was really impressed after reading it. FITA is glad
To inform you that; we provide practical training on all the technologies with MNC exports. We
Assure you that through our training the students will gain all the sufficient knowledge to have a voyage in IT industry.
FITA Chennai Reviews

Emi Jackson said...

Thanks for sharing your view to our knowledge’s, its helps me plenty keep sharing...

Thanks and Regards.
iOS Training in Chennai | Informatica Training in Chennai

Steve Smith said...

Great and Useful Article.

Online Java Training

Online Java Training from India

Online Java Training

Online Java Training From India

Java Training Institutes in Chennai

Java Training in Chennai

Sathik Ali. A said...

Informative post for people who are using Java Spring but mostly nowadays i think all are using hibernate.

Regards
Java Spring Training in Chennai

Gopi Perumal said...

Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
Regards,

Regards,
CCNA Training in Chennai | CCNA Training Institute in Chennai | Best CCNA Training in Chennai

tessa tessa said...

Superb explanation & it's too clear to understand the concept as well, keep sharing admin with some updated information with right examples.Keep update more posts.

Web Design Company in Chennai

Well well... why another J2EE blog? I benefited from other people's technical blogs, and guess what, it's a good idea to contribute some of my works too. Hope it's helpful and useful, to all of your folks.