2

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

Yashar
  • 1,122
  • 2
  • 15
  • 43

1 Answers1

2

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

Community
  • 1
  • 1
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
  • you are telling me that "@Singleton" is a Scope in Weld? I didn't have "@singleton" at first, but I read that if I want to use "@startup" I have to have a singleton class with @Singleton annotaion – Yashar May 06 '13 at 14:53
  • applicationscoped is used together with 'eager' – Aksel Willgert May 06 '13 at 14:57