0

getting error of java.lang.NoClassDefFoundError while executing the submit button, the compilation was really successfull and the build/class/

Error

-------
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@31809212: defining beans [crunchifyHelloWorld,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,viewResolver,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Jul 17, 2015 2:09:59 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: com/crunchify/controller/PasswordCheck
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
    at java.lang.Class.getDeclaredMethods(Class.java:1855)

src/com/crunchify/controller/CrunchifyHelloWorld.java


package com.crunchify.controller;

import com.crunchify.controller.PasswordCheck;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.validation.*;
import org.springframework.web.servlet.ModelAndView;
/*
 * author: Crunchify.com
 * 
 */

@Controller
public class CrunchifyHelloWorld {

    @RequestMapping("/welcome")
    public ModelAndView helloWorld() {

        String message = "<br><div style='text-align:center;'>" + 
                         "<h3>********** Welcome to LDO Support Landing page **********<h3> </div><br><br>";
        return new ModelAndView("welcome", "message", message);
    }


    @RequestMapping(value = "/loginCheck", method = RequestMethod.GET)
      public ModelAndView addContact(@ModelAttribute("index")
      com.crunchify.controller.PasswordCheck passcheck, BindingResult result) {

            System.out.println("userid:" + passcheck.getUser_id() + "password:" + passcheck.getPassword());

                //return "redirect:contacts.html";
            String message = "<br><div style='text-align:center;'>" + 
                     "<h3>********** Welcome to LDO Support Landing page **********<h3> </div><br><br>";

                return new ModelAndView("welcome", "message", message);
        }


}

src/com/crunchify/controller/PasswordCheck.java

package com.crunchify.controller;

public class PasswordCheck {

    private String user_id;
    private String password;
    public String getUser_id() {
        return user_id;
    }
    public void setUser_id(String user_id) {
        this.user_id = user_id;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

}
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Gopal
  • 757
  • 3
  • 13
  • 30

1 Answers1

0

Since this is Spring, you should annotate the PasswordCheck as @Service or @Component and make it available in the controller via @Resource.
This should make it available, since the Controller is being instantiated while the context loads, your component scan will not have detected the PasswordCheck-class at that time.
So, you should do this:

@Service
public class PasswordCheck {
    // code omitted
}

and

@Controller
public class CrunchifyHelloWorld {

    @Resource
    private PasswordCheck passwordCheck;

and use the bean name "passwordCheck" in your method.