
|
If you were logged in you would be able to see more operations.
|
|
|
|
The call to getBean(factoryProcessorNames[i]) is flawed because it then must go out to get dependencies just to do ordering.. Below is an example where I had a problem. And below is a work around.. I think rather than implement order perhaps you might want to add an attribute to bean definition i.e: order= and use that instead.
What was happening is that to find the order of ConfigurationPlaceholderProcessor it had to satisfy dependency jconfigBean. The placeholder in that bean was supposed to be replaced first by propertyPlaceholderConfigurer so even though it gets the order for ConfigurationPlaceholderProcessor it's then to late to instantiate jconfigBean with appropriate placeholder from the propertyPlaceholderConfigurer since it had already been instantiated.
--------- flawed code -------
for (int i = 0; i < factoryProcessorNames.length; i++) {
if (Ordered.class.isAssignableFrom(getType(factoryProcessorNames[i]))) {
orderedFactoryProcessors.add(getBean(factoryProcessorNames[i]));
}
else {
nonOrderedFactoryProcessorNames.add(factoryProcessorNames[i]);
}
}
------------- Here is where I had problem ------------
<bean id="jmxExporter"
class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="Configuration:name=jmxConfig">
<ref local="jconfigBean" />
</entry>
</map>
</property>
</bean>
<bean id="jconfigBean" class="org.jconfig.jmx.ConfigHandler">
<property name="resourceName">
<value>${config.filename}</value>
</property>
<property name="configurationName">
<value>jmxConfig</value>
</property>
</bean>
<bean id="configurationFactory"
class="org.reactive.configuration.JConfigConfigurationFactory"
singleton="true">
<property name="fileName"><value>jmxConfig</value></property>
</bean>
<bean id="configuration"
factory-bean="configurationFactory"
factory-method="getConfiguration"
depends-on="jmxExporter"
/>
<bean id="configurationPlaceholderProcessor"
class="org.reactive.beans.factory.config.ConfigurationPlaceholderProcessor">
<property name="placeholderEvaluator">
<bean class="org.reactive.beans.factory.config.jconfig.JConfigPlaceholderEvaluator">
<property name="configuration">
<ref bean="configuration"/>
</property>
</bean>
</property>
<property name="order">
<value>2</value>
</property>
</bean>
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<props>
<prop key="config.filename">dev_config.xml</prop>
</props>
</property>
<property name="systemPropertiesModeName">
<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
<property name="order">
<value>1</value>
</property>
</bean>
------------- Here is possible (not ultimate) fix -----------
for (int i = 0; i < factoryProcessorNames.length; i++) {
if (Ordered.class.isAssignableFrom(getType(factoryProcessorNames[i]))) {
MutablePropertyValues values = getBeanFactory().getBeanDefinition(factoryProcessorNames[i]).getPropertyValues();
int order = Integer.MAX_VALUE;
if (values != null) {
PropertyValue orderValue = values.getPropertyValue("order");
if (orderValue != null) {
String orderInt = (String) orderValue.getValue();
if (orderInt != null) {
order = new Integer(orderInt).intValue();
}
}
}
OrderedFactoryHolder factoryProcessorHolder = new OrderedFactoryHolder(factoryProcessorNames[i],order);
orderedFactoryProcessorHolders.add(factoryProcessorHolder);
}
else {
nonOrderedFactoryProcessorNames.add(factoryProcessorNames[i]);
}
}
private class OrderedFactoryHolder implements Ordered {
/**
* @param factoryName
* @param order
*/
public OrderedFactoryHolder(String factoryProcessorName, int order) {
this.factoryProcessorName = factoryProcessorName;
this.order = order;
}
private String factoryProcessorName;
private int order;
/**
* @return Returns the factoryProcessorName.
*/
public String getFactoryProcessorName() {
return factoryProcessorName;
}
/* (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder()
*/
public int getOrder() {
return order;
}
}
|
|
Description
|
The call to getBean(factoryProcessorNames[i]) is flawed because it then must go out to get dependencies just to do ordering.. Below is an example where I had a problem. And below is a work around.. I think rather than implement order perhaps you might want to add an attribute to bean definition i.e: order= and use that instead.
What was happening is that to find the order of ConfigurationPlaceholderProcessor it had to satisfy dependency jconfigBean. The placeholder in that bean was supposed to be replaced first by propertyPlaceholderConfigurer so even though it gets the order for ConfigurationPlaceholderProcessor it's then to late to instantiate jconfigBean with appropriate placeholder from the propertyPlaceholderConfigurer since it had already been instantiated.
--------- flawed code -------
for (int i = 0; i < factoryProcessorNames.length; i++) {
if (Ordered.class.isAssignableFrom(getType(factoryProcessorNames[i]))) {
orderedFactoryProcessors.add(getBean(factoryProcessorNames[i]));
}
else {
nonOrderedFactoryProcessorNames.add(factoryProcessorNames[i]);
}
}
------------- Here is where I had problem ------------
<bean id="jmxExporter"
class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="Configuration:name=jmxConfig">
<ref local="jconfigBean" />
</entry>
</map>
</property>
</bean>
<bean id="jconfigBean" class="org.jconfig.jmx.ConfigHandler">
<property name="resourceName">
<value>${config.filename}</value>
</property>
<property name="configurationName">
<value>jmxConfig</value>
</property>
</bean>
<bean id="configurationFactory"
class="org.reactive.configuration.JConfigConfigurationFactory"
singleton="true">
<property name="fileName"><value>jmxConfig</value></property>
</bean>
<bean id="configuration"
factory-bean="configurationFactory"
factory-method="getConfiguration"
depends-on="jmxExporter"
/>
<bean id="configurationPlaceholderProcessor"
class="org.reactive.beans.factory.config.ConfigurationPlaceholderProcessor">
<property name="placeholderEvaluator">
<bean class="org.reactive.beans.factory.config.jconfig.JConfigPlaceholderEvaluator">
<property name="configuration">
<ref bean="configuration"/>
</property>
</bean>
</property>
<property name="order">
<value>2</value>
</property>
</bean>
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<props>
<prop key="config.filename">dev_config.xml</prop>
</props>
</property>
<property name="systemPropertiesModeName">
<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
<property name="order">
<value>1</value>
</property>
</bean>
------------- Here is possible (not ultimate) fix -----------
for (int i = 0; i < factoryProcessorNames.length; i++) {
if (Ordered.class.isAssignableFrom(getType(factoryProcessorNames[i]))) {
MutablePropertyValues values = getBeanFactory().getBeanDefinition(factoryProcessorNames[i]).getPropertyValues();
int order = Integer.MAX_VALUE;
if (values != null) {
PropertyValue orderValue = values.getPropertyValue("order");
if (orderValue != null) {
String orderInt = (String) orderValue.getValue();
if (orderInt != null) {
order = new Integer(orderInt).intValue();
}
}
}
OrderedFactoryHolder factoryProcessorHolder = new OrderedFactoryHolder(factoryProcessorNames[i],order);
orderedFactoryProcessorHolders.add(factoryProcessorHolder);
}
else {
nonOrderedFactoryProcessorNames.add(factoryProcessorNames[i]);
}
}
private class OrderedFactoryHolder implements Ordered {
/**
* @param factoryName
* @param order
*/
public OrderedFactoryHolder(String factoryProcessorName, int order) {
this.factoryProcessorName = factoryProcessorName;
this.order = order;
}
private String factoryProcessorName;
private int order;
/**
* @return Returns the factoryProcessorName.
*/
public String getFactoryProcessorName() {
return factoryProcessorName;
}
/* (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder()
*/
public int getOrder() {
return order;
}
} |
Show » |
|
If you use suggestion order=
then
if (Ordered.class.isAssignableFrom(getType(factoryProcessorNames[i]))) {
should be changed to look for that instead...