-
Notifications
You must be signed in to change notification settings - Fork 10
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 #235 from trydofor/develop
3.2.120 previewed
- Loading branch information
Showing
50 changed files
with
1,151 additions
and
310 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
Submodule docs
updated
20 files
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
21 changes: 21 additions & 0 deletions
21
wings/silencer/src/main/java/pro/fessional/wings/silencer/enhance/ThisLazy.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,21 @@ | ||
package pro.fessional.wings.silencer.enhance; | ||
|
||
/** | ||
* <pre> | ||
* @Setter(onMethod_ = {@Autowired, @Lazy}) | ||
* protected RuntimeConfServiceImpl thisLazy = this; | ||
* </pre> | ||
* | ||
* @author trydofor | ||
* @since 2024-05-10 | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public class ThisLazy<T> implements ThisLazyAware<T> { | ||
|
||
protected T thisLazy = (T) this; | ||
|
||
@Override | ||
public void setThisLazy(T self) { | ||
this.thisLazy = self; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
wings/silencer/src/main/java/pro/fessional/wings/silencer/enhance/ThisLazyAware.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,20 @@ | ||
package pro.fessional.wings.silencer.enhance; | ||
|
||
/** | ||
* <pre> | ||
* @Setter(onMethod_ = {@Autowired, @Lazy}) | ||
* protected RuntimeConfServiceImpl thisLazy = this; | ||
* </pre> | ||
* | ||
* @author trydofor | ||
* @since 2024-05-10 | ||
*/ | ||
public interface ThisLazyAware<T> { | ||
|
||
/** | ||
* inject enhanced this before Bean Initialization | ||
* | ||
* @param thisLazy enhanced bean | ||
*/ | ||
void setThisLazy(T thisLazy); | ||
} |
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
86 changes: 86 additions & 0 deletions
86
...ilencer/src/main/java/pro/fessional/wings/silencer/spring/boot/WingsReorderProcessor.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,86 @@ | ||
package pro.fessional.wings.silencer.spring.boot; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.beans.factory.support.AbstractBeanDefinition; | ||
import org.springframework.boot.context.properties.bind.Bindable; | ||
import org.springframework.boot.context.properties.bind.Binder; | ||
import org.springframework.context.EnvironmentAware; | ||
import org.springframework.core.ResolvableType; | ||
import org.springframework.core.env.Environment; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* (@Order | @Priority) > Ordered.getOrder | ||
* | ||
* @author trydofor | ||
* @see org.springframework.core.annotation.AnnotationAwareOrderComparator | ||
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#getBeanProvider(ResolvableType, boolean) | ||
* @since 2024-05-11 | ||
*/ | ||
public class WingsReorderProcessor implements BeanFactoryPostProcessor, EnvironmentAware { | ||
|
||
private static final Log log = LogFactory.getLog(WingsReorderProcessor.class); | ||
|
||
/** | ||
* reorder bean by beanName(one-one) or beanClass(one-many). | ||
*/ | ||
public static final String PrefixReorder = "wings.reorder"; | ||
|
||
/** | ||
* set bean as primary by beanName | ||
*/ | ||
public static final String PrefixPrimary = "wings.primary"; | ||
|
||
private Environment environment; | ||
|
||
@Override | ||
public void setEnvironment(@NotNull Environment env) { | ||
this.environment = env; | ||
} | ||
|
||
@Override | ||
public void postProcessBeanFactory(@NotNull ConfigurableListableBeanFactory beanFactory) throws BeansException { | ||
Map<String, Integer> reorderProp = Binder.get(environment) | ||
.bind(PrefixReorder, Bindable.mapOf(String.class, Integer.class)) | ||
.orElseGet(Collections::emptyMap); | ||
|
||
Map<String, Boolean> primaryProp = Binder.get(environment) | ||
.bind(PrefixPrimary, Bindable.mapOf(String.class, Boolean.class)) | ||
.orElseGet(Collections::emptyMap); | ||
|
||
if (reorderProp.isEmpty() && primaryProp.isEmpty()) { | ||
log.info("WingsReorderProcessor skipped, for no properties under " + PrefixReorder + " and " + PrefixPrimary); | ||
return; | ||
} | ||
|
||
for (String bn : beanFactory.getBeanDefinitionNames()) { | ||
BeanDefinition definition = beanFactory.getBeanDefinition(bn); | ||
Integer order = reorderProp.get(bn); | ||
String logExt = ""; | ||
if (order == null) { | ||
String clz = definition.getBeanClassName(); | ||
order = reorderProp.get(clz); | ||
logExt = ", class=" + clz; | ||
} | ||
|
||
if (order != null) { | ||
log.info("WingsReorderProcessor reorder bean=" + bn + ", order=" + order + logExt); | ||
definition.setAttribute(AbstractBeanDefinition.ORDER_ATTRIBUTE, order); | ||
} | ||
|
||
Boolean primary = primaryProp.get(bn); | ||
if (primary != null) { | ||
log.info("WingsReorderProcessor reorder bean=" + bn + ", primary=" + primary); | ||
definition.setPrimary(primary); | ||
} | ||
} | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
...ilencer/src/test/java/pro/fessional/wings/silencer/app/bean/TestReorderConfiguration.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,94 @@ | ||
package pro.fessional.wings.silencer.app.bean; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import pro.fessional.wings.silencer.spring.boot.ConditionalWingsEnabled; | ||
|
||
/** | ||
* @author trydofor | ||
* @since 2024-05-11 | ||
*/ | ||
@ConditionalWingsEnabled | ||
@Configuration(proxyBeanMethods = false) | ||
public class TestReorderConfiguration { | ||
|
||
@Bean | ||
@ConditionalWingsEnabled | ||
@Order(2) | ||
public PlainClass plainClass1() { | ||
return new PlainClass(1); | ||
} | ||
|
||
@Bean | ||
@ConditionalWingsEnabled | ||
@Order(1) | ||
public PlainClass plainClass2() { | ||
return new PlainClass(2); | ||
} | ||
|
||
@Bean | ||
@ConditionalWingsEnabled | ||
@Order(2) | ||
public GetterClass getterClass1() { | ||
return new GetterClass(1); | ||
} | ||
|
||
@Bean | ||
@ConditionalWingsEnabled | ||
@Order(1) | ||
public GetterClass getterClass2() { | ||
return new GetterClass(2); | ||
} | ||
|
||
|
||
@Bean | ||
@ConditionalWingsEnabled | ||
@Order(2) | ||
public OrderedClass orderedClass1() { | ||
return new OrderedClass(1); | ||
} | ||
|
||
@Bean | ||
@ConditionalWingsEnabled | ||
@Order(1) | ||
public OrderedClass orderedClass2() { | ||
return new OrderedClass(2); | ||
} | ||
|
||
|
||
@RequiredArgsConstructor | ||
public static class PlainClass { | ||
private final int order; | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(order); | ||
} | ||
} | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public static class GetterClass { | ||
private final int order; | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(order); | ||
} | ||
} | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public static class OrderedClass implements Ordered { | ||
private final int order; | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(order); | ||
} | ||
} | ||
} |
Oops, something went wrong.