EJB远程处理+ Spring DI,缺少应用程序上下文(EJB Side)

时间:2017-03-29 20:07:19

标签: java-ee ejb autowired interceptor applicationcontext

所以我读了很多问题,有些答案在某些方面帮助了我,但最后我还没有看到任何解决方法。

上下文:我们在wildfly 10中部署了使用maven / spring(JPA)/ JSF创建的Web应用程序,今天我们有spring bean正在处理来自应用程序中不同页面的数据,因此当您单击&#时34;一些按钮"它调用spring bean中的一个函数,它通过spring自动装配的接口调用一些方法,应用程序上下文由web.xml和applicationContext.xml在部署应用程序时创建,所以当我们只调用一个bean时就准备好了并连接所有接口

当他们希望我们分层时,问题就出现了,所以我们必须得到2个Web服务器,一个只托管视图(我的意思是xhtmls,我们将其称为视图服务器),另一个Web服务器管理该过程数据,所以我们调用远程ejb,这个ejb在另一个服务器(我们称之为进程服务器),所以视图服务器调用进程服务器中的ejb,然后这个ejb具有所有进程查看服务器,问题是我们需要启动应用程序上下文"某处" (这可能是主要问题),因为这个ejb项目没有web.xml,到目前为止我尝试使用@Interceptors(SpringBeanAutowiringInterceptor.class) 但据我所知,如果spring的应用程序上下文已经开始或者其他东西,这将有效:

@Component
@Stateless
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class BitacoraBean implements BitacoraBeanRemote{
#Code with its @Autowired and methods (getters and setters)

}

但这会在部署时在日志中给出以下错误(编译正常,但部署失败)

Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0466: Failed to process business interfaces for EJB class class some.package.bean.BitacoraBean
    at org.jboss.as.ejb3.deployment.processors.BusinessViewAnnotationProcessor.deploy(BusinessViewAnnotationProcessor.java:93)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
    ... 5 more
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)

所以我尝试删除拦截器并在创建EJB时创建applicationContext(我不喜欢这个aproach,因为我需要启动大量的应用程序上下文,每个EJB 1个)这种方式有效,我做了一个java使用main的类并执行这个确切的代码,我可以从上下文调用任何SpringBean(在下一个代码中注释,唯一的问题是我无法从jndi到达数据源,因为它的java主类没有运行在任何服务器)

@Component
@Stateless
public class BitacoraBean implements BitacoraBeanRemote{
    public BitacoraBean(){
       /*BitacoraBean obj = (BitacoraBean) context.getBean("bitacoraBean");
        System.out.println(obj.getRfcBitacora());
        obj.setRfcBitacora("alo");
        System.out.println(obj.getRfcBitacora());*/

        ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/applicationContext.xml");

    }

但是当我在ejb中创建它并在流程服务器中运行并从视图服务器调用它时会发生这种情况:

    13:47:07,733 ERROR [org.jboss.as.ejb3.invocation] (default task-8) WFLYEJB0034: EJB Invocation failed on component BitacoraBean for method public abstract java.lang.String some.package.bean.BitacoraBeanRemote.getRfcBitacora(): javax.ejb.EJBException: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance

那是因为"失败" ejb创建,这就是它失败的原因

    Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:134)
    at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)
    at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:64)
    at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:61)
    at org.jboss.as.ejb3.pool.AbstractPool.create(AbstractPool.java:56)
    at org.jboss.as.ejb3.pool.strictmax.StrictMaxPool.get(StrictMaxPool.java:124)
    at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:47)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
    ... 46 more
Caused by: javax.ejb.EJBException: javax.enterprise.inject.CreationException
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:187)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:344)
    at org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor.processInvocation(LifecycleCMTTxInterceptor.java:68)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
    at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
    ... 55 more
Caused by: javax.enterprise.inject.CreationException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:40)
    at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:50)
    at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:90)
    at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:127)
    at org.jboss.weld.injection.ConstructorInjectionPoint$1.proceed(ConstructorInjectionPoint.java:101)
    at org.jboss.as.weld.injection.WeldManagedReferenceFactory.create(WeldManagedReferenceFactory.java:51)
    at org.jboss.as.ee.component.ComponentInstantiatorInterceptor.processInvocation(ComponentInstantiatorInterceptor.java:67)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:114)
    at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:105)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.weld.injection.WeldConstructionStartInterceptor$1.aroundConstruct(WeldConstructionStartInterceptor.java:53)
    at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallback(ConstructorInjectionPoint.java:109)
    at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:95)
    at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
    at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
    at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:116)
    at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:180)
    at org.jboss.weld.injection.producer.ejb.SessionBeanInjectionTarget.produce(SessionBeanInjectionTarget.java:126)
    at org.jboss.as.weld.injection.WeldInjectionContext.produce(WeldInjectionContext.java:46)
    at org.jboss.as.weld.injection.WeldConstructionStartInterceptor.processInvocation(WeldConstructionStartInterceptor.java:37)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:26)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:100)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
    ... 71 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/support/ClassPathXmlApplicationContext
    at some.package.bean.bitacora.BitacoraBean.<init>(BitacoraBean.java:43)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
    ... 99 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.support.ClassPathXmlApplicationContext from [Module "deployment.EjbSite.jar:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
    ... 105 more

是否可以像这样启动应用程序上下文?我试着改变&#34; \ META-INF \ applicationContext&#34;到该xml的任何可能目录。

如果它有帮助,那么是applicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:security="http://www.springframework.org/schema/security"
        xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/security 
        http://www.springframework.org/schema/security/spring-security.xsd
        http://www.springframework.org/schema/task 
        http://www.springframework.org/schema/task/spring-task.xsd">



    <context:component-scan base-package="some.package.bean.*" />
    <context:annotation-config />


    <task:annotation-driven />


    <bean id="emf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="SITE_EJB" />
    </bean>



    <bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="emf" />
    </bean>


    <bean id="myProperties"
        class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>file:/conf/ce.properties</value>
            </list>
        </property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"
        proxy-target-class="true" />



</beans>

对不起,如果时间太长,我想描述我们所做的一切: 总结:我们需要在非网络上创建一个应用程序上下文。 ejb项目能够创建一个弹簧容器,所以我们可以将(我希望)春豆注入我们的ejb,但我们失败了:&#39;(

谢谢

0 个答案:

没有答案