CDI 无法在部署到 glassfish v3.0.1 的耳朵中工作

发布于 2024-09-08 04:26:09 字数 8534 浏览 5 评论 0原文

我在使用焊接记录仪注入时遇到一些问题。

场景:我的耳朵里有ejb-jar。

这是我的 ejb bean:

@Stateless
@LocalBean
public class PartnersService {
    @Inject
    Logger log;

    @PersistenceContext(unitName = "Utopia")
    EntityManager em;

    public PartnersService() {
    }

    public OasysPartnerEntity getPartner(long id){
        return em.find(OasysPartnerEntity.class, id);
    }

    @Schedule( hour = "*", minute = "*", second = "*/15")
    public void print1Partner(){
        System.out.println("This is test");
        log.info("This is partner`s email under id 1 = ");
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void saveTempPartnerTemp(OasysPartnerTempEntity part){
        em.persist(part);
    }

}

当 print1Partner 调用时,我得到了异常:

|2010-07-02T19:25:35.003+0300|警告|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=48;_ThreadName=Thread- 1;|A 期间发生系统异常 对 EJB PartnersService 的调用 方法公共无效 ua.co.oasys.fenix.persistence.PartnersService.print1Partner() javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException:无法 创建无状态 EJB com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:448) 在 com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2467) 在 com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1860) 在 com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3962) 在 com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1667) 在 com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:98) 在 com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2485) 在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 在 java.util.concurrent.FutureTask.run(FutureTask.java:138) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:619) 引起原因:javax.ejb.EJBException: javax.ejb.CreateException:无法 创建无状态 EJB com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:720) 在 com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:200) 在 com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:443) ... 12 更多 原因: javax.ejb.CreateException:无法 创建无状态 EJB com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:528) 在 com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:90) 在 com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:718) ... 14 更多 造成原因: java.lang.NullPointerException 位于 java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768) 在 org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:1171) 在 org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:132) 在 org.glassfish.weld.services.JCDIServiceImpl._createJCDIInjectionContext(JCDIServiceImpl.java:145) 在 org.glassfish.weld.services.JCDIServiceImpl.createJCDIInjectionContext(JCDIServiceImpl.java:122) 在 com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1616) 在 com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:469) ... 16 更多 |#]

使用:ejb 3.1,glassfish 3.0.1

一些maven依赖项:

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.ejb</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>
<!-- SL4J API -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- SLF4J JDK14 Binding  -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.6.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Injectable Weld-Logger -->
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-logger</artifactId>
            <version>1.0.0-CR2</version>
            <scope>provided</scope>
        </dependency>
            <!--CDI-->
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <scope>provided</scope>
            <version>1.0-CR4</version>
        </dependency>

ear pom.xml

<dependencies>
....
<!--weld-->
        <!-- SL4J API -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.0</version>
        </dependency>

        <!-- SLF4J JDK14 Binding  -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.6.0</version>
        </dependency>

        <!-- Injectable Weld-Logger -->
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-logger</artifactId>
            <version>1.0.0-CR2</version>
        </dependency>

        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>

            <version>1.0-CR4</version>
        </dependency>


    </dependencies>
<build>
...
<configuration>
                    <modules>
...
                       <!--weld-->
                        <!-- SL4J API -->
                        <jarModule>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-api</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>

                        <!-- SLF4J JDK14 Binding  -->
                        <jarModule>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-jdk14</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>

                        <!-- Injectable Weld-Logger -->
                        <jarModule>
                            <groupId>org.jboss.weld</groupId>
                            <artifactId>weld-logger</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>
                        <jarModule>
                            <groupId>javax.enterprise</groupId>
                            <artifactId>cdi-api</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>

                    </modules>
                </configuration>
            </plugin>

        </plugins>

    </build>

META-INF/中的

bean.xml在没有ejb的ear中使用相同的配置(在战争中,但如果我在war 和weld 中使用ejb - 相同的异常)

Q1:出了什么问题?

Q2:焊接和焊接的使用规则是什么? ejb 3.1?

I have some problem with using weld logger injection.

Scenario: I have ear with ejb-jar inside.

This is my ejb bean:

@Stateless
@LocalBean
public class PartnersService {
    @Inject
    Logger log;

    @PersistenceContext(unitName = "Utopia")
    EntityManager em;

    public PartnersService() {
    }

    public OasysPartnerEntity getPartner(long id){
        return em.find(OasysPartnerEntity.class, id);
    }

    @Schedule( hour = "*", minute = "*", second = "*/15")
    public void print1Partner(){
        System.out.println("This is test");
        log.info("This is partner`s email under id 1 = ");
    }

    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void saveTempPartnerTemp(OasysPartnerTempEntity part){
        em.persist(part);
    }

}

when print1Partner called I got exception:

