【问题标题】:java spring context:property-placeholder manually loadingjava spring context:property-placeholder 手动加载
【发布时间】:2012-11-23 17:11:02
【问题描述】:

Spring java-quartz 调度应用

我想加载 .property 文件动态传递的 throw 程序参数而不是 context:property-placeholder 在 spring 上下文中,我该如何完成这项任务,感谢任何帮助...

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

SpringUtil_1.loadSpringConfig();
rootContext = new ClassPathXmlApplicationContext();
rootContext.setConfigLocation("abc-configuration.xml");
rootContext.refresh();

在 spring 配置中,我有如下的上下文属性占位符,我想从代码中获取。

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

我在 spring 上下文中使用占位符,使用 spring EL 的 java 文件如下

<bean id="dataSource" 
class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
        <property name="driverClassName" value="net.sourceforge.jtds.jdbcx.JtdsDataSource"/>
        <property name="url" value="${dataSource.url}"/>
    </bean>

在java中我访问如下

private @Value("${dz.host}") String dzHost;

【问题讨论】:

    标签: java spring properties loading


    【解决方案1】:

    找到答案

    @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;
    }
    

    资源http://www.baeldung.com/2012/02/06/properties-with-spring/#byhandnew

    【讨论】:

      猜你喜欢
      • 2011-11-24
      • 2013-06-22
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多