当我运行应用程序时,计数器按预期递增,但如何将bean从Web模块移动到ejb模块?
一般结构:
NetBeansProjects/EntAppWeb/
├── build.xml
├── EntAppWeb-ejb
│ ├── build.xml
│ ├── nbproject
│ │ ├── ant-deploy.xml
│ │ ├── build-impl.xml
│ │ ├── genfiles.properties
│ │ ├── private
│ │ │ ├── private.properties
│ │ │ └── private.xml
│ │ ├── project.properties
│ │ └── project.xml
│ └── src
│ ├── conf
│ │ └── MANIFEST.MF
│ └── java
├── EntAppWeb-war
│ ├── build.xml
│ ├── nbproject
│ │ ├── ant-deploy.xml
│ │ ├── build-impl.xml
│ │ ├── genfiles.properties
│ │ ├── private
│ │ │ ├── private.properties
│ │ │ └── private.xml
│ │ ├── project.properties
│ │ └── project.xml
│ ├── src
│ │ ├── conf
│ │ │ └── MANIFEST.MF
│ │ └── java
│ │ └── dur
│ │ ├── database
│ │ │ ├── Clients.java
│ │ │ ├── ClientsQueryBean.java
│ │ │ └── QueryBeanWithEntityManager.java
│ │ └── facelets
│ │ ├── DirectoryBean.java
│ │ ├── Hello.java
│ │ └── MyQueueBean.java
│ └── web
│ ├── eagle.xhtml
│ ├── falcon.xhtml
│ ├── index.xhtml
│ ├── menu.xhtml
│ ├── next.xhtml
│ ├── parrot.xhtml
│ ├── template.xhtml
│ └── WEB-INF
│ └── web.xml
├── LICENSE
├── nbproject
│ ├── ant-deploy.xml
│ ├── build-impl.xml
│ ├── genfiles.properties
│ ├── private
│ │ └── private.properties
│ ├── project.properties
│ └── project.xml
├── README.md
└── src
└── conf
└── MANIFEST.MF
EAR
如何构建:
thufir@dur:~$
thufir@dur:~$ jar -tf NetBeansProjects/EntAppWeb/dist/EntAppWeb.ear
META-INF/
META-INF/MANIFEST.MF
lib/
EntAppWeb-ejb.jar
EntAppWeb-war.war
lib/javaee-api-7.0.jar
thufir@dur:~$
小脸:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head></h:head>
<h:body>
This and everything before will be ignored
<ui:composition template="template.xhtml">
<ui:define name="navigation">
<ui:include src="menu.xhtml"/>
</ui:define>
<ui:define name="main">
<h1>bird</h1>
next #{myQueueBean.next}
</ui:define>
</ui:composition>
This and everything after will be ignored
</h:body>
</html>
和bean:
package dur.facelets;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.inject.Named;
import javax.ejb.Singleton;
import javax.enterprise.context.ApplicationScoped;
//import javax.inject.Singleton;
@Named
@ApplicationScoped
@Singleton
public class MyQueueBean implements Serializable {
private static final long serialVersionUID = 1L;
private final Logger log = Logger.getLogger(MyQueueBean.class.getName());
private int next = 1001;
public MyQueueBean() {
}
public int getNext() {
log.info("next\t" + next);
return next++;
}
}
完整来源: