forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#1016, Annotation Enhancemane
* Add compatibility for Spring 3.2.x to resolve * Add final to BEAN_NAME field * @EnableDubboConfig & @EnableDubbo
- Loading branch information
1 parent
1f2dcbe
commit d528433
Showing
40 changed files
with
3,802 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...aba/dubbo/config/spring/beans/factory/annotation/DubboConfigBindingBeanPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.alibaba.dubbo.config.spring.beans.factory.annotation; | ||
|
||
import com.alibaba.dubbo.common.utils.Assert; | ||
import com.alibaba.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar; | ||
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfigBinding; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.PropertyValues; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.validation.DataBinder; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Dubbo Config Binding {@link BeanPostProcessor} | ||
* | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @see EnableDubboConfigBinding | ||
* @see DubboConfigBindingRegistrar | ||
* @since 2.5.8 | ||
*/ | ||
public class DubboConfigBindingBeanPostProcessor implements BeanPostProcessor { | ||
|
||
private final Log log = LogFactory.getLog(getClass()); | ||
|
||
/** | ||
* Binding Bean Name | ||
*/ | ||
private final String beanName; | ||
|
||
/** | ||
* Binding {@link PropertyValues} | ||
*/ | ||
private final PropertyValues propertyValues; | ||
|
||
|
||
/** | ||
* @param beanName Binding Bean Name | ||
* @param propertyValues {@link PropertyValues} | ||
*/ | ||
public DubboConfigBindingBeanPostProcessor(String beanName, PropertyValues propertyValues) { | ||
Assert.notNull(beanName, "The name of bean must not be null"); | ||
Assert.notNull(propertyValues, "The PropertyValues of bean must not be null"); | ||
this.beanName = beanName; | ||
this.propertyValues = propertyValues; | ||
} | ||
|
||
@Override | ||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { | ||
|
||
if (beanName.equals(this.beanName)) { | ||
DataBinder dataBinder = new DataBinder(bean); | ||
// TODO ignore invalid fields by annotation attribute | ||
dataBinder.setIgnoreInvalidFields(true); | ||
dataBinder.bind(propertyValues); | ||
if (log.isInfoEnabled()) { | ||
log.info("The properties of bean [name : " + beanName + "] have been binding by values : " | ||
+ Arrays.asList(propertyValues.getPropertyValues())); | ||
} | ||
} | ||
|
||
return bean; | ||
|
||
} | ||
|
||
|
||
@Override | ||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
return bean; | ||
} | ||
|
||
} |
Oops, something went wrong.