1

我有一个war 文件,其中有10 个portlet。因此,在每个 acc-portlet.xml(所有 10 个 portlets.xml)中,我在其中添加了 spring injection beans 声明,并且我有 common.xml,其中包含跨 portlet 的常用 bean,并使用标签导入了这个 xml 文件每个 portlet xml 文件。

在 portlet 的控制器类中,我实现了 ApplicationContextAware。当我打印 applicationcontext 时,我实际上看到了 10 个 diff webapplicationcontext。

但根据我的理解(如果我没记错的话)应该只有 webapplicationcontext,因为这是一场单一的战争。

由于我在每个 portlet 中导入了 common.xml,spring 正在为每个 portlet 实例化单例 bean。

查看日志内容:

13:03:44,795 INFO  [XmlPortletApplicationContext:500] Refreshing PortletApplicationContext for namespace 'acc1-portlet': startup date [Thu Mar 21 13:03:44 GMT 2013]; parent: Root WebApplicationContext
13:03:44,795 INFO  [XmlBeanDefinitionReader:315] Loading XML bean definitions from PortletContext resource [/WEB-INF/acc1-portlet.xml]
13:03:44,827 INFO  [XmlBeanDefinitionReader:315] Loading XML bean definitions from PortletContext resource [/WEB-INF/common.xml]
13:03:44,858 INFO  [DefaultListableBeanFactory:581] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e894e0: defining beans [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver#0,viewResolver,messageSource,jaxbMarshaller


13:03:44,795 INFO  [XmlPortletApplicationContext:500] Refreshing PortletApplicationContext for namespace 'bcc1-portlet': startup date [Thu Mar 21 13:03:44 GMT 2013]; parent: Root WebApplicationContext
13:03:44,795 INFO  [XmlBeanDefinitionReader:315] Loading XML bean definitions from PortletContext resource [/WEB-INF/bcc1-portlet.xml]
13:03:44,827 INFO  [XmlBeanDefinitionReader:315] Loading XML bean definitions from PortletContext resource [/WEB-INF/common.xml]
13:03:44,858 INFO  [DefaultListableBeanFactory:581] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e894e0: defining beans [org.springframework.web.servlet.handler.SimpleMappingExceptionResolver#0,viewResolver,messageSource,jaxbMarshaller.

我怎样才能使 common.xml 内容只加载一次并有一个单一的 spring applicationcontext?

4

0 回答 0