I was hoping for a more detailed answer than what Noel gave. Maybe there is some best practice to this? Here is my current solution:
Give the xml file locations as a init parameter to my portlet.
My init method looks something like this
@Override
public void init(PortletConfig config) throws PortletException {
super.init(config);
String configLocations = config.getInitParameter("contextConfigLocation");
ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext();
springContext.setConfigLocation(configLocations);
springContext.refresh();
config.getPortletContext().setAttribute(APPLICATION_CONTEXT_ATTRIBUTE, springContext);
}
Now I can access my applicationContext through PortletContext every time I need.
(ApplicationContext) portalContext.getAttribute(APPLICATION_CONTEXT_ATTRIBUTE);
APPLICATION_CONTEXT_ATTRIBUTE is just string constant that I made up. I'm still open for better solutions.