Spring and Portlet 2.0

Hi I am using spring and I am moving on Portlet 2.0. I have problem how to get services to application class. I am new to spring and portlets overall. Here is my configuration from spring.


<bean id="'applicationBean" class="com.example.demo.DemoApplication" scope="prototype">
		<property name="demoService" ref="demoBean"></property>
</bean>

<bean id="demoBean" class="service.impl.DemoServiceImpl"></bean>

When I was using portlet 1.0, I just called application url in Portlet.xml. But now I have to call
the DemoApplication class.


<portlet>
    <portlet-name>demo-portlet</portlet-name>
    <display-name>Demo Portlet </display-name>
    
<!-- Map portlet to a servlet. -->
    <portlet-class>com.vaadin.terminal.gwt.server.ApplicationPortlet2</portlet-class>
    
    <init-param>
      <name>application</name>
      <value>com.example.demo.DemoApplication</value>
    </init-param>
    
    <init-param>
		    <name>widgetset</name>
		    <value>com.vaadin.portal.gwt.PortalDefaultWidgetSet</value>
	</init-param>

Is there good solution where I could set my services in spring config, without that autowire?

Thanks for your help
Pete

Hello Petteri,

Maybe you could subclass AbstractApplicationPortlet and look up the application instance from Spring?

-Petter-

I used this kind of solution for the problem

context = PortletApplicationContextUtils.getRequiredWebApplicationContext(portletContext);
context.getBean(“myBeanNameInSpring”);

Hideho,

old thread, but relevant for my specific situation.

@Petteri: How do you get your ‘portletContext’ needed as a parameter in the “PortletApplicationContextUtils.getRequiredWebApplicationContext(portletContext)” call?

The reason I’m asking is that I have an issue where the context I’m getting when I do a ‘getContext’ in my application, is not of type PortletApplicationContext, nor PortletApplicationContext2. It is in fact of type ‘WebApplicationContext’ which is really REALLY weird and very disturbing to me…

so ehm, any idea?

P.