Вот первозданный вид
Version:0.9 StartHTML:00000000108 EndHTML:00000003623 StartFragment:00000000108 EndFragment:00000003623
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="Server.properties"/> <property name="ignoreUnresolvablePlaceholders" value="true"/> bean>>
1)Идея поменять параметры бина в коде оказалась провальной - спринг читает сразу весь applicationContext.xml, что приводит к невозможности проинициализировать только один бин дручками до того как вычитать всё, следующий код вылетает с ошибкой
ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(new String[]{applicationContextName},false); final Object placeholderConfigurer = classPathXmlApplicationContext.getBean("placeholderConfigurer"); classPathXmlApplicationContext.refresh();до вызова refresh().
2)Использовать org.springframework.beans.factory.config.PropertyPathFactoryBean
Version:0.9 StartHTML:00000000108 EndHTML:00000006014 StartFragment:00000000108 EndFragment:00000006014
<bean id="serverProperties" class="ru.intelcom.server.ServerProperties"/> <bean id="serverProperties.properties" class="org.springframework.beans.factory.config.PropertyPathFactoryBean"/> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" ref="serverProperties.properties"/> <property name="ignoreUnresolvablePlaceholders" value="true"/> bean>
С утилитными схемами:Version:0.9 StartHTML:00000000108 EndHTML:00000000509 StartFragment:00000000108 EndFragment:00000000509
xmlns:util="http://www.springframework.org/schema/util"Version:0.9 StartHTML:00000000108 EndHTML:00000000574 StartFragment:00000000108 EndFragment:00000000574
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
можно написать это так
Version:0.9 StartHTML:00000000108 EndHTML:00000005762 StartFragment:00000000108 EndFragment:00000005762
<bean id="serverProperties" class="ru.intelcom.server.ServerProperties"/> <util:property-path id="serverProperties.properties" path="serverProperties.properties"/> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" ref="serverProperties.properties"/> <property name="ignoreUnresolvablePlaceholders" value="true"/> bean>
3) Использовать org.springframework.beans.factory.config.FieldRetrievingFactoryBean
Version:0.9 StartHTML:00000000108 EndHTML:00000004810 StartFragment:00000000108 EndFragment:00000004810
<bean id="ru.intelcom.server.ServerProperties.properties" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" ref="ru.intelcom.server.ServerProperties.properties"/> <property name="ignoreUnresolvablePlaceholders" value="true"/> bean>>
или так
Version:0.9 StartHTML:00000000108 EndHTML:00000006125 StartFragment:00000000108 EndFragment:00000006125
<bean id="serverProperties" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"> <property name="staticField" value="ru.intelcom.server.ServerProperties.properties"/> bean> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" ref="serverProperties"/> <property name="ignoreUnresolvablePlaceholders" value="true"/> bean>
С утилитными схемами:V
Version:0.9 StartHTML:00000000108 EndHTML:00000004549 StartFragment:00000000108 EndFragment:00000004549
<util:constant static-field="ru.intelcom.server.ServerProperties.properties"/> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" ref="ru.intelcom.server.ServerProperties.properties"/> <property name="ignoreUnresolvablePlaceholders" value="true"/> bean>
иили так
Version:0.9 StartHTML:00000000108 EndHTML:00000004898 StartFragment:00000000108 EndFragment:00000004898
<util:constant id="serverProperties" static-field="ru.intelcom.server.ServerProperties.properties"/> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" ref="serverProperties"/> <property name="ignoreUnresolvablePlaceholders" value="true"/> bean>
узнал всё тут:
http://static.springsource.org/spring/docs/2.0.x/reference/xsd-config.html
http://springindepth.com/book/in-depth-ioc-constructor-setter-injection.html
Nice, but would have been awesome if you made it available in English as well.
ОтветитьУдалить