我有兩個模塊WAR和Business。無法找到EJB無狀態Bean。注入失敗
我嘗試在Web模塊中注入一個無狀態bean。但無狀態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
我認爲你需要在業務模塊和戰爭之間添加項目依賴關係。 –
它們是否打包在同一個EAR中? – zeller
@SaiYeYanNaingAye我在Pom.xml中定義了依賴關係。 – Kayser