|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object oranjestad.spring.plugin.PluginBeanFactoryPostProcessor
public class PluginBeanFactoryPostProcessor
Utility used by spring to dynamically plug-in beans into extension beans. This approach was first publicized in the 2006 publication of devx magazine.
Typical spring allows you to directly wire together components. This
post processor will insert a bean definition into a List
based property
of another bean just before object creation. This combined with springs
auto discovery of context files allows you to wire together components without
the original component's configuration getting modified.
<beans>
<bean id="extension.object" class="some.class">
<property name="extProperty">
<list>
<!-- properties typically added via plug-in mechanism -->
</list>
</property>
</bean>
</beans>
Now imagine we want to wire in a bean reference to extProperty but
we don't want to modify this file. We could define a seperate context file
as follows. It defines the plug-in bean and uses an instance of
PluginBeanFactoryPostProcessor
to wire in its reference.
<beans>
<bean class="oranjestad.spring.PluginBeanFactoryPostProcessor">
<property name="extensionBeanName" value="extension.object" />
<property name="propertyName" value="extProperty" />
<property name="pluginBeanName" value="plugin" />
</bean>
<bean id="plugin" class="some.class.AppropriateForExtProperty" />
</beans>
<bean class="platform.spring.PluginBeanFactoryPostProcessor">
<property name="extensionBeanName" value="bean with list based property" />
<property name="propertyName" value="list based property" />
<property name="pluginBeanName" value="bean to plugin" />
</bean>
In spring when using <import resource="classpath*:.."/>
it is possible to pick up the same spring file multiple times (for example
if a jar is on the classpath twice). Usually this is not a problem since
spring uses a last-one-in-wins approach. But with plugins, it would be
possible for a plug-in to get added twice, since this class might be created
and registered twice.
To work around this case, this class only adds beans not currently in the extension points list of objects. If, however, the actual intent is to add the same bean twice, you can accomplish this by creating an alias to the same bean and adding that alias.
Constructor Summary | |
---|---|
PluginBeanFactoryPostProcessor()
|
Method Summary | |
---|---|
void |
postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
|
void |
setBeanName(java.lang.String name)
|
void |
setExtensionBeanName(java.lang.String beanName)
The bean that is being extended (the bean with a List based
property. |
void |
setPluginBeanName(java.lang.String pluginName)
The name of the bean to plug-in to the extension bean's list property. |
void |
setPropertyName(java.lang.String propertyName)
The name of the List property within the
extension bean. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PluginBeanFactoryPostProcessor()
Method Detail |
---|
public void setExtensionBeanName(java.lang.String beanName)
List
based
property.
beanName
- Spring bean name.public void setPropertyName(java.lang.String propertyName)
List
property within the
extension
bean.
propertyName
- property name.public void setPluginBeanName(java.lang.String pluginName)
pluginName
- The plugin bean's name.public void setBeanName(java.lang.String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) throws org.springframework.beans.BeansException
postProcessBeanFactory
in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
org.springframework.beans.BeansException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |