0

Hibernate ロジックを含む jar (CorbeilleGestionHibernate.jar という名前) と EJB jar (CorbeilleGestionEJBImpl.jar という名前) の 2 つのモジュールのみを含む耳があります。

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
  <display-name>CorbeilleGestionEAR</display-name>
  <initialize-in-order>true</initialize-in-order>
  <module>
    <java>./CorbeilleGestionHibernate.jar</java>
  </module>
  <module>
    <ejb>CorbeilleGestionEJBImpl.jar</ejb>
  </module>
  <library-directory>lib</library-directory>
</application>

私の問題は、EJB jar で JNDI を介して Hibernate jar 内のオブジェクトにアクセスできることです。

これは、スタンドアロン モードで JBoss を起動するときにローカルでうまく機能します。しかし、JBoss をドメイン モードで起動すると、次のエラーが発生します。

08:56:43,181 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.subunit."CorbeilleGestionEAR.ear"."CorbeilleGestionEJBImpl.jar".component.StartupBean.START: org.jboss.msc.service.StartException in service jboss.deployment.subunit."CorbeilleGestionEAR.ear"."CorbeilleGestionEJBImpl.jar".component.StartupBean.START: Failed to start service
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_30]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_30]
        at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_30]
Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
        at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85)
        at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:116)
        at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:130)
        at org.jboss.as.ee.component.ComponentStartService.start(ComponentStartService.java:44)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        ... 3 more
Caused by: javax.ejb.EJBException: java.lang.IllegalStateException: javax.naming.NameNotFoundException: CorbeilleGestionHibernate -- service jboss.naming.context.java.jboss.CorbeilleGestionHibernate
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:333)
        at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:56)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
        ... 9 more
Caused by: java.lang.IllegalStateException: javax.naming.NameNotFoundException: CorbeilleGestionHibernate -- service jboss.naming.context.java.jboss.CorbeilleGestionHibernate
        at org.jboss.spring.support.SpringInjectionSupport.lookup(SpringInjectionSupport.java:180)
        at org.jboss.spring.support.SpringInjectionSupport.getObjectFromBeanFactory(SpringInjectionSupport.java:136)
        at org.jboss.spring.support.SpringInjectionSupport.injectToField(SpringInjectionSupport.java:202)
        at org.jboss.spring.support.SpringInjectionSupport.inject(SpringInjectionSupport.java:80)
        at org.jboss.spring.callback.SpringLifecycleInterceptor.postConstruct(SpringLifecycleInterceptor.java:43)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_30]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_30]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_30]
        at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_30]
        at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:118)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:112)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:112)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228)
        ... 18 more
Caused by: javax.naming.NameNotFoundException: CorbeilleGestionHibernate -- service jboss.naming.context.java.jboss.CorbeilleGestionHibernate
        at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
        at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
        at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
        at javax.naming.InitialContext.lookup(InitialContext.java:392) [rt.jar:1.6.0_30]
        at org.jboss.spring.support.SpringInjectionSupport.lookup(SpringInjectionSupport.java:173)
        ... 49 more

このエラーは、Hibernate jar が EJB jar の前にロードされていないことを明確に意味します。

このように jboss-deployment-structure.xml に依存関係を追加して、デプロイを「強制」しようとします

<sub-deployment name="CorbeilleGestionEJBImpl.jar">
    <dependencies>
        <module name="deployment.CorbeilleGestionEAR.ear.CorbeilleGestionHibernate.jar"  />
        <module name="org.jboss.as.webservices.server.integration" />
    </dependencies>
</sub-deployment>

しかし、これは何も変わらないようです。

少し調べてみたところ、Java モジュールは「initialize-in-order」属性を尊重していないようです。私が間違っている ?

私が間違っているとしたら、EJB jar の前に Hibernate jar がロードされない理由がわかりません。

私が間違っていなければ、EJB jar の前に Hibernate jar をロードするための最良の解決策は何ですか。

質問を完了するために、JNDI からロードされたオブジェクトは、Spring コンテキストで定義されたオブジェクトです。このコンテキストは、この jboss-spring.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:tx="http://www.springframework.org/schema/tx"
       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">

    <!-- Ceci permet de définir le nom JNDI -->
    <description>BeanFactory=(CorbeilleGestionHibernate)</description>

    <!-- Chargement des properties -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>file:${jboss.server.config.dir}/corbeille/corbeille.properties</value>
            </list>
        </property>
    </bean>

    <!-- Pour pouvoir récupérer l'application context facilement -->
    <bean id="hibernateApplicationContextHolder" class="com.sham.corbeille.util.SpringApplicationContextHolder" />

    <import resource="*-config.xml"/>
</beans>

すべての「*-config.xml」、つまり db-config.xml と dao-config.xml の 2 つのファイルが読み込まれていることがわかります。db-config.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:tx="http://www.springframework.org/schema/tx"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:context="http://www.springframework.org/schema/context"
       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/jee
        http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
        <property name="persistenceXmlLocation" value="classpath:META-INF/jpa-persistence.xml" />
    </bean>

    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManagerName" value="java:jboss/TransactionManager" />
        <property name="userTransactionName" value="java:jboss/UserTransaction" />
        <property name="transactionSynchronizationRegistryName" value="java:jboss/TransactionSynchronizationRegistry" />
    </bean>

    <bean id="exceptionTranslator" class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>

    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- JPA annotations bean post processor -->
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

    <!-- Exception translation bean post processor -->
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

</beans>

そしてdao-config.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:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       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">

    <!-- Configuration par annotations -->
    <context:annotation-config />
    <context:component-scan base-package="com.sham.corbeille.dao" />


    <!-- DAOs Codification -->
    <bean id="elementCodifDAO" class="com.sham.corbeille.dao.codification.ElementCodifDAOImpl" />
    <bean id="sinCodTacheDAO" class="com.sham.corbeille.dao.codification.SinCodTacheDAOImpl" />

    <!-- DAOs Client -->
    <bean id="cliClientDAO" class="com.sham.corbeille.dao.client.CliClientDAOImpl" />

    <!-- DAOs Contrat -->
    <bean id="conContratDAO" class="com.sham.corbeille.dao.contrat.ConContratDAOImpl" />

    <!-- DAOs Flux -->
    <bean id="vueMessagesCorbeilleFluxClientDAO" class="com.sham.corbeille.dao.flux.VueMessagesCorbeilleClientDAOImpl" />
    <bean id="vueMessagesCorbeilleFluxSinistreDAO" class="com.sham.corbeille.dao.flux.VueMessagesCorbeilleSinistreDAOImpl" />
    <bean id="vueMessagesCorbeilleFluxUtilisateurDAO" class="com.sham.corbeille.dao.flux.VueMessagesCorbeilleUtilisateurDAOImpl" />

    <!-- DAOs Habilitations -->
    <bean id="habUtilisateurDAO" class="com.sham.corbeille.dao.habilitations.HabUtilisateurDAOImpl" />
    <bean id="habGroupeDAO" class="com.sham.corbeille.dao.habilitations.HabGroupeDAOImpl" />
    <bean id="habFonctionDAO" class="com.sham.corbeille.dao.habilitations.HabFonctionDAOImpl" />

    <!-- DAOs Historisation -->
    <bean id="sinHistoriseEtatNotifDAO" class="com.sham.corbeille.dao.historisation.SinHistoriseEtatNotifDAOImpl" />
    <bean id="sinHistoriseEtatMessageDAO" class="com.sham.corbeille.dao.historisation.SinHistoriseEtatMessageDAOImpl" />

    <!-- DAOs Notifications -->
    <bean id="sinNotificationsDAO" class="com.sham.corbeille.dao.notifications.SinNotificationsDAOImpl" />
    <bean id="sinMessagesDAO" class="com.sham.corbeille.dao.notifications.SinMessagesDAOImpl" />
    <bean id="notificationDAO" class="com.sham.corbeille.dao.notifications.NotificationDAOImpl" />

    <!-- DAOs Personne -->
    <bean id="cliContactsDAO" class="com.sham.corbeille.dao.personne.CliContactsDAOImpl" />
    <bean id="sinActeurExterneDAO" class="com.sham.corbeille.dao.personne.SinActeurExterneDAOImpl" />

    <!-- DAOs Règlements -->
    <bean id="sinReglementDAO" class="com.sham.corbeille.dao.reglement.SinReglementDAOImpl" />

    <!-- DAOs Sinistres -->
    <bean id="sinSinistreDAO" class="com.sham.corbeille.dao.sinistres.SinSinistreDAOImpl" />
    <bean id="sinProcedureDAO" class="com.sham.corbeille.dao.sinistres.SinProcedureDAOImpl" />
    <bean id="sinVictimeDAO" class="com.sham.corbeille.dao.sinistres.SinVictimeDAOImpl" />

    <!-- DAOs Vues -->
    <bean id="vueMessagesCorbeilleDAO" class="com.sham.corbeille.dao.vues.VueMessagesCorbeilleDAOImpl" />
</beans>

これは、EJB でオブジェクトを注入するために使用されます。たとえば、タイプ CliClientDAO のオブジェクトを注入するには、次のアノテーションを使用しました

@Spring(bean = "cliClientDAO", jndiName = "CorbeilleGestionHibernate")

これらのインジェクションは、失敗した JNDI ルックアップの原因です

問題を完全に理解するためにさらに情報が必要な場合は、私に尋ねてください。

4

0 に答える 0