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 sc开发者_如何学Pythonope APPLICATION, this should not be the case. I need this class to be a singleton.
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
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,
精彩评论