Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaSpring上下文:手动加载属性占位符_Java_Spring_Properties_Loading - Fatal编程技术网

JavaSpring上下文:手动加载属性占位符

JavaSpring上下文:手动加载属性占位符,java,spring,properties,loading,Java,Spring,Properties,Loading,SpringJava-quartz调度应用程序 我想加载动态传递的.property文件,抛出程序参数,而不是context:property占位符在spring上下文中,如何实现此任务,欢迎任何帮助… 我正在从主java文件手动加载和刷新spring上下文,如下代码所示 SpringUtil_1.loadSpringConfig(); rootContext = new ClassPathXmlApplicationContext(); rootContext.setConfigLocatio

SpringJava-quartz调度应用程序

我想加载动态传递的.property文件,抛出程序参数,而不是context:property占位符在spring上下文中,如何实现此任务,欢迎任何帮助…

我正在从主java文件手动加载和刷新spring上下文,如下代码所示

SpringUtil_1.loadSpringConfig();
rootContext = new ClassPathXmlApplicationContext();
rootContext.setConfigLocation("abc-configuration.xml");
rootContext.refresh();
在spring配置中,我有上下文属性placeholder,如下所示,我想从代码中删除它

<context:property-placeholder location="classpath:lnRuntime.properties"/>
找到答案

@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
  PropertySourcesPlaceholderConfigurer pspc =
   new PropertySourcesPlaceholderConfigurer();
  Resource[] resources = new ClassPathResource[ ]
   { new ClassPathResource( "foo.properties" ) };
  pspc.setLocations( resources );
  //pspc.setIgnoreUnresolvablePlaceholders( true );
  return pspc;
}
决议

private @Value("${dz.host}") String dzHost;
@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
  PropertySourcesPlaceholderConfigurer pspc =
   new PropertySourcesPlaceholderConfigurer();
  Resource[] resources = new ClassPathResource[ ]
   { new ClassPathResource( "foo.properties" ) };
  pspc.setLocations( resources );
  //pspc.setIgnoreUnresolvablePlaceholders( true );
  return pspc;
}