Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

jakarta ee - 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">
    <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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...