开发者

CDI with ejb 3.1 , weld-logger on glassfish v3.0.1

Scenario: 1) create maven ear project, create war project inside 2) add beans.xml to war project`s WEB-INF/ 3) creat simple @Steateless bean

project - http://drp.ly/1j5C3t

ejb bean :

@Stateless
@LocalBean
public class TestEjb {


    @Inject
    Logger log;

    public TestEjb() {
    }

    @Schedule(hour = "*", minute = "*", second = "*/15")
    public void print1Partner() {
        log.info("Yrjaaaa");
        System.out.println("This is test");

    }


}

maven pom-xml of war project :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  开发者_StackOverflow  <parent>
        <artifactId>Testo</artifactId>
        <groupId>ua.co.testo</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>Testo-web</artifactId>

    <packaging>war</packaging>

     <properties>
        <project.build.sourceEncoding>
            UTF-8
        </project.build.sourceEncoding>

        <project.reporting.outputEncoding>
            UTF-8
        </project.reporting.outputEncoding>        
    </properties>



    <dependencies>

        <dependency>
            <groupId>ua.eset.oasys</groupId>
            <artifactId>utopia</artifactId>
            <version>1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>ua.eset.oasys</groupId>
            <artifactId>fenix</artifactId>
            <version>1.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>-->



        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.0.2-FCS</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.0.2-FCS</version>
            <scope>provided</scope>
        </dependency>


        <!--J2EE-->
        <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>



        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.servlet</artifactId>
            <version>3.0</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>


    </dependencies>

    <build>
        <finalName>testo-web</finalName>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <encoding>utf8</encoding>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

maven pom.xml of ear project :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>Testo</artifactId>
        <groupId>ua.co.testo</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>Testo-ear</artifactId>
    <packaging>ear</packaging>

    <properties>
        <project.build.sourceEncoding>
            UTF-8
        </project.build.sourceEncoding>

        <project.reporting.outputEncoding>
            UTF-8
        </project.reporting.outputEncoding>

    </properties>

    <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>-->

        <dependency>
            <groupId>ua.co.testo</groupId>
            <artifactId>Testo-web</artifactId>
            <version>1.0</version>
            <type>war</type>
        </dependency>


    </dependencies>

    <build>
        <finalName>testo</finalName>
        <plugins>
            <plugin>
                <!--<groupId>org.apache.maven.plugins</groupId>-->
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <modules>

                        <webModule>
                            <bundleFileName>testo-web.war</bundleFileName>
                            <groupId>ua.co.testo</groupId>
                            <artifactId>Testo-web</artifactId>
                        </webModule>



                        <!--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>

</project>

Test case 1 ( Problem ): deploying project with beans.xml give exception :

[#|2010-07-04T19:36:50.003+0300|WARNING|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=33;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB TestEjb method public void TestEjb.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 |#] [#|2010-07-04T19:36:50.004+0300|INFO|oracle-glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=33;_ThreadName=Thread-1;|EJB5119:Expunging timer ['13@@1278255602087@@server@@oasys' 'TimedObject = TestEjb' 'Application = testo' 'BEING_DELIVERED' 'PERIODIC' 'Container ID = 83771744647118848' 'Sun Jul 04 19:36:45 EEST 2010' '0' '*/15 # * # * # * # * # * # * # null # null # null # true # print1Partner # 0' ] after [2] failed deliveries|#]

[#|2010-07-04T19:37:00.000+0300|INFO|oracle-glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=33;_ThreadName=Thread-1;|This is test|#]

expecting results:

Yrjaaaa

This is test

results :

Exception

This is test


case 2: remove beans.xml

expecting results :

Yrjaaaa

This is test

results

Yrjaaaa

This is test

Goal: I want to use ejb weld(CDI) in web project inside ear archive that include some other war & ejb projects, but i don`t wond to separate my web project (war + ejb )

tools & environment : maven & ejb 3.1 & weld & glassfish 3.0.1

Q1: is this could be some kind of specific glassfish bug ? Q2: what could be a cause of problem? Q3: is there is some design for such case ?

Thank you.


Either package your EJB in a .war OR package it as ejb-jar inside a "traditional" .ear. I consider the .war packaging as a convenience for projects without strong modularization needs. But this doesn't mean the rules changed when using an .ear packaging.

In other words, I don't think you can mix both approaches and wouldn't expect a container to support it.

As a side note, I wonder why you're packaging cdi-api inside the EAR, I think the API is provided by the container.

In my opinion, you should try to keep things simple.


looks like we cant use Injection of weld logger in ejb in a case of glassfish ejb container because of it is ejb container managed bean and it dont see producer

Current design is to separate ejb and war module - at list it forks for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