为什么在JUnit测试尝试启动Seam时会抛出InstantiationException?

时间:2013-01-17 14:07:32

标签: java-ee exception seam quartz-scheduler instantiation

我试图为现有的Java EE应用程序编写集成测试,该应用程序使用Seam和Hibernate并部署到Glassfish。

然而,测试目前无法在一开始就启动Seam。这似乎是因为它无法实例化Quartz Scheduler组件 - 请参阅下面的代码。异常堆栈跟踪也在下面。

非常感谢任何帮助......

这些可能是不必要的细节,但我使用JUnit(而不是TestNG)编写了测试,如here所述。该测试扩展了AbstractSeamT​​est,并具有实例化ComponentTest的@Test方法,并覆盖here所述的testComponents。在Maven的预集成阶段使用Cargo将应用程序部署到现有的本地Glassfish实例,并使用Failsafe插件运行测试。

InitialiseQuartz类:

@Name("initialiseQuartz")
@Scope(ScopeType.APPLICATION)
@Startup
public class InitialiseQuartz {

    private QuartzTriggerHandle qth;

    @In(create=true) 
    private EmailService emailService;

    @Create
    public void startSchedule() {
        System.out.print("Schedule started");
        qth = emailService.generateDailyEmail("0 0 7 * * ?");
    }

    @Destroy
    public void stopSchedule() {
        try {
            qth.cancel();
        } catch (SchedulerException se) {

        }
    }
}

堆栈追踪:

org.jboss.seam.InstantiationException: Could not instantiate Seam component: initialiseQuartz
    at org.jboss.seam.async.AbstractDispatcher.extractAndValidateParameters(AbstractDispatcher.java:171)
    at org.jboss.seam.async.AbstractDispatcher.createTimerSchedule(AbstractDispatcher.java:113)
    at org.jboss.seam.async.ThreadPoolDispatcher.scheduleInvocation(ThreadPoolDispatcher.java:56)
    at org.jboss.seam.async.ThreadPoolDispatcher.scheduleInvocation(ThreadPoolDispatcher.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
    at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
    at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
    at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
    at org.jboss.seam.async.ThreadPoolDispatcher_$$_javassist_seam_3.scheduleInvocation(ThreadPoolDispatcher_$$_javassist_seam_3.java)
    at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:40)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
    at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
    at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
    at uk.police.kent.optica.schedule.EmailService_$$_javassist_seam_2.generateDailyEmail(EmailService_$$_javassist_seam_2.java)
    at uk.police.kent.optica.schedule.InitialiseQuartz.startSchedule(InitialiseQuartz.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
    at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
    at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
    at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
    at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
    at uk.police.kent.optica.schedule.InitialiseQuartz_$$_javassist_seam_1.startSchedule(InitialiseQuartz_$$_javassist_seam_1.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
    at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
    at org.jboss.seam.Component.callCreateMethod(Component.java:2198)
    at org.jboss.seam.Component.newInstance(Component.java:2158)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
    at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:143)
    at org.jboss.seam.init.Initialization.init(Initialization.java:744)
    at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:929)
    at com.ipl.rdhi.acceptance.RdhiAdapterIT.setUpBeforeClass(RdhiAdapterIT.java:118)

1 个答案:

答案 0 :(得分:0)

你正在使用Witch Seam版本吗?

通常在某些依赖项无法注入组件时会发生此错误。 bean EmailService在测试用例中成功启动了吗?