BOS:关于服务器地址遗留问题解决

关于bos项目服务器地址问题,原先用的是常量类的方式,代码如下
/**
 * 常量工具类
 * 
 * @author itcast
 *
 */
public class Constants {

    public static final String BOS_MANAGEMENT_HOST = "http://localhost:9001";
    public static final String CRM_MANAGEMENT_HOST = "http://localhost:9002";
    public static final String BOS_FORE_HOST = "http://localhost:9003";
    public static final String BOS_SMS_HOST = "http://localhost:9004";
    public static final String BOS_MAIL_HOST = "http://localhost:9005";

    private static final String BOS_MANAGEMENT_CONTEXT = "/bos_management";
    private static final String CRM_MANAGEMENT_CONTEXT = "/crm_management";
    private static final String BOS_FORE_CONTEXT = "/bos_fore";
    private static final String BOS_SMS_CONTEXT = "/bos_sms";
    private static final String BOS_MAIL_CONTEXT = "/bos_mail";

    public static final String BOS_MANAGEMENT_URL = BOS_MANAGEMENT_HOST + BOS_MANAGEMENT_CONTEXT;
    public static final String CRM_MANAGEMENT_URL = CRM_MANAGEMENT_HOST + CRM_MANAGEMENT_CONTEXT;
    public static final String BOS_FORE_URL = BOS_FORE_HOST + BOS_FORE_CONTEXT;
    public static final String BOS_SMS_URL = BOS_SMS_HOST + BOS_SMS_CONTEXT;
    public static final String BOS_MAIL_URL = BOS_MAIL_HOST + BOS_MAIL_CONTEXT;
}
如果遇到服务器地址变更很不利于后期代码的维护,所以将常量类抽取成properties配置文件,书写规范,=前后最好不要有空格,
BOS_MANAGEMENT_HOST=http://localhost:9001
CRM_MANAGEMENT_HOST=http://localhost:9002
BOS_FORE_HOST=http://localhost:9003
BOS_SMS_HOST=http://localhost:9004
BOS_MAIL_HOST=http://localhost:9005
BOS_MANAGEMENT_CONTEXT=/bos_management
CRM_MANAGEMENT_CONTEXT=/crm_management
BOS_FORE_CONTEXT=/bos_fore
BOS_SMS_CONTEXT=/bos_sms
BOS_MAIL_CONTEXT=/bos_mail
BOS_MANAGEMENT_URL=http://localhost:9001/bos_management
CRM_MANAGEMENT_URL=http://localhost:9002/crm_management
BOS_FORE_URL=http://localhost:9003/bos_fore
BOS_SMS_URL=http://localhost:9004/bos_sms
BOS_MAIL_URL=http://localhost:9005/bos_mail
将文件名为address.properties配置在当前工程下的applicationContext.xml里面
<!-- 加载properties文件 -->
<context:property-placeholder location="classpath:config.properties"  
ignore-unresolvable="true"/>
    <context:property-placeholder location="classpath:address.properties"  
    ignore-unresolvable="true"/>
这里需要注意的是当引入多个properties文件时,需要加上 ignore-unresolvable=”true” 这个参数,否则会报异常
哪里需要调用url路径就在哪里使用@value注解注入,这个properties配置文件一定是在调用url路径下的工程里面,此文件不能跨工程访问
@Value("${BOS_MANAGEMENT_URL}")  private String BOS_MANAGEMENT_URL;
@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class PromotionAction extends BaseAction<Promotion> {
    // 注入properties url路径
    @Value("${BOS_MANAGEMENT_URL}")
    private String BOS_MANAGEMENT_URL;

    @Action(value = "promotion_pageQuery", results = { @Result(name = "success", type = "json") })
    public String pageQuery() {

        // 基于WebService 获取 bos_management的 活动列表 数据信息
        PageBean<Promotion> pageBean = WebClient.create(
                BOS_MANAGEMENT_URL + "/services/promotionService/pageQuery?page=" + page + "&rows=" + rows)
                .accept(MediaType.APPLICATION_JSON).get(PageBean.class);

        ActionContext.getContext().getValueStack().push(pageBean);

        return SUCCESS;
    }
如有问题,欢迎指正
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值