SessionScoped Stateful Bean and clustering problem
tomask7 Jun 14, 2012 8:03 PMHi, i've created test applicaton for clustering. It's based on "Java EE Web Project" from JBoss developer studio's JBoss Central. My modifications of the project are:
new class in controller package:
import java.util.concurrent.atomic.AtomicInteger; import javax.ejb.Stateful; import javax.enterprise.context.SessionScoped; import javax.inject.Named; import org.jboss.annotation.ejb.Clustered; @Clustered @SessionScoped @Stateful @Named("bean") public class ClusteredSessionBean { //private int atribute = 2; private AtomicInteger atribute = new AtomicInteger(2); public void increase() { //atribute++; atribute.getAndIncrement(); } public int getAtribute() { return atribute.get(); } }
web.xml in src/main/webapp/WEB-INF:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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/web-app_3_0.xsd"> <!-- Clustering --> <distributable/> </web-app>
dependencies to pom.xml:
<dependency> <groupId>jboss</groupId> <artifactId>jboss-annotations-ejb3</artifactId> <version>4.2.2.GA</version> </dependency> <dependency> <groupId>jboss</groupId> <artifactId>jbossha</artifactId> <version>4.2.2.GA</version> </dependency>
index.xhtml:
<h:form> <h:commandLink action="#{bean.increase}" value="Make it happen" /> </h:form> <h:outputLabel value="#{bean.atribute}" />
I started 2 separate instances of jboss 7.1.1 with standalone-ha.xml config... (standalone.bat -c standalone-ha.xml and standalone.bat -c standalone-ha.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=daenarys) WAR file is in standalone/deployments/clusterTest.war
problem is, when I open first instance (http://localhost:8080/clusterTest/index.jsf) it is working fine, but second instance ( http://localhost:8180/clusterTest/index.jsf) shows only ERROR 500 ServletException caused by NullPointerException from the bean...
Do you have any idea, how to set this up to work correctly?
Thanks