首先要在初始化参数的类上写上注解@Compoent,并且这个类要实现InitializingBean,ServletContextAware两个接口,然后在通过类的加载器获得参数配置文件

在利用Properties类得到参数的值。

  

 1 @Component
 2 public class InitArgument implements InitializingBean,ServletContextAware{
 3 
 4     private ServletContext context;
 5     public void afterPropertiesSet() throws Exception {
 6         InputStream in = ReadFile.class.getClassLoader().getResourceAsStream("config.properties");
 7         Properties p = new Properties();
 8         p.load(in);
 9         String zipPath = p.getProperty("WEBRESOURCE_ZIP_PATH").trim();
10         if(zipPath != null && !zipPath.equals("")){
11             ConstantUtil.setWEBRESOURCE_ZIP_PATH(zipPath);
12         }
13 }
14 
15     public void setServletContext(ServletContext context) {
16         this.context = context;
17     }

 

相关文章:

  • 2022-12-23
  • 2021-11-14
  • 2021-10-10
  • 2021-11-08
  • 2021-12-13
  • 2022-01-26
  • 2021-12-18
  • 2021-10-22
猜你喜欢
  • 2022-12-23
  • 2021-05-17
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
相关资源
相似解决方案