我想创建一个 portlet(我们称之为“动作管理器”)来列出@ActionMapping
与我的动作管理器 portlet 在同一页面中的所有 portlet 的所有动作方法(使用 spring Annotation )。
我所有其他的 portlet 都ParameterHandlerMapping
用来将传入的请求映射到适当的控制器
<bean id="parameterHandlerMapping" class="org.springframework.web.portlet.handler.ParameterHandlerMapping">
<property name="defaultHandler" ref="Controller1" />
<property name="parameterName" value="control" />
<property name="parameterMap">
<map>
<entry key="1" value-ref="Controller1" />
<entry key="2" value-ref="Controller2" />
</map>
</property>
</bean>
所以我的意图是获取当前页面中的所有 portlet(我已经这样做了)并尝试parameterHandlerMapping
从每个 portlet 中获取 bean,并从那里获取它的控制器名称(Controller1
, Controller2
),我稍后将使用它来获取@ActionMapping
注释方法。
是否可以访问每个 portlet“私有”上下文并检索parameterHandlerMapping
bean?
我目前坚持这个:
PortletBag portletBag = PortletBagPool.get(portlet.getPortletId());
if (portletBag != null) {
ServletContext servletContext = portletBag.getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);
ParameterHandlerMapping parameterHandlerMapping = (ParameterHandlerMapping) ctx.getBean(ParameterHandlerMapping.class);
}
这会导致抛出异常,因为应用程序上下文中没有匹配的 bean。我试图通过 bean 的名称来获取它,结果几乎相同。
我还使用了上下文中存在的所有 bean 的列表
String beanNames[] = ctx.getBeanNamesForType(Object.class);
for (String beanName : beanNames) {
System.out.println(beanName);
}
豆子不parameterHandlerMapping
存在。
我的理解是每个 portlet 都有自己的parameterHandlerMapping
bean,所以我猜ctx
我得到的是“全局”上下文,而不是parameterHandlerMapping
定义 bean 的 portlet 自己的“私有”上下文。
如果我是正确的并且我正在获取“全局”上下文,有没有办法根据其 portletId 获取 portlet 的“私有”上下文?甚至可以做我想做的事吗?
谢谢你的帮助