我正在尝试使用 @Singleton 和 @Startup 注释(在 tomcat 7 上运行)在 Weld CDI 中为我的应用程序定义一个启动类,但我的 PostConstruct 方法从未被调用。
这是我的启动课程:
import java.util.List;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Startup;
import javax.inject.Inject;
import javax.ejb.Singleton;
import javax.persistence.EntityManager;
import se.raindance.squid.core.domain.SquidSettings;
@Singleton
@Startup
public class InitSquid {
@Inject
private Logger log;
@Inject
EntityManager entityManager;
@PostConstruct
public void init() {
System.out.println("startup!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! InitSquid");
// Init Rainlets
InitRainlets initRainlets = new InitRainlets(entityManager);
initRainlets.init();
initSquidSettings();
}
private void initSquidSettings() {
List<SquidSettings> settingsList = (List<SquidSettings>) entityManager
.createQuery(
"select squidsettings from SquidSettings squidsettings")
.getResultList();
if (settingsList.size() == 0) {
log.info("No SquidSettings entity exists in system, creating one");
SquidSettings settings = new SquidSettings();
settings.setSubledgerRestResourceURI("http://localhost:8080/subledger-webapp/resteasy/");
entityManager.persist(settings);
}
}
}
我尝试了在这两篇文章中找到的提示 Startup POJO with WELD和Startup EJB doesn't work但都没有帮助