Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ Choose the version that matches your Spring Boot generation:

| Branch | Spring Boot Compatibility | Latest Version |
|--------|---------------------------|----------------|
| `main` | 3.0.x – 3.5.x, 4.1.x | `0.2.27` |
| `1.x` | 2.0.x – 2.7.x | `0.1.27` |
| `main` | 3.0.x – 3.5.x, 4.1.x | `0.2.28` |
| `1.x` | 2.0.x – 2.7.x | `0.1.28` |

### Add Module Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ String getPrefix() {
*/
@Nonnull
Class<?> getBeanClass() {
return getBeanType().getRawClass();
return getBeanType().resolve();
}

void initializeBean(Object bean) {
Expand Down Expand Up @@ -209,7 +209,7 @@ private void initBeanProperties() {
}

private void initBeanProperties(ResolvableType beanType, ConfigurationPropertyName prefixName, String nestedPath) {
Class<?> beanClass = beanType.getRawClass();
Class<?> beanClass = beanType.resolve();
if (isCandidateClass(beanClass)) {
Constructor<?> bindConstructor = this.bindConstructor;
if (bindConstructor == null) {
Expand Down Expand Up @@ -544,8 +544,14 @@ static String buildPropertyPath(String propertyName, @Nullable String nestedPath
* @return {@code true} if the property is a binding candidate, {@code false} otherwise
*/
static boolean isCandidateProperty(PropertyDescriptor descriptor) {
if (descriptor == null) {
return false;
}
Method readMethod = descriptor.getReadMethod();
return readMethod == null || !Object.class.equals(readMethod.getDeclaringClass());
if (readMethod == null) {
return false;
}
return !Object.class.equals(readMethod.getDeclaringClass());
}

/**
Expand All @@ -563,6 +569,9 @@ static boolean isCandidateProperty(PropertyDescriptor descriptor) {
* @return {@code true} if the class is a binding candidate, {@code false} otherwise
*/
static boolean isCandidateClass(Class<?> beanClass) {
if (beanClass == null) {
return false;
}
if (isPrimitiveOrWrapper(beanClass) || beanClass.isEnum()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
* @see ConfigurationPropertiesBeanPropertyChangedEvent
* @since 1.0.0
*/
public class EventPublishingConfigurationPropertiesBeanPropertyChangedListener implements BindListener,
ApplicationContextAware, InitializingBean, SmartInitializingSingleton {
public class EventPublishingConfigurationPropertiesBeanPropertyChangedListener implements BindListener, ApplicationContextAware, InitializingBean, SmartInitializingSingleton {

private static final Logger logger = getLogger(EventPublishingConfigurationPropertiesBeanPropertyChangedListener.class);

Expand Down Expand Up @@ -190,4 +189,4 @@ public void afterSingletonsInstantiated() {
public boolean isBound() {
return bound;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import org.springframework.core.annotation.AnnotationAttributes;

import java.beans.PropertyDescriptor;
import java.util.concurrent.TimeUnit;

import static io.microsphere.spring.boot.context.properties.bind.ConfigurationPropertiesBeanContext.getInstance;
import static io.microsphere.spring.boot.context.properties.bind.ConfigurationPropertiesBeanContext.isCandidateClass;
import static io.microsphere.spring.boot.context.properties.bind.ConfigurationPropertiesBeanContext.isCandidateProperty;
import static io.microsphere.spring.core.annotation.AnnotationUtils.getAnnotationAttributes;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -144,11 +146,33 @@ void testGetInstance() {

@Test
void testIsCandidateProperty() {
assertFalse(isCandidateProperty(null));
PropertyDescriptor descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "name");
assertTrue(isCandidateProperty(descriptor));
assertFalse(isCandidateProperty(descriptor));

descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "not-found");
assertFalse(isCandidateProperty(descriptor));

descriptor = getPropertyDescriptor(ConfigurationPropertiesBeanContextTest.class, "class");
assertFalse(isCandidateProperty(descriptor));

descriptor = getPropertyDescriptor(ServerProperties.class, "port");
assertTrue(isCandidateProperty(descriptor));
}

@Test
void testIsCandidateClass() {
// null
assertFalse(isCandidateClass(null));
// primitive type and wrapper type are not candidate class
assertFalse(isCandidateClass(int.class));
assertFalse(isCandidateClass(Integer.class));
// enumeration type
assertFalse(isCandidateClass(TimeUnit.class));
// String is candidate class,but is under java.lang package.
assertFalse(isCandidateClass(String.class));
// current class
assertTrue(isCandidateClass(getClass()));
}

public void setName(String name) {
Expand Down
Loading