Question

I am setting up an application on Weld CDI with tomcat and trying to run a class in application startup to initiate the entity manager. I am getting the following exception winch indicate I have more than one scope for my class.

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

here is my 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);
}
}

}

I will appreciate any hint on this problem

Was it helpful?

Solution

you are specifying the bean to be both singleton and applicationscoped. try settling with one.

this question should give a hint on which one to use: stackoverflow.com/questions/4555844/what-is-the-difference-between-applicationscoped-and-singleton-scopes-in-cdi

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top