I'm still new to Java EE 7 / Spring and trying to solve the following issue. I use Glassfish 4.1 and JDK 1.8.
I have created a test project in Eclipse (New Project -> Spring Project -> Simple Java) using the project facets "Dynamic Web Module", "Java", "JavaScript", "JavaServer Faces" as follows:
index.xhtml
<!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>
Bean.java
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";
}
}
UserServiceImpl
package springWeb;
import org.springframework.stereotype.Component;
//@Component
public class UserServiceImpl implements UserService {
@Override
public void service() {
System.out.println ("Service running...");
}
}
When pressing the Command-Button, I receive the following error:
javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/springframework/context/annotation/AnnotationConfigApplicationContext
root cause javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: org/springframework/context/annotation/AnnotationConfigApplicationContext
root cause java.lang.NoClassDefFoundError: org/springframework/context/annotation/AnnotationConfigApplicationContext
root cause java.lang.ClassNotFoundException: org.springframework.context.annotation.AnnotationConfigApplicationContext
What is the reason for this and how to solve it? (For reasons of clarity, I have commented out the dependency injection.)
Thank you very much for your help!