PDA

View Full Version : why my spring beans cannot find their classes?



wangjian2000
Feb 4th, 2008, 05:10 AM
i am a beginner,my web-app use to run well.
but yesterday,i added a "dao.ReplyDAO" into my springDAO.xml ,then suddenly found that my beans could not find their classes any more.

the exception shows like this:

org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name 'membersDAO' defined in class path resource [conf/springDAO.xml]: Class that bean class [dao.MembersDAO] depends on not found; nested exception is java.lang.NoClassDefFoundError: null
conf.GetDAO.getDAO(:13)
DTO.Welcome.doGet(Welcome.java:27)


my conf/springDAO.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans SYSTEM "spring-beans.dtd" >
<beans>
<bean id="membersDAO" class="dao.MembersDAO" ></bean>
<bean id="boardDAO" class="dao.BoardDAO" ></bean>
<bean id="articleDAO" class="dao.ArticleDAO" ></bean>
<bean id="replyDAO" class="dao.ReplyDAO" ></bean>
</beans>

my GetDAO.java:
public class GetDAO {

public static Object getDAO(String daoName)
{
return new ClassPathXmlApplicationContext("conf/springDAO.xml").getBean(daoName);
}

}


my welcome.java:
public class Welcome extends HttpServlet {

public void doGet(HttpServletRequest request,HttpServletResponse response)
{
try {

MemberImp md=(MemberImp)GetDAO.getDAO("membersDAO");
... ....
}

}


and i swear i have checked the webapp in tomcat5.5,all the DAO classes exsit in their place ,but why my spring cannot find them??please help me.

labsilts
Feb 4th, 2008, 05:18 AM
And if you remove the "dao.ReplyDAO" it works again?

wangjian2000
Feb 4th, 2008, 05:49 AM
no,it won't run,even i have removed the "dao.ReplyDAO".
and the tool i use is eclipse,is this a bug of eclipse or tomcat?

labsilts
Feb 4th, 2008, 06:26 AM
Well, so I suppose you should have to use the full package name for your beans. I mean "dao.MembersDAO" should be something like "org.example.myapp.dao.MembersDAO".

Bye!
Christian

wangjian2000
Feb 4th, 2008, 06:39 AM
Well, so I suppose you should have to use the full package name for your beans. I mean "dao.MembersDAO" should be something like "org.example.myapp.dao.MembersDAO".

Bye!
Christian

no,the "dao.MembersDAO" is the "full package"!!what could i suppose to do ?!!!

wangjian2000
Feb 4th, 2008, 06:44 AM
i am crazy......help me,please

Marten Deinum
Feb 4th, 2008, 07:00 AM
First of all when posting code pleae use the [ code][/code ] tags, that way we can still read your code. Second post your whole stacktrace.

Next to the above 2 issues you also have another issue.



public class GetDAO {

public static Object getDAO(String daoName)
{
return new ClassPathXmlApplicationContext("conf/springDAO.xml").getBean(daoName);
}

}

If you want to run out of resources and performance that is the way to retrieve beans! Use the ContextLoaderListener and use the WebApplicationContextUtils to get a reference to the ApplicationContext, that way it will be loaded only once.

wangjian2000
Feb 4th, 2008, 08:13 AM
If you want to run out of resources and performance that is the way to retrieve beans! Use the ContextLoaderListener and use the WebApplicationContextUtils to get a reference to the ApplicationContext, that way it will be loaded only once.[/QUOTE]


thank you very much,i am sorry for not using tag code.but i still don't know how to use WebApplicationContextUtils to solve my trouble.would you please tell me more about it ??or an example will be great!!!

wangjian2000
Feb 4th, 2008, 06:58 PM
anybody could help me??

Marten Deinum
Feb 5th, 2008, 12:34 AM
Read what I posted and post the whole stacktrace!



but i still don't know how to use WebApplicationContextUtils to solve my trouble

It isn't going to solve this problem but the problem you would get in the future.