.properties文件常量定义

application.properties文件,位于resources目录下。一般定义一些不会改变的数据如数据库相关配置,文件路径,项目地址。

如何在项目代码中获取该文件中的配置信息:

1,在applicationContext.xml中配置.properties中内容。

代码:

 1 <!--项目配置信息 -->
 2     <bean id="configInfo" class="com.pingan.credit.model.ConfigInfo">
 3         <property name="jks_name" value="${jks.name}"/>
 4         <property name="jks_password" value="123456"/>
 5 
 6         <property name="py_ssl_ip" value="${py.ssl.ip}"/>
 7         <property name="py_username" value="${py.username}"/>
 8         <property name="py_password" value="${py.password}"/>
 9         <property name="py_file_path" value="${py.filePath}"/>
10 
11         <property name="udmp_path" value="${udmp.path}"/>
12 
13         <property name="qhpdf_path" value="${qhpdf.path}"/>
14 
15         <property name="qh_rskdoo_url" value="${qh.rskdoo.url}"/>
16         <property name="qh_loanee_url" value="${qh.loanee.url}"/>
17         <property name="qh_antiFraudDoo_url" value="${qh.antiFraudDoo.url}"/>
18         <property name="qh_eChkPkgs_url" value="${qh.eChkPkgs.url}"/>
19         <property name="qh_address_url" value="${qh.address.url}"/>
20         <property name="qh_ubzc2m_url" value="${qh.ubzc2m.url}"/>
21         <property name="qh_creTrackInc_url" value="${qh.creTrackInc.url}"/>
22         <property name="qh_creLBS_url" value="${qh.creLBS.url}"/>
23         <property name="qh_eroticPerson_url" value="${qh.eroticPerson.url}"/>
24         <property name="qh_credoo_url" value="${qh.credoo.url}"/>
25         <property name="qh_eChkPkgsCard_url" value="${qh.eChkPkgsCard.url}"/>
26         <property name="qh_xsCrtItgDataIdx_url" value="${qh.xsCrtItgDataIdx.url}"/>
27         <property name="qh_orgCode" value="${qh.orgCode}"/>
28         <property name="qh_chnlId" value="${qh.chnlId}"/>
29         <property name="qh_authCode" value="${qh.authCode}"/>
30         <property name="qh_username" value="${qh.username}"/>
31         <property name="qh_password" value="${qh.password}"/>
32 
33         <property name="server_ip" value="${server.ip}"/>
34     </bean>

 

2,在项目中定义实体,属性为applicationContext.xml文件中配置的属性信息

代码:

 1 @Component("configInfo")
 2 public class ConfigInfo {
 3 
 4     private String jks_name;
 5 
 6     private String py_ssl_ip;
 7 
 8     private String py_username;
 9 
10     private String py_password;
11 
12     private String jks_password;
13 
14     private String udmp_path;
15 
16     private String qhpdf_path;
17 
18     private String qh_rskdoo_url;
19 
20     private String qh_loanee_url;
21 
22     private String qh_antiFraudDoo_url;
23 
24     private String qh_eChkPkgs_url;
25 
26     private String qh_address_url;
27 
28     private String qh_ubzc2m_url;
29 
30     private String qh_creTrackInc_url;
31 
32     private String qh_creLBS_url;
33 
34     private String qh_eroticPerson_url;
35 
36     private String qh_credoo_url;
37 
38     private String qh_eChkPkgsCard_url;
39 
40     private String qh_xsCrtItgDataIdx_url;
41 
42     private String qh_orgCode;
43 
44     private String qh_chnlId;
45 
46     private String qh_authCode;
47 
48     private String qh_username;
49 
50     private String qh_password;
51 
52     private String py_file_path;
53 
54     private String server_ip;
三,在项目中
注入调用
String pdfFilePath = configInfo.getPy_file_path() + "credit" + fileName + PDF_SUFFIX;
posted on 2018-01-18 09:17  T-M  阅读(575)  评论(0编辑  收藏  举报