views:

160

answers:

1

Is it possible to do dependency injection using spring into a jsr168 Portlet?

+2  A: 

Yes - have a look at the portlet chapter in the spring reference.

Notice that you need to implement the special spring portlet controller interface, and not the standard portlet. These controller as well as the injected beans should be in the spring context file specified in the contextConfigLocation parameter. I guess that the usual applicationContext.xml will work as well (if you register the spring servlet context listener)

David Rabinowitz
great thanks, I'll have a read and see how i get on
combi001
ok cool so JSR168's portlet.xml file works kinda like a regular spring applicationContext.xml. My question however is, do i need to create a separate xml file containing the name of the Portlet class i want to inject or can i do it through the Portlet.xml file? Also, would there be a conflict if this class is created as a bean in both xml files? Thanks
combi001
I've added some info. notice that the portlet.xml is not a spring context file. You define in it a spring implementation of a portlet, which knows to delegate the requests to other beans (this is similar to web.xml and the DispatcherServlet)
David Rabinowitz