我有两个模块WAR和Business。
我尝试在Web模块中注入无状态bean。但无法找到无状态豆?
错误在哪里?任何想法??
在业务模块中:
@Stateless
public class BusinessFacade {
public void processEntity(final MyEntitiy entity) {
System.out.println(entity.getName());
}
}
在WAR模块中:
@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {
@EJB
BusinessFacade businessFacade;
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
}
错误:
[31.08.12 10:19:38:835 CEST] 00000018 webapp E com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: {0}
java.lang.NoClassDefFoundError: com.myproject.business.beans.BusinessFacade
at java.lang.Class.getDeclaredFieldsImpl(Native Method)
at java.lang.Class.getDeclaredFields(Class.java:544)
at org.apache.myfaces.config.annotation.AnnotationConfigurator.fields(AnnotationConfigurator.java:846)
at org.apache.myfaces.config.annotation.AnnotationConfigurator.createFacesConfig(AnnotationConfigurator.java:328)
at org.apache.myfaces.config.annotation.AnnotationConfigurator.createFacesConfig(AnnotationConfigurator.java:94)
at org.apache.myfaces.config.DefaultFacesConfigurationProvider.getAnnotationsFacesConfig(DefaultFacesConfigurationProvider.java:148)
at org.apache.myfaces.config.DefaultFacesConfigurationMerger.getFacesConfigData(DefaultFacesConfigurationMerger.java:91)
....
..
Caused by: java.lang.ClassNotFoundException: com.myproject.business.beans.BusinessFacade
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:198)
at java.lang.ClassLoader.loadClass(ClassLoader.java:646)
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:113)
at java.lang.ClassLoader.loadClass(ClassLoader.java:612)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:564)
at java.lang.ClassLoader.loadClass(ClassLoader.java:612)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:564)
at java.lang.ClassLoader.loadClass(ClassLoader.java:612)
... 33 more
答案 0 :(得分:0)
试试这个,看看会发生什么:
@Stateless
@LocalBean
public class BusinessFacade {
public void processEntity(final MyEntitiy entity) {
System.out.println(entity.getName());
}
}
答案 1 :(得分:0)
我认为你不能那么简单地做到这一点。这种类型的注入在同一个EAR中的EJB之间工作,但是如果我在JBoss 5.0GA中正确记得你不能将EJB注入到Servlet中等等(你应该检查我是否正确)。
您应该告诉您是否使用EAR来保存Web模块和EJB部件,或者以其他方式部署它们。
看看here它可以以某种方式帮助你。
答案 2 :(得分:0)
创建界面
@Local
public interface BusinessLocal {
void processEntity(final MyEntitiy entity);
}
在ejb中实现界面
public class BusinessFacade implements BusinessLocal {
...
}
注入界面。
@EJB
BusinessLocal businessFacade;