2

我正在使用 tomcat 在 Weld CDI 上设置应用程序,并尝试在应用程序启动时运行一个类来启动实体管理器。我收到以下异常绞盘,表明我的班级不止一个范围。

WELD-000046 At most one scope may be specified on public@ApplicationScoped @Singleton class se.raindance.squid.core.init.InitSquid

这是我的 InitSquid.Java

@ApplicationScoped
@Singleton 
@Startup
public class InitSquid {

@Inject   
private Logger log;  


@Inject
EntityManager entityManager;

/**
 *
 * @param startupEvent is sent when JSF is ready and up and running( After first
 *      request to FacesServlet).
 */
@PostConstruct
public void init() {

System.out.println("stutrup!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 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);
}
}

}

我将不胜感激有关此问题的任何提示

4

1 回答 1

2

您将 bean 指定为单例和应用程序范围。尝试解决一个。

这个问题应该提示使用哪一个:stackoverflow.com/questions/4555844/what-is-the-difference-between-applicationscoped-and-singleton-scopes-in-cdi

于 2013-05-06T14:44:30.847 回答