本文介绍了未创建struts 2 bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我的问题是使用struts2 + tile2 + toplink.根本没有春天.

At first some precondition to my question, I'm using struts2 + tiles2 + toplink. NO spring at all.

最简单的方案-在页面上显示实体列表.为了优化解析JPA的EntityManager,我想创建实现实体管理器延迟加载的助手(JPAResourceBean).为此,我将使用struts2的bean声明:

The simplest scenario - is to display list of entities on the page. To optimize resolving 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"/>

为什么在会话中都没有实例化bean? (我仅将s:property用于调试)

Why bean is not instantiated neither in session? (I'm using s:property just for debug)

...
<s:property value="#session.myfactory" default="buka.1"/>
...

在普通豆列表中也不是

...
<s:property value="#myfactory" default="buka.2"/>
...

问题的第二部分可能是-如何从Java代码中解析此bean?

May be the second part of question is - how to resolve this bean from java code?

推荐答案

我找到了解决方案.

问题是使用延迟加载(按需解决)方法实例化bean的struts,因此,当我通过以下语法访问它时,我的JPAResourceBean已成功解决:

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);

这篇关于未创建struts 2 bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 07:09