Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Gary Pinkham
Multiple Spring Portlets Shared beans?
29 marzo 2013 15.14
Risposta

Gary Pinkham

Punteggio: New Member

Messaggi: 5

Data di Iscrizione: 29 marzo 2013

Messaggi recenti

Curious if there are any examples of multiple Spring MVC portlets but with shared beans using component scan and autowiring? I currently have two portlets in a single war and the component scans for the service beans is in both portlets portletContext file.. I had thought that the appContext referenced in the web.xml was the parent context of the portletContexts and therefore if I defined the component scan in that file those beans could be used for autowiring in the controllers defined in the portletContexts.. This didn't work.. wondering if I need to define all the connections manually and not use component scan and autowiring.. or maybe it's just not possible..

thanks in advance!
Gary
David H Nebinger
RE: Multiple Spring Portlets Shared beans?
30 marzo 2013 6.05
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 10342

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

Each portlet has a portlet context, even though they are in the same war file.

Try using a spring context loader listener at the servlet level to instantiate your beans.
Gary Pinkham
RE: Multiple Spring Portlets Shared beans?
30 marzo 2013 6.12
Risposta

Gary Pinkham

Punteggio: New Member

Messaggi: 5

Data di Iscrizione: 29 marzo 2013

Messaggi recenti

Thanks David. . I did actually have the app context defined in the context listener in the web.xml.. let me provide some more details..

web.xml -> ContextLoaderListener -> main application context xml file.. defines services via component scan for @service

portlet.xml -> multiple DispatcherPortlets -> each pointing to it's own portlet context xml file.. defines the controller and view resolver (have moved that up to with no luck).. The controller is using autowiring to find it's services..

This works fine with the @service component scan is in each portlet context file.. but I have the service instances multiple times.. when I moved the component scan up to the app context the autowiring breaks..

question. should I "import" the application context into the portlet context via:
1<import resource="classpath:META-INF/spring/applicationContext.xml" />
Gary Pinkham
RE: Multiple Spring Portlets Shared beans?
31 marzo 2013 4.32
Risposta

Gary Pinkham

Punteggio: New Member

Messaggi: 5

Data di Iscrizione: 29 marzo 2013

Messaggi recenti

ok.. not sure what I had done wrong the first time but it worked this time.. I did notice if I redeploy my war into the liferay deploy folder it fails to autowire. . but if I stop the server.. delete the app from the webapps folder and redeploy, restart (twice) the autowiring works perfectly...
Gary Pinkham
RE: Multiple Spring Portlets Shared beans?
31 marzo 2013 18.01
Risposta

Gary Pinkham

Punteggio: New Member

Messaggi: 5

Data di Iscrizione: 29 marzo 2013

Messaggi recenti

a coworker discovered this (nice catch Thomas).. http://issues.liferay.com/browse/LPS-29103 this is what was causing the issues we were having with the Spring MVC Portlets and our shared beans..

Thanks
Pritesh Shah
RE: Multiple Spring Portlets Shared beans?
6 novembre 2013 23.18
Risposta

Pritesh Shah

Punteggio: Junior Member

Messaggi: 31

Data di Iscrizione: 4 luglio 2012

Messaggi recenti

Hello,

I am facing the same issue.
I have bean defined in context file which is loaded under ContextLoaderListener in web.xml by specifying contextConfigLocation. This bean is reference in portlet controllers and some servlets.

As portlet context is loaded first in 6.1.2 bean defined in context file which would be loading in ContextLoaderListener is not yet loaded so I am not able to initialize controller having those bean references.

I checked the http://issues.liferay.com/browse/LPS-29103 and it seems to be the same issue.

Can anyone please provide any workaround for the same?
I am using LR v6.1.20EE

Thanks in advance!!!