[英]java.lang.NoClassDefFoundError while executing in spring
执行提交按钮时遇到java.lang.NoClassDefFoundError
错误,编译确实成功,并且build / class /
错误
-------
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;
}
}
由于这是Spring,因此您应该将PasswordCheck
注释为@Service
或@Component
并通过@Resource
在控制器中使其可用。
这将使其可用,因为在上下文加载期间正在实例化Controller,此时您的组件扫描将不会检测到PasswordCheck
-class。
因此,您应该这样做:
@Service
public class PasswordCheck {
// code omitted
}
和
@Controller
public class CrunchifyHelloWorld {
@Resource
private PasswordCheck passwordCheck;
并在您的方法中使用bean名称“ passwordCheck
”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.