*
The moose likes Spring and the fly likes CannotLoadBeanClassException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "CannotLoadBeanClassException" Watch "CannotLoadBeanClassException" New topic
Author

CannotLoadBeanClassException

k sabeerdeen
Greenhorn

Joined: Mar 11, 2010
Posts: 14
hi..
i tried to call a method isValidUserId() in LoginImplementation.java from LoginMain.java

i am getting the following exception:

org.springframework.beans.factory.CannotLoadBeanClassException:
Cannot find class [LoginImplementation] for bean with name 'isValidUserId'
defined in class path resource [BusinessObject.xml];
nested exception is java.lang.ClassNotFoundException: LoginImplementation

i am using eclipse 3.4


LoginMain.java
===========

public static void main(String args[])
{

try{
LoginController loginController = LoginFactory.isValidUserId();
String result = loginController.isValidUserId(loginDTO);
}catch(Exception e){
// here i got the exception
}
}


LoginController.java
===================
public interface LoginController{
public Collection isValidUserId() throws Exception;
}

LoginFactory.java
=================

public class LoginFactory {

public static LoginController isValidUserId() throws Exception {
ClassPathResource resource = new ClassPathResource("BusinessObject.xml");
BeanFactory factory = new XmlBeanFactory(resource);
return (LoginController) factory.getBean("isValidUserId");
}
}

BusinessObject.xml
=============

<bean id="isValidUserId" class="com.visiontss.smartweb.spring.LoginImplementation"/>


LoginImplemetation.java
========================
public class LoignImplementation implements LoginController {
public Collection isValidUserId() throws Exception {
System.out.println("Yes Valid user");
}
}
thanks in advance
Mark Secrist
Ranch Hand

Joined: Jul 01, 2003
Posts: 89
Ultimately, it seems like it comes down to the Spring container not being able to locate the class LoginImplementation. Here are a couple of things to consider.
  • You may have mistyped the full path (package + class name) in the bean definition
  • A classfile may not have been generated since it looks like the isValidUserId method on LoginImplementation should return a value since your method signature says it does


  • Mark
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: CannotLoadBeanClassException
     
    Similar Threads
    que in spring mvc - simpleformcontroller
    Spring cannot find file in classpath (within JAR)
    Bean definition found but not found
    Configuration Issues with Spring Framework on eclipse
    very new to spring. Need help in this small spring program