Spring ActionFactory

public class ActionFactory {

	public static Action getAction(String actionName) {

		Properties cfgFile = new Properties();
		try {
			cfgFile.load(new FileInputStream(ActionFactory.class.getResource(
					"springbeans.properties").getFile()));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		String className = cfgFile.getProperty(actionName);
		Action action = null;
		try {
			action = (Action) Class.forName(className).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return action;
	}
}

 

你可能感兴趣的:(spring)