What is the difference between @ApplicationScoped and @Singleton scopes in CDI?

amorfis picture amorfis · Dec 29, 2010 · Viewed 72.9k times · Source

In CDI there is the @ApplicationScoped and the (javax.inject) @Singleton pseudo-scope. What is the difference between them? Besides the fact that @ApplicationScoped is proxied, and @Singleton is not.

Can I just change my @Singleton bean to @ApplicationScoped? Can @ApplicationScoped bean have two (or more) instances?

Answer

Bozho picture Bozho · Dec 29, 2010

@Singleton is not part of the CDI specification. It is part of EJB and javax.inject (JSR-330). It is not mentioned in the spec what is its behaviour, so you can only rely on what's written in the Weld documentation.