I'm trying to create some Java EE application. The base is EJB as a controller. Next I want to present the data with JSF+ManagedBeans. The problem is there is
javax.servlet.ServletException: standards/SampleController
java.lang.NoClassDefFoun开发者_JAVA百科dError: standards/SampleController
The Code looks like this:
Managed bean(Dynamic Web Project):WebView project: StdSampleController.java:
import javax.ejb.EJB;
import standards.SampleController;
public class StdSampleController {
@EJB private SampleController c;
public String value;
public StdSampleController() {
c = new SampleController();
value = c.getValue();
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
EJB(EJB Project): WebController project: standards.SampleController.java:
package standards;
import javax.ejb.Stateless;
/**
* Session Bean implementation class SampleController
*/
@Stateless
public class SampleController implements SampleControllerRemote {
private String value;
public SampleController() {
value = "EJB:SampleController bean";
}
public String getValue(){
return value;
}
}
All this code is put together in an Enterprise Application Project.
I use GlassFish version 3 and Eclipse 3.5.2.Adding to the answer of unbeli, please remove the following from your code:
public StdSampleController() {
c = new SampleController();
value = c.getValue();
}
This is wrong. In the situation you're depicting, c
will be injected by the container with a reference to your EJB. Do not instantiate the EJB yourself via the new() operator.
You call your EJB using the (remote) interface, not it's implementation. Therefore, instead of
@EJB private SampleController c;
you need
@EJB private SampleControllerRemote c;
and adjust imports accordingly.
精彩评论