IDE:NetBeans 8.1
AP服务器:GlassFish 4.1
框架:JSF2.2 + Omnifaces 2.2
当我右键单击项目>跑 作为Pic 1
带有@Eager批注的应用程序Bean( Omnifaces )在部署Web应用程序之前启动(来自server.log),它会产生一些异常或错误:
但>服务器>右键单击GlassFish>以Pic 2
开头它没有任何例外...... lol
这是由Omnifaces的错误导致的吗?
应用程序Bean:
import org.omnifaces.cdi.Eager;
import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;
@Named
@ApplicationScoped
@Eager
public class pingController {
PingThread pingThread;
@PostConstruct
public void init() {
t = new PingThread();
t.start();
....
其他代码:
public class PingThread extends Thread {
@Override
public void run() {
while (true) {
try {
Thread.sleep(30000);
spmsEm = JPAUnit.getSPMSEntityManagerFactory().createEntityManager(); //RESOURCE_LOCAL
//PingResult is just a simple POJO
//but it will throw java.lang.IllegalStateException:
// This web container has not yet been started
PingResult result = new PingResult()
....
try {
EntityTransaction eT = spmsEm.getTransaction();
if (!eT.isActive()) {
eT.begin();
}
//An entity class
//It will throw java.lang.IllegalArgumentException:
// Object: model.entity.NePingMin[ id=null ] is not a known entity type.
NePingMin np = new NePingMin();
np.setCount(p.count);
np.setNeId(c.getControllerId());
np.setNeType("controller");
np.setSuccessCount(p.successCount);
np.setRecordTime(new Date(System.currentTimeMillis()));
spmsEm.persist(np);
eT.commit();
} catch (Exception ex) {
ex.printStackTrace();
}
.....