java-怎样在main方法中调用action


java中spring 框架 中的action操作(extends ActionSupport) 一般配置在struts中 通过 浏览器 通过链接形式访问 


例如:我的action和配置文件如下:

RapToDpsProjectRaw.java

package  com.action.rap;

public class RapToDpsProjectRaw extends ActionSupport {


	/**
	 * 
	 */
	private static final long serialVersionUID = 4759438181190004544L;


	private DpsProjectRapReposity dpsProjectRapReposity;


	public void setDpsProjectRapReposity(
			DpsProjectRapReposity dpsProjectRapReposity) {
		this.dpsProjectRapReposity = dpsProjectRapReposity;
	}


	public String execute() {
		System.out.println("已执行");   

		return SUCCESS;
	}


rap.xml    spring文件



		
	


	
		
	


rap.xml              struts文件




		
		
			
							
	



我要执行这个action  就会在浏览器中输入  http://localhost:8080/项目名/rap/rapToDpsProjectRaw



如果要在 main方式中 运行  主要是获取到 rapToDpsProjectRaw这个Bean  代码如下:

public static void main(final String[] args) {
        LOG.info("starting to copy record from rap system to mongo db...");
        final String[] paths = new String[] {
                "resource/spring/action/rap/rap.xml",
                "resource/struts/rap.xml", "resource/spring/common-beans.xml",
                "resource/spring/reposity/common-reposity.xml" };
        @SuppressWarnings("resource")
        final ApplicationContext context = new FileSystemXmlApplicationContext(
                paths); // ClassPathXmlApplicationContext
        final RapToDpsProjectRaw processor = (RapToDpsProjectRaw) context
                .getBean("rapToDpsProjectRaw");
        final String result = processor.execute();
        if (ActionSupport.SUCCESS.equals(result)) {
            LOG.info("Good job, copy operation succedded!");
        } else {
            LOG.warn("Oops! There's something wrong under the hook!");
        }
        LOG.info("finished copying record from rap system to mongo db.");
    }



你可能感兴趣的:(java,ssh)