Struts单元测试行为

时间:2015-12-18 10:10:47

标签: java eclipse hibernate maven struts2

在我启动所有项目单元测试之前,每件事情似乎都是完美的。 将我的项目从 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 tree的结果

[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传递依赖中定义的那个。我的解决方案我从我的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)