Results 1 to 5 of 5
  1. #1
    cgk_js is offline Member
    Join Date
    Oct 2012
    Posts
    21
    Rep Power
    0

    Default org.springframework.beans.factory.CannotLoadBeanCl assException:

    I had created the simple spring MVC controller, when i tried to execute i am getting the error.

    Error Message:

    org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [SpringApp.web.java.HelloController] for bean with name 'Redirect.jsp' defined in ServletContext resource [/WEB-INF/springapp-servlet.xml]; nested exception is java.lang.ClassNotFoundException: SpringApp.web.java.HelloController


    This is my application structure.

    SpringApp
    ----Web Pages
    ----META-INF
    ----WEB-INF
    ----springapp-servlet.xml
    ----web.xml
    ----Redirect.jsp
    ----index1.jsp
    ----Source Packages
    ----java
    ----HelloController.java



    web.xml
    --------
    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    To change this template, choose Tools | Templates
    and open the template in the editor.
    -->
    
    <web-app version="2.4"
             xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
    
      <servlet>
        <servlet-name>springapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>springapp</servlet-name>
        <url-pattern>*.htm</url-pattern>
      </servlet-mapping>
    
    
      <welcome-file-list>
        <welcome-file>
          index1.jsp
        </welcome-file>
      </welcome-file-list>
    
    </web-app>
    springapp-servlet.xml
    ----------------------

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    
    1. This file will be used up by the DispatcherServlet and which contains the bean definition
    2. The file will be picked up by the specification in the WEB-INF/web.xml using <servlet>spring</servlet>
    3. hello controller is responsible for handling the request for the particular page of the website and known 
    as the page controller.
    -->
    
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
      <!-- the application context definition for the springapp DispatcherServlet -->
    
      <bean name="Redirect.jsp" class="SpringApp.web.java.HelloController"/>
    
    </beans>
    index1.jsp
    ---------
    Java Code:
    <%-- 
        Document   : index
        Created on : Nov 23, 2012, 11:55:53 AM
        Author     : gopc
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>Hello World!</h1>
        </body>
    </html>
    Redirect.jsp
    ------------

    Java Code:
    <%-- 
        Document   : index
        Created on : Nov 23, 2012, 11:55:53 AM
        Author     : gopc
    --%>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Hello Controller redirect</title>
        </head>
        <body>
            <h1>This is redirect from the HelloController!</h1>
        </body>
    </html>

    HelloController.java
    -------------------
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package java;
    /**
     *
     * @author gopc
    */
    
    
    
    import org.springframework.web.servlet.mvc.Controller;
    import org.springframework.web.servlet.ModelAndView;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    import java.io.IOException;
    
    public class HelloController implements Controller {
    
        protected final Log logger = LogFactory.getLog(getClass());
    
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            logger.info("Returning hello view");
            System.out.println("hi this handlerequest");
    
            return new ModelAndView("Redirect.jsp");
        }
    
    }
    Last edited by cgk_js; 11-23-2012 at 07:35 AM.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: org.springframework.beans.factory.CannotLoadBeanCl assException:

    Your controller class is HelloController under the java package. So when define it in the springapp-servlet.xml the class attribute of the bean should be "java.HelloController" instead of "SpringApp.web.java.HelloController".

  3. #3
    cgk_js is offline Member
    Join Date
    Oct 2012
    Posts
    21
    Rep Power
    0

    Default Re: org.springframework.beans.factory.CannotLoadBeanCl assException:

    i tried with java.HelloController but still i am getting the same error.

    i tried with glassfish and tomcat, receiving the same error.

  4. #4
    cgk_js is offline Member
    Join Date
    Oct 2012
    Posts
    21
    Rep Power
    0

    Default Re: org.springframework.beans.factory.CannotLoadBeanCl assException:

    hey, now i had removed the folder java and also removed the package java. now i is able to show the content of index1.jsp, but i am not getting any debug stage or System.out.println from the controller..

  5. #5
    cgk_js is offline Member
    Join Date
    Oct 2012
    Posts
    21
    Rep Power
    0

    Default Re: org.springframework.beans.factory.CannotLoadBeanCl assException:

    i am closing this, since i got after moving inside the WEB-INF/jsp with redirect.jsp and accessing using the http://localhost:8080/SpringApp/Redirect.htm

Similar Threads

  1. Replies: 11
    Last Post: 06-14-2012, 05:06 PM
  2. Replies: 4
    Last Post: 03-15-2011, 10:13 AM
  3. Replies: 5
    Last Post: 02-17-2010, 08:40 PM
  4. How to make Beans Lazily-instantiating beans
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 11:10 AM
  5. How to make Beans Lazily-instantiating beans
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 09:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •