java - JAX_RS resources and EJB lifecycle mismatch -


jax-rs resources (class annotated @path) have per-request default lifecycle.

now ejbs have own lifecycle too,i mean when have reference ejb, reference reference of proxy object manages pool of ejbs.

how these lifecycle models coexist when ejb jax-rs resource ?

https://jersey.java.net/documentation/latest/jaxrs-resources.html

jax-rs resources managed in per-request scope default means new resource created each request.

source: https://jersey.java.net/documentation/latest/jaxrs-resources.html

jax-rs works enterprise javabeans technology (enterprise beans) , contexts , dependency injection java ee (cdi).

in general, jax-rs work enterprise beans, need annotate class of bean @path convert root resource class. can use @path annotation stateless session beans , singleton pojo beans.

jax-rs , cdi have different component models. default, jax-rs root resource classes managed in request scope, , no annotations required specifying scope. cdi managed beans annotated @requestscoped or @applicationscoped can converted jax-rs resource classes.

for web application use bean injects bean class, bean needs able hold state on duration of user's interaction application. way define state give bean scope

  • @requestscoped: user's interaction web application in single http request.

  • @sessionscoped: user's interaction web application across multiple http requests.

  • @applicationscoped: shared state across users' interactions web application.

  • @dependent: default scope if none specified; means object exists serve 1 client (bean) , has same lifecycle client (bean).

  • @conversationscoped: user's interaction servlet, including javaserver faces applications. conversation scope exists within developer-controlled boundaries extend across multiple requests long-running conversations. long-running conversations scoped particular http servlet session , may not cross session boundaries.

answering question, can contexts , dependency injection 1 inside another, each bean manage own state independently. , depending on role going perform must define scope it.

https://docs.oracle.com/javaee/7/tutorial/jaxrs-advanced004.htm https://docs.oracle.com/javaee/7/tutorial/cdi-basic008.htm#gjbbk


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -