Accessing other spring defined beans in the portle

2019-07-22 08:14发布

问题:

Context: Using maven 3,spring portlet mvc 3.1

Background:

  • I have built a portlet using spring portlet mvc 3.1.
  • This portlet uses the spring portlet mvc defined Dispatched and is defined accordingly in the -portlet.xml.
  • The dispatcher portlet is configured to pass requests to the myController (POJO with annotation of @Controller)
  • I also have a service project (jar) which defines a business service to be used by myController. This service has its own spring file and defines the bean 'myService'
  • I want to inject myService into myController using a predefined bean, so I have defined ContextLoaderListener in the web.xml of my portlet project

Problem: I have tried both ways of trying to inject myService into myController i.e. using annotations and xml defined beans, but the portlet fails on deployment with an error that myService bean could not be found (or when using annotations no matching bean with class type found)

Note: I can see some logs on undeploy that the beans are available, but I think the issue is with PortletApplicationContext (as defined by -portlet.xml) is loading before the root Web ApplicationContext (as defined applicationContext through default usage in web.xml)

Note2: If I put the import for spring file defining 'myService' bean into the -portlet.xml, then it works.

Would appreciate any help in sorting this out.