我还是Java EE 7 / Spring的新手,并尝试解决以下问题。我使用Glassfish 4.1和JDK 1.8。
我使用项目方面“Dynamic Web Module”,“Java”,“JavaScript”,“JavaServer Faces”在Eclipse中创建了一个测试项目(New Project - > Spring Project - > Simple Java),如下所示:
的index.xhtml
TimeLogger.log
Bean.java
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:form>
<h:commandButton value="Submit Query" action="#{bean.login()}"></h:commandButton>
</h:form>
</html>
UserServiceImpl
package springWeb;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@RequestScoped
@Named
public class Bean {
//@Autowired
private UserService userService;
public String login(){
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(springConfiguration.class);
// userService = (UserService)context.getBean("UserService");
// userService.service();
return "go.jsf";
}
}
按下命令按钮时,收到以下错误:
javax.servlet.ServletException:java.lang.NoClassDefFoundError: 组织/ springframework的/上下文/注解/ AnnotationConfigApplicationContext
根本原因javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: 组织/ springframework的/上下文/注解/ AnnotationConfigApplicationContext
root cause java.lang.NoClassDefFoundError: 组织/ springframework的/上下文/注解/ AnnotationConfigApplicationContext
root cause java.lang.ClassNotFoundException: org.springframework.context.annotation.AnnotationConfigApplicationContext
这是什么原因以及如何解决? (为清楚起见,我已经注释掉依赖注入。)
非常感谢你的帮助!
答案 0 :(得分:0)
最后我能够自己解决问题。原因是我的代码依赖于并且在编译时出现的类文件在运行时尚未找到。因此,我不得不复制七个缺少的库(例如spring-context-4.2.0.RELEASE.jar,spring-expression-4.2.0.RELEASE.jar,spring-core-4.2.0.RELEASE.jar,spring- context-support-4.2.0.RELEASE.jar等)到以下Glassfish libary-folder
C:\的glassfish-4.1 \ glassfish4 \的glassfish \域\ domainXXXX \ lib中
您可以轻松在线找到的遗失的图书馆,例如在Maven存储库中:http://repo1.maven.org/maven2/
帮助我理解这一点的相关帖子是: Why am I getting a NoClassDefFoundError in Java?和 Maven vs. Eclipse Project Facets for Java EE 6