在spring中执行时java.lang.NoClassDefFoundError

时间:2015-07-17 06:22:40

标签: java eclipse

执行提交按钮时出现java.lang.NoClassDefFoundError错误,编译非常成功,构建/类/

错误

-------
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 /控制器/ 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 /控制器/ 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;
    }

}

1 个答案:

答案 0 :(得分:0)

由于这是春天,您应该将PasswordCheck注释为@Service@Component并通过@Resource在控制器中提供。
这应该使它可用,因为在上下文加载时实例化Controller,组件扫描当时不会检测到PasswordCheck - 类。 所以,你应该这样做:

@Service
public class PasswordCheck {
    // code omitted
}

@Controller
public class CrunchifyHelloWorld {

    @Resource
    private PasswordCheck passwordCheck;

并使用bean名称&#34; passwordCheck&#34;在你的方法中。