tags:

views:

190

answers:

2

Hi,

I have a Seam component annotated like this:

@AutoCreate
@Name("asyncServiceManager")
@Scope(ScopeType.APPLICATION)
public class AsyncServiceManager {

The classes that use it are configured like this:

@In("#{asyncServiceManager}")
private AsyncServiceManager asyncServiceManager;

When running the code, I see that the class AsyncServiceManager is instantiated everytime it is used. As I annotated the class with scope APPLICATION, this should not be the case. I need this class to be a singleton, so to speak...

Thanks!

A: 

Hi raoul,

Seam in Action book says:

Any components marked as application-scoped startup components (i.e., annotated with both @Startup and @Scope(ScopeType.APPLICATION)) are automatically instantiated by Seam at this time.

So i think @AutoCreate annotation should be removed.

Seam uses SeamListener to bootstrap @Scope(ScopeType.APPLICATION) marked components.

regards,

Arthur Ronald F D Garcia
+1  A: 

Additionally, you can simply your configuration. You don't need this:

@In("#{asyncServiceManager}")

Instead, since your variable name is identical to the component name, this is sufficient

@In
private AsyncServiceManager asyncServiceManager;

Depending on how often your component is used (this is an optimization), you can make it an event-scoped component, have it auto-created when an event is observed, and then let it get destroyed after that.

Walter

@Walter White Hi Walter, do not forget when using @In without create attribute enabled, Seam does not create a Seam component if it does not exist. But when using a Expression Language (lookup with option to create) as used by Raul @In(#{asyncServiceManager}), Seam creates one if it does not exist. (+1) for naming convention
Arthur Ronald F D Garcia