I want to expose some functionality of my existing JEE7 web app using a SOAP based @WebService
. Can/should this service inject my app's CDI beans? How do @RequestScoped
, @SessionScoped
, and @ApplicationScoped
CDI beans behave, given that there's no HttpServletRequest
to identify the current session or request? ie. How do they get looked up?
My observations:
@ApplicationScoped
seems to work as expected@SessionScoped
seems to behave like request scope in that a new bean is created each time the web service is called, but it is subsequently accessible from other beans up until the service completes@RequestScoped
beans don't seem to be looked up property - eg. if my webservice injects two@RequestScoped
beans, then one of those injects the other one, a new instance is created, rather than the first one being injected
My idea was to use the @Dependent
annotation to make my session beans behave like request beans when injected into my @WebService
, but this isn't working due to the request scoped behaviour noted above. I could just use my @SessionSoped
beans as they are, but I'm concerned about the memory overhead since a new bean would be created for every web service request, and then persist for some 30 minutes or so, rather than being destroyed once the service has completed.
Any clarification or ideas would be appreciated!