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.

13 comments:

சின்னப்பயல் 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!

Anonymous 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

Unknown 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

Unknown 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

IICT 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

Unknown 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

Unknown 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

cynthiawilliams said...

Excellent blog admin, share more like this.
Spring Training in Chennai

priya rajesh said...

Thanks a lot for sharing this page really helpful.
Spring Hibernate Training in Chennai
Hibernate Training in Chennai
Spring and Hibernate Training in Chennai
Struts Training in Chennai
RPA Training in Chennai
AngularJS Training in Chennai
AWS Training in Chennai

TIC Academy said...

Excellent Post
Manual Testing Training in Chennai
QTP Training in Chennai
Selenium Training in Chennai
SoapUI Training in Chennai
Software Testing Training in Chennai

MDSU BA 1st Year Exam Result 2021 said...

This is the one of the most important information for me. And I am feeling glad reading your article. The article is really excellent ?

MDSU BA 2nd Year Exam Result 2021 | MDSU BA 3rd Year Exam Result 2021.

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.