java 工具类调用action_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文件

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

rap.xml              struts文件

/p>

"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"

"http://struts.apache.org/dtds/struts-2.1.7.dtd">

我要执行这个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.");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值