At first some precondition to my question, I'm using struts2 + tiles2 + toplink. NO spring at all.
The simplest scenario - is to display list of entities on the page. To optimize resolvin开发者_开发技巧g JPA's EntityManager I would like to create helper (JPAResourceBean) that implements lazy load of entity manager. For this purposes I'm going to use struts2's bean declaration:
<bean name="myfactory" class="my.model.JPAResourceBean"
scope="session" optional="false"/>
Why bean is not instantiated neither in session? (I'm using s:property just for debug)
...
<s:property value="#session.myfactory" default="buka.1"/>
...
nor in plain bean list:
...
<s:property value="#myfactory" default="buka.2"/>
...
May be the second part of question is - how to resolve this bean from java code?
I've found solution.
The matter is struts using lazy load (resolve on demand) approach to instantiate beans, so my JPAResourceBean was successfully resolved when I've accessed it over following syntax:
ActionContext.getContext().getContainer().getInstance(JPAResourceBean.class);
精彩评论