为什么在ORM类中具有某个类的ejb参数会导致找不到类错误?

我的Java项目在Wildfly上运行时,情况非常奇怪。

我有一个interface,例如

package com.bc.ejb;

//Some imports

@Local
public interface InventoryItemSessionLocal {
    //Some method declarations
}

及其实现

package com.bc.ejb;

//Some imports

@Stateless
public class InventoryItemSession implements InventoryItemSessionLocal {
    //Some method definitions
}

我还有一个ORM类,其定义如下:

打包com.bc.orm;

//Some imports

@SuppressWarnings("serial")
@Entity
@Table(name="custom_inventory")
@Inheritance(strategy=InheritanceType.JOINED)
public class CustomInventory extends BaseEntity implements Auditable,Serializable {
    //Some method definitions
}

它有这样一种方法:

public boolean updateImageFromBC(InventoryItemSessionLocal iSession,InventoryItem ii) {
    //Some operations
    iSession.update(ii);
}

其中InventoryItem是另一个ORM类。我所有的测试都进展顺利,无可挑剔,但是,有一个名为BreakClient的子项目只能与VPN访问一起使用,而我对此没有VPN访问,因此只能由非技术人员进行测试。 BreakClient具有BreakClientDao class,例如:

package com.bc.dao;

//Some imports

public class BreakClientDao extends BaseDao {
    //Some methods
}

BaseDao定义为

package com.bc.dao

//Some imports

public class BaseDao <T> {
    //Some method definitions
}

如果使用BreakClientSessionFactory class,看起来像

package com.bc.dao;

//Some imports

public class BreakClientSessionFactory {
    //Some method definitions
}

所有这些,我被告知BreakClient停止工作,最初我没有关于实际问题的任何信息,因此,与一个非技术人员一起,我们共同努力找到了对问题负责。我有能力和知识来处理源代码,并且checkout提交并在测试服务器上进行构建和部署,并且她具有对BreakClient的VPN访问权限。经过数小时的可能分支测试,我们找到了负责的分支。现在,负责的分支自己拥有许多提交,因此我们逐个提交地搜索,直到发现有问题的提交为止。我仍然没有足够的信息,向她询问了日志,直到我们意识到在她的计算机上BreakClient记录了错误。这是错误:

09:09:25,399 [Thread-17] ERROR breakclient.BreakClientLogin    - Caught Throwable 
java.lang.NoClassDefFoundError: com/bc/ejb/InventoryItemSessionLocal
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getDeclaredMethods(Unknown Source)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredMethodProperties(JavaXClass.java:89)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:106)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:98)
    at org.hibernate.cfg.AnnotationBinder.addElementsofAClass(AnnotationBinder.java:1023)
    at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:859)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:667)
    at org.hibernate.cfg.Annotationconfiguration.processArtifactsOfType(Annotationconfiguration.java:546)
    at org.hibernate.cfg.Annotationconfiguration.secondPassCompile(Annotationconfiguration.java:291)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1319)
    at org.hibernate.cfg.Annotationconfiguration.buildSessionFactory(Annotationconfiguration.java:867)
    at com.bc.dao.BreakClientSessionFactory.getSession(BreakClientSessionFactory.java:22)
    at com.bc.dao.BreakClientDao.getSession(BreakClientDao.java:27)
    at com.bc.dao.BreakClientDao.findByusernamePassword(BreakClientDao.java:221)
    at com.bc.breakclient.BreakClientLogin$LoginThread.run(BreakClientLogin.java:161)
Caused by: java.lang.ClassnotFoundException: com.bc.ejb.InventoryItemSessionLocal
    at java.net.URLClassLoader.findClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 17 more
09:21:45,454 [Thread-17] ERROR breakclient.BreakClientLogin    - Caught Throwable 
java.lang.NoClassDefFoundError: com/bc/ejb/InventoryItemSessionLocal
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getDeclaredMethods(Unknown Source)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredMethodProperties(JavaXClass.java:89)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:106)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:98)
    at org.hibernate.cfg.AnnotationBinder.addElementsofAClass(AnnotationBinder.java:1023)
    at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:859)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:667)
    at org.hibernate.cfg.Annotationconfiguration.processArtifactsOfType(Annotationconfiguration.java:546)
    at org.hibernate.cfg.Annotationconfiguration.secondPassCompile(Annotationconfiguration.java:291)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1319)
    at org.hibernate.cfg.Annotationconfiguration.buildSessionFactory(Annotationconfiguration.java:867)
    at com.bc.dao.BreakClientSessionFactory.getSession(BreakClientSessionFactory.java:22)
    at com.bc.dao.BreakClientDao.getSession(BreakClientDao.java:27)
    at com.bc.dao.BreakClientDao.findByusernamePassword(BreakClientDao.java:221)
    at com.bc.breakclient.BreakClientLogin$LoginThread.run(BreakClientLogin.java:161)
Caused by: java.lang.ClassnotFoundException: com.bc.ejb.InventoryItemSessionLocal
    at java.net.URLClassLoader.findClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 17 more
10:34:53,298 [Thread-17] ERROR breakclient.BreakClientLogin    - Caught Throwable 
java.lang.NoClassDefFoundError: com/bc/ejb/InventoryItemSessionLocal
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getDeclaredMethods(Unknown Source)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredMethodProperties(JavaXClass.java:89)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:106)
    at org.hibernate.annotations.common.reflection.java.JavaXClass.getDeclaredProperties(JavaXClass.java:98)
    at org.hibernate.cfg.AnnotationBinder.addElementsofAClass(AnnotationBinder.java:1023)
    at org.hibernate.cfg.AnnotationBinder.getElementsToProcess(AnnotationBinder.java:859)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:667)
    at org.hibernate.cfg.Annotationconfiguration.processArtifactsOfType(Annotationconfiguration.java:546)
    at org.hibernate.cfg.Annotationconfiguration.secondPassCompile(Annotationconfiguration.java:291)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1319)
    at org.hibernate.cfg.Annotationconfiguration.buildSessionFactory(Annotationconfiguration.java:867)
    at com.bc.dao.BreakClientSessionFactory.getSession(BreakClientSessionFactory.java:22)
    at com.bc.dao.BreakClientDao.getSession(BreakClientDao.java:27)
    at com.bc.dao.BreakClientDao.findByusernamePassword(BreakClientDao.java:221)
    at com.bc.breakclient.BreakClientLogin$LoginThread.run(BreakClientLogin.java:161)
Caused by: java.lang.ClassnotFoundException: com.bc.ejb.InventoryItemSessionLocal
    at java.net.URLClassLoader.findClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 17 more

看到这一点,我已将updateImageFromBC更改为如下形式:

public boolean updateImageFromBC(Object iSession,InventoryItem ii) {
    //Some Operations
    ((InventoryItemSessionLocal)iSession).update(ii);
}

进行此更改后,我的同事告诉我BreakClient有效。即使这已经解决了问题,我仍然认为我上面的修复很丑陋,并且想改进这段代码,所以我的问题是:

如何在不破坏BreakClient的情况下更改updateImageFromBC以使其看起来像初始实现?

请注意,由于我无法访问BreakClient才能正常工作所需的VPN,因此很难进行测试。

bduxxl 回答:为什么在ORM类中具有某个类的ejb参数会导致找不到类错误?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3102446.html

大家都在问