系统配置化的几种方法

系统配置化的几种方法

Java注解利用properties文件方法

@Value("#{prop['server.cn']}")

private String cnWebUrl;

@RequestMapping(value = "/addConObj")

public String addConObj(Model model) {

String language = CASUtil.getCustomer().getLanguage();

if ("CN".equals(language)) {

return "redirect:" +cnWebUrl + "/offer/addConObj";

}

}

db.properties

server.cn=http://10.0.1.222:8080/web

server.en=http://10.0.1.214:8080/web

//Java中通过注解用配置文件的配置方法

<bean id="prop" class="org.springframework.beans.factory.config.PropertiesFactoryBean" p:location="classpath:db.properties"/>

//配置文件直接用配置的配置方法

<context:property-placeholder location="classpath:db.properties" />

package com.esteel.common;

/**

 * 

 * <静态描述>

 * @author  点钢

 * @data  2016年6月5日

 */

public class StaticVariables

{

  /**

     * web url

     */

    public static String CN_WEB_URL = "http://localhost:8081/web"; // 中文测试环境用

    public static String EN_WEB_URL = "http://localhost:8083/web"; // 英文测试环境用

    /**

     * session中存放userId对应的key

     */

     }

<%

String topPath = request.getContextPath();

request.setAttribute("TopPath",topPath);

String cnSiteUrl = com.esteel.common.StaticVariables.CN_WEB_URL;

request.setAttribute("cnSiteUrl",cnSiteUrl);

String enSiteUrl = com.esteel.common.StaticVariables.EN_WEB_URL;

request.setAttribute("enSiteUrl",enSiteUrl);

//英文地址

String enUrl = "http://10.0.1.214:8080";

request.setAttribute("enUrl", enUrl);

//中文地址

String cnUrl = "http://10.0.1.222:8080";

request.setAttribute("cnUrl", cnUrl);

%>

<script >

var cnSiteUrl = "${cnSiteUrl}";

var enSiteUrl = "${enSiteUrl}";

</script>

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2357479