【问题标题】:Struts unit test behaviorStruts 单元测试行为
【发布时间】:2015-12-18 10:10:47
【问题描述】:

在我启动所有项目单元测试之前,一切似乎都很完美。 将我的项目从 2.2.1.1 升级到 struts 2.3.15.1 后,出现以下错误:

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
    at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
    at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)

问题实际上是struts 2.3.15.1 使用了另一个版本的asm 框架,它不同于以前的版本。这里是 mvn 树的结果

[INFO] |  +- com.holly.project:ejbMex:ejb-client:client:8.13.0-SNAPSHOT:compile
[INFO] |  |  +- com.holly.project:commons-care:jar:8.13.0-SNAPSHOT:compile
[INFO] |  |  |  +- org.hibernate:hibernate:jar:3.2.5.ga:compile
[INFO] |  |  |  |  +- net.sf.ehcache:ehcache:jar:1.2.3:compile
[INFO] |  |  |  |  +- asm:asm-attrs:jar:1.5.3:compile
[INFO] |  |  |  |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  |  |  |  \- cglib:cglib:jar:2.1_3:compile

+- org.apache.struts:struts2-core:jar:2.3.15.1:compile
[INFO] |  +- org.apache.struts.xwork:xwork-core:jar:2.3.15.1:compile
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] |  |  +- asm:asm:jar:3.3:compile
[INFO] |  |  \- asm:asm-commons:jar:3.3:compile
[INFO] |  |     \- asm:asm-tree:jar:3.3:compile
[INFO] |  +- org.freemarker:freemarker:jar:2.3.19:compile
[INFO] |  +- ognl:ognl:jar:3.0.6:compile
[INFO] |  |  \- javassist:javassist:jar:3.11.0.GA:compile
[INFO] |  +- commons-fileupload:commons-fileupload:jar:1.3:compile
[INFO] |  \- commons-io:commons-io:jar:1.4:compile

如您所见,struts 使用 asm 3.3,它不是在 hibernate transitive dependency 中定义的。我的解决方案我从我的 struts 声明中排除了这种依赖关系

<dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.3.15.1</version>
            <exclusions>
                <exclusion>
                    <groupId>asm</groupId>
                    <artifactId>asm</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

问题已解决,但我现在遇到了新的错误,我不知道是什么。?

java.lang.VerifyError: Instruction type does not match stack map in method holly.commons.ihm.utils.ServiceLocator.getMePage()Lcom.holly.project/service/IMEPage; at offset 959
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at org.easymock.internal.ObjectMethodsFilter.<init>(ObjectMethodsFilter.java:55)
    at org.easymock.internal.MocksControl.createMock(MocksControl.java:59)
    at org.easymock.EasyMock.createMock(EasyMock.java:103)
    at holly.commons.ihm.remote.TemplMePageTest.<init>(TemplMePageTest.java:63)

【问题讨论】:

  • 正如您提到的,当一个类依赖于其他类并且该类在编译后发生不兼容的更改时,就会出现此问题。

标签: java eclipse hibernate maven struts2


【解决方案1】:

@AleksandrM 一如既往,感谢您的合作 :) 事实上,在从 struts 核心传递依赖项中排除 ognl 工件后,问题就得到了解决。似乎用于编译所有单元测试的版本与用于运行这些单元测试的版本不同。

<dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.3.15.1</version>
            <exclusions>
                <exclusion>
                    <groupId>asm</groupId>
                    <artifactId>asm</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>ognl</groupId>
                    <artifactId>ognl</artifactId>
                </exclusion>            
            </exclusions>       
        </dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多