2 Replies Latest reply on Oct 13, 2011 4:49 AM by Tim Snyder

    Weld creating multiple instances of @SessionScoped beans

    Tim Snyder Newbie

      Using JbossAS 7.0.2 with CDI. The problem is that for every reference from an xhtml file to a @SessionScoped @Named bean a new instance of the bean is being created. I have run it within the debugger and watched the object ids increment. In moving to a new page, new instances are also created. I created my POM from the jboss 7 login example, (after finding out an EAR flat would not work), and added from there. The POM is :

       

      <?xml version="1.0"?>

      <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/maven-v4_0_0.xsd">

         <modelVersion>4.0.0</modelVersion>

       

         <groupId>com.zensa.vault</groupId>

         <artifactId>vault</artifactId>

         <version>0.0.1.Snapshot</version>

         <packaging>war</packaging>

         <name>Vault</name>

       

       

        <properties>

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

      <!--

          <jsf.version>2.0.3-b05</jsf.version>

      -->

           <el.impl.version>2.2.1-b04</el.impl.version>

       

          <itext.version>2.0.4</itext.version>

          <fileupload.version>1.2.1</fileupload.version>

          <common.io.version>1.4</common.io.version>

          <jstl.version>1.2</jstl.version>

          <slf4j.version>1.6.1</slf4j.version>

          <richfaces.version>4.0.0.Final</richfaces.version>

      <!--

          <jboss.600.home>/Users/tim/Servers/jboss.6.1.0.Final</jboss.600.home>

          <jboss.600.server>default</jboss.600.server>

      -->

        </properties>

       

         <!-- Include the JBoss Maven repository so we can access JBoss artifacts -->

         <repositories>

            <repository>

               <id>jboss-public-repository</id>

               <name>JBoss Repository</name>

               <url>https://repository.jboss.org/nexus/content/groups/public</url>

               <releases>

                  <enabled>true</enabled>

               </releases>

               <snapshots>

                  <enabled>false</enabled>

               </snapshots>

            </repository>

         </repositories>

       

         <pluginRepositories>

            <pluginRepository>

               <id>jboss-public-repository</id>

               <name>JBoss Repository</name>

               <url>https://repository.jboss.org/nexus/content/groups/public</url>

               <releases>

                  <enabled>true</enabled>

               </releases>

               <snapshots>

                  <enabled>false</enabled>

               </snapshots>

            </pluginRepository>

         </pluginRepositories>

       

         <dependencyManagement>

            <dependencies>

                <dependency>

                  <groupId>org.jboss.spec</groupId>

                  <artifactId>jboss-javaee-web-6.0</artifactId>

                  <version>2.0.0.Final</version>

                  <type>pom</type>

                  <scope>import</scope>

               </dependency>

            </dependencies>

         </dependencyManagement>

       

         <dependencies>

           <dependency>

             <groupId>javax.enterprise</groupId>

             <artifactId>cdi-api</artifactId>

             <scope>provided</scope>

           </dependency>

       

           <dependency>

             <groupId>org.jboss.spec.javax.annotation</groupId>

             <artifactId>jboss-annotations-api_1.1_spec</artifactId>

             <scope>provided</scope>

           </dependency>

       

           <dependency>

             <groupId>org.jboss.spec.javax.faces</groupId>

             <artifactId>jboss-jsf-api_2.0_spec</artifactId>

             <scope>provided</scope>

           </dependency>

       

           <dependency>

             <groupId>org.hibernate.javax.persistence</groupId>

             <artifactId>hibernate-jpa-2.0-api</artifactId>

             <scope>provided</scope>

           </dependency>

       

           <dependency>

             <groupId>org.jboss.spec.javax.transaction</groupId>

             <artifactId>jboss-transaction-api_1.1_spec</artifactId>

             <scope>provided</scope>

           </dependency>

       

           <dependency>

             <groupId>org.jboss.spec.javax.ejb</groupId>

             <artifactId>jboss-ejb-api_3.1_spec</artifactId>

             <scope>provided</scope>

           </dependency>

       

          <dependency>

            <groupId>javax.mail</groupId>

            <artifactId>mail</artifactId>

            <scope>provided</scope>

          </dependency>

           

          <dependency>

            <groupId>com.zensa.vault</groupId>

            <artifactId>vault-core</artifactId>

            <version>0.0.1-SNAPSHOT</version>

          </dependency>

       

          <dependency>

            <groupId>org.apache.activemq</groupId>

            <artifactId>activemq-all</artifactId>

            <version>5.5.1-fuse-00-06</version>

          </dependency>

       

          <dependency>

            <groupId>org.eclipse.emf</groupId>

            <artifactId>ecore</artifactId>

            <version>2.6.1</version>

          </dependency>

       

          <dependency>

            <groupId>org.eclipse.emf</groupId>

            <artifactId>common</artifactId>

            <version>2.6.0</version>

          </dependency>

       

          <dependency>

            <groupId>org.eclipse.emf</groupId>

            <artifactId>ecore.xmi</artifactId>

            <version>2.5.0</version>

          </dependency>

       

          <dependency>

            <groupId>org.apache.commons</groupId>

            <artifactId>commons-lang</artifactId>

            <version>2.4</version>

          </dependency>

         

          <dependency>

            <groupId>org.apache.commons</groupId>

            <artifactId>commons-pool</artifactId>

            <version>1.5.3</version>

          </dependency>

       

          <dependency>

            <groupId>com.ibm.websphere</groupId>

            <artifactId>dynacache</artifactId>

            <version>2006</version>

          </dependency>

       

          <dependency>

            <groupId>org.richfaces.ui</groupId>

            <artifactId>richfaces-components-api</artifactId>

            <version>${richfaces.version}</version>

          </dependency>

       

          <dependency>

            <groupId>org.richfaces.ui</groupId>

            <artifactId>richfaces-components-ui</artifactId>

            <version>${richfaces.version}</version>

            <exclusions>

              <exclusion>

                <groupId>com.google.guava</groupId>

                <artifactId>guava</artifactId>

              </exclusion>

            </exclusions>

          </dependency>

         

          <dependency>

            <groupId>org.richfaces.core</groupId>

            <artifactId>richfaces-core-impl</artifactId>

            <version>${richfaces.version}</version>

            <exclusions>

              <exclusion>

                <groupId>com.google.guava</groupId>

                <artifactId>guava</artifactId>

              </exclusion>

            </exclusions>

          </dependency>

       

          <dependency>

            <groupId>com.google.guava</groupId>

            <artifactId>guava</artifactId>

            <version>r09</version>

            <type>jar</type>

            <scope>compile</scope>

          </dependency>   

       

      <!--

          <dependency>

            <groupId>org.glassfish.web</groupId>

            <artifactId>el-impl</artifactId>

            <version>${el.impl.version}</version>

            <exclusions>

              <exclusion>

                <groupId>javax.el</groupId>

                <artifactId>el-api</artifactId>

              </exclusion>

            </exclusions>

          </dependency>

       

          <dependency>

            <groupId>jstl</groupId>

            <artifactId>jstl</artifactId>

            <version>${jstl.version}</version>

            <scope>provided</scope>

          </dependency>

      -->

       

          <dependency>

            <groupId>javax.servlet</groupId>

            <artifactId>servlet-api</artifactId>

            <version>2.5</version>

            <scope>provided</scope>

          </dependency>

       

       

          <dependency>

            <groupId>commons-fileupload</groupId>

            <artifactId>commons-fileupload</artifactId>

            <version>${fileupload.version}</version>

            <scope>provided</scope>

          </dependency>

       

          <dependency>

            <groupId>commons-io</groupId>

            <artifactId>commons-io</artifactId>

            <version>${common.io.version}</version>

            <scope>provided</scope>

          </dependency>

       

          <dependency>

            <groupId>commons-codec</groupId>

            <artifactId>commons-codec</artifactId>

            <version>1.2</version>

          </dependency>

       

          <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-simple</artifactId>

            <version>1.5.10</version>

          </dependency>

       

          <dependency>

            <groupId>org.slf4j</groupId>

            <artifactId>slf4j-api</artifactId>

            <version>1.5.10</version>

          </dependency>

         

        </dependencies>

       

         <build>

            <finalName>Vault</finalName>

            <plugins>

               <plugin>

                  <artifactId>maven-war-plugin</artifactId>

                  <version>2.1.1</version>

                  <configuration>

                     <!-- Java EE 6 doesn't require web.xml, Maven needs to catch

                        up! -->

                     <failOnMissingWebXml>false</failOnMissingWebXml>

                  </configuration>

               </plugin>

               <!-- JBoss AS plugin to deploy war -->

               <plugin>

                  <groupId>org.jboss.as.plugins</groupId>

                  <artifactId>jboss-as-maven-plugin</artifactId>

                  <version>7.0.0.Final</version>

               </plugin>

               <!-- Compiler plugin enforces Java 1.6 compatibility and activates

                  annotation processors -->

               <plugin>

                  <artifactId>maven-compiler-plugin</artifactId>

                  <version>2.3.1</version>

                  <configuration>

                     <source>1.6</source>

                     <target>1.6</target>

                  </configuration>

               </plugin>

            </plugins>

         </build>

       

      </project>