1

当从 BIRT 脚本数据源中的脚本运行时,Spring 无法正确加载 bean,但它自己运行正常时,我遇到了一个问题。

这是一个最小的测试用例:

春豆:

package test;
import org.springframework.stereotype.Component;

@Component
public class TestComponent { }

上下文提供者:

package test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringContextHolder {
    private static ApplicationContext ac;

    public static ApplicationContext getApplicationContext() {

        if( ac == null ) {
            ac = new ClassPathXmlApplicationContext("classpath:beans.xml");     
        }
        return ac;
    }
}

豆类.xml:

<beans .......>
<context:component-scan base-package="test"></context:component-scan>
<context:annotation-config />
</beans>

最后是测试程序,它是一个简单的 Eclipse java 项目,在其构建路径中包含所有 spring 和相关 jar 以及上面的 test.jar:

public class cltest {
    public static void main(String[] args ) throws BeansException { 
        System.out.println(test.SpringContextHolder.getApplicationContext().getBean("testComponent"));      
    }
}

该程序运行良好并提供 bean。但是当我通过在报告类路径首选项中设置它们在 BIRT 设计器(4.3.0)中运行相同的 jar 时,我得到一个异常:

发生 BIRT 异常。有关详细信息,请参阅下一个例外。Wrapped org.springframework.beans.factory.BeanDefinitionStoreException:无法读取候选组件类:URL [jar:file:/C:/Users/xxx/.m2/repository/test/test/0.0.1-SNAPSHOT/test-0.0 .1-SNAPSHOT.jar!/test/SpringContextHolder.class]; 嵌套异常是 java.lang.ArrayIndexOutOfBoundsException: 6

脚本源很简单:

importPackage(Packages.test);
ts = SpringContextHolder.getApplicationContext().getBean("testComponent");

org.springframework.asm.ClassReader异常导致readShort 违反了某些数组边界。Spring 版本为 3.2.3 RELEASE,Oracle Java 7u25,BIRT Designer 4.3.0。

谁能解释这两种运行场景之间的区别是什么?当 Eclipse 运行时加载 jar 时,可能会出现一些类加载器问题?

4

0 回答 0