|2010-07-02T19:25:35.003+0300|WARNING|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=48;_ThreadName=Thread-1;|A
system exception occurred during an
invocation on EJB PartnersService
method public void
ua.co.oasys.fenix.persistence.PartnersService.print1Partner()
javax.ejb.EJBException:
javax.ejb.EJBException:
javax.ejb.CreateException: Could not
create stateless EJB at
com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:448)
at
com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2467)
at
com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1860)
at
com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:3962)
at
com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1667)
at
com.sun.ejb.containers.EJBTimerService.access$100(EJBTimerService.java:98)
at
com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2485)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at
java.util.concurrent.FutureTask.run(FutureTask.java:138)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at
java.lang.Thread.run(Thread.java:619)
Caused by: javax.ejb.EJBException:
javax.ejb.CreateException: Could not
create stateless EJB at
com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:720)
at
com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:200)
at
com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:443)
... 12 more Caused by:
javax.ejb.CreateException: Could not
create stateless EJB at
com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:528)
at
com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:90)
at
com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:718)
... 14 more Caused by:
java.lang.NullPointerException at
java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768)
at
org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:1171)
at
org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:132)
at
org.glassfish.weld.services.JCDIServiceImpl._createJCDIInjectionContext(JCDIServiceImpl.java:145)
at
org.glassfish.weld.services.JCDIServiceImpl.createJCDIInjectionContext(JCDIServiceImpl.java:122)
at
com.sun.ejb.containers.BaseContainer.createEjbInstanceAndContext(BaseContainer.java:1616)
at
com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:469)
... 16 more |#]

Using: ejb 3.1, glassfish 3.0.1

Some of maven dependency:

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.ejb</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>
<!-- SL4J API -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- SLF4J JDK14 Binding  -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.6.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Injectable Weld-Logger -->
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-logger</artifactId>
            <version>1.0.0-CR2</version>
            <scope>provided</scope>
        </dependency>
            <!--CDI-->
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <scope>provided</scope>
            <version>1.0-CR4</version>
        </dependency>

ear pom.xml

<dependencies>
....
<!--weld-->
        <!-- SL4J API -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.0</version>
        </dependency>

        <!-- SLF4J JDK14 Binding  -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.6.0</version>
        </dependency>

        <!-- Injectable Weld-Logger -->
        <dependency>
            <groupId>org.jboss.weld</groupId>
            <artifactId>weld-logger</artifactId>
            <version>1.0.0-CR2</version>
        </dependency>

        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>

            <version>1.0-CR4</version>
        </dependency>


    </dependencies>
<build>
...
<configuration>
                    <modules>
...
                       <!--weld-->
                        <!-- SL4J API -->
                        <jarModule>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-api</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>

                        <!-- SLF4J JDK14 Binding  -->
                        <jarModule>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-jdk14</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>

                        <!-- Injectable Weld-Logger -->
                        <jarModule>
                            <groupId>org.jboss.weld</groupId>
                            <artifactId>weld-logger</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>
                        <jarModule>
                            <groupId>javax.enterprise</groupId>
                            <artifactId>cdi-api</artifactId>
                            <bundleDir>lib</bundleDir>
                        </jarModule>

                    </modules>
                </configuration>
            </plugin>

        </plugins>

    </build>

bean.xml in META-INF/

Same configuration working with war in ear without ejb (in war, but if I use ejb in war and weld - same exception)

Q1: what is wrong?

Q2: what is the rules of using weld & ejb 3.1 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江挽川 2024-09-15 04:26:09

Weld Logger 和 SFLF4J 工件提供,如果您想使用它们,您需要将它们添加到您的应用程序中:

<!-- SL4J API -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.0</version>
</dependency>

<!-- SLF4J JDK14 Binding  -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-jdk14</artifactId>
  <version>1.6.0</version>
</dependency>

<!-- Injectable Weld-Logger -->
<dependency>
  <groupId>org.jboss.weld</groupId>
  <artifactId>weld-logger</artifactId>
  <version>1.0.0-CR2</version>
</dependency>

然后

import javax.inject.Inject;
import org.slf4j.Logger;

public class Foo {
    @Inject
    private Logger logger;

    public void bar() {
        logger.info("Look ma, I'm using an injected Logger!");
    }
}

我自己使用焊接记录器(使用 logback 作为绑定)并且在 GlassFish 3.0.1 下测试了您的代码,它可以正常工作。

The Weld Logger and SFLF4J artifacts are NOT provided, if you want to use them, you need to add them to your application:

<!-- SL4J API -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.0</version>
</dependency>

<!-- SLF4J JDK14 Binding  -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-jdk14</artifactId>
  <version>1.6.0</version>
</dependency>

<!-- Injectable Weld-Logger -->
<dependency>
  <groupId>org.jboss.weld</groupId>
  <artifactId>weld-logger</artifactId>
  <version>1.0.0-CR2</version>
</dependency>

Then

import javax.inject.Inject;
import org.slf4j.Logger;

public class Foo {
    @Inject
    private Logger logger;

    public void bar() {
        logger.info("Look ma, I'm using an injected Logger!");
    }
}

I'm using the weld-logger myself (with logback as binding) and tested your code under GlassFish 3.0.1, it just works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文