alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (BaseAction.java)

This example Spring Framework source code file (BaseAction.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

action, action, baseaction, petstorefacade, petstorefacade, servlet, servletcontext, servletcontext, webapplicationcontext, webapplicationcontext

The Spring Framework BaseAction.java source code

package org.springframework.samples.jpetstore.web.struts;

import javax.servlet.ServletContext;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionServlet;

import org.springframework.samples.jpetstore.domain.logic.PetStoreFacade;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * Superclass for Struts actions in JPetStore's web tier.
 *
 * <p>Looks up the Spring WebApplicationContext via the ServletContext
 * and obtains the PetStoreFacade implementation from it, making it
 * available to subclasses via a protected getter method.
 *
 * <p>As alternative to such a base class, consider using Spring's
 * ActionSupport class for Struts, which pre-implements
 * WebApplicationContext lookup in a generic fashion.
 *
 * @author Juergen Hoeller
 * @since 30.11.2003
 * @see #getPetStore
 * @see org.springframework.web.context.support.WebApplicationContextUtils#getRequiredWebApplicationContext
 * @see org.springframework.web.struts.ActionSupport
 */
public abstract class BaseAction extends Action {

  private PetStoreFacade petStore;

	public void setServlet(ActionServlet actionServlet) {
		super.setServlet(actionServlet);
		if (actionServlet != null) {
			ServletContext servletContext = actionServlet.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
			this.petStore = (PetStoreFacade) wac.getBean("petStore");
		}
	}

	protected PetStoreFacade getPetStore() {
		return petStore;
	}

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework BaseAction.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.