Skip to content

Commit

Permalink
Merge pull request #23 from mercyblitz/dev-1.x
Browse files Browse the repository at this point in the history
[Compatiblity] 1.x branch supports the Spring Boot 2.x as low as possible
  • Loading branch information
mercyblitz authored Jan 8, 2025
2 parents df331a8 + 64973ac commit 30ced67
Show file tree
Hide file tree
Showing 23 changed files with 1,469 additions and 43 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
strategy:
matrix:
java: [ '8', '11' , '17' , '21' ]
maven-profile-spring-boot: [ 'spring-boot-2.4' , 'spring-boot-2.5' , 'spring-boot-2.6' , 'spring-boot-2.7' ]
maven-profile-spring-boot: [ 'spring-boot-2.1' , 'spring-boot-2.2' , 'spring-boot-2.3',
'spring-boot-2.4' ,'spring-boot-2.5' , 'spring-boot-2.6' ,
'spring-boot-2.7' ]
steps:
- name: Checkout Source
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@ compiler/.gradle/*
.extract
.java-version

# vscode
.vscode/

# others
build.txt
44 changes: 44 additions & 0 deletions microsphere-core-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
</dependency>

<!-- Testing Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -62,4 +68,42 @@
</dependency>

</dependencies>

<profiles>
<profile>
<id>spring-boot-2.1</id>
<dependencies>
<!-- Compatible -->
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-compatible</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</profile>

<profile>
<id>spring-boot-2.2</id>
<dependencies>
<!-- Compatible -->
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-compatible</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</profile>

<profile>
<id>spring-boot-2.3</id>
<dependencies>
<!-- Compatible -->
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-compatible</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, Bind
return returnValue;
}

@Override
/**
* {@inheritDoc}
*
* @since Spring Boot 2.2.2
*/
public Object onCreate(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {
Object returnValue = super.onCreate(name, target, context, result);
Object returnValue = result;
bindHandlers.onCreate(name, target, context, result);
return returnValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Map;

import static io.microsphere.spring.core.env.PropertySourcesUtils.getSubProperties;
import static java.lang.Integer.valueOf;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
Expand Down Expand Up @@ -59,6 +60,6 @@ void testBind() {
Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "user");
beanBinder.bind(properties, true, true, user);
assertEquals("mercyblitz", user.getName());
assertEquals(37, user.getAge());
assertEquals(valueOf(37), user.getAge());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.mock.env.MockPropertySource;
import org.springframework.test.context.TestPropertySource;

import javax.annotation.PostConstruct;

import static java.lang.Integer.valueOf;
import static java.util.Locale.SIMPLIFIED_CHINESE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

Expand All @@ -43,10 +44,11 @@
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
@SpringBootTest(classes = {ListenableConfigurationPropertiesBindHandlerAdvisor.class,
EventPublishingConfigurationPropertiesBeanPropertyChangedListener.class,
EventPublishingConfigurationPropertiesBeanPropertyChangedListenerTest.class})
@TestPropertySource(properties = {"server.error.path=/error.jsp"})
@SpringBootTest(classes =
{ListenableConfigurationPropertiesBindHandlerAdvisor.class,
EventPublishingConfigurationPropertiesBeanPropertyChangedListener.class,
EventPublishingConfigurationPropertiesBeanPropertyChangedListenerTest.class},
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@EnableAutoConfiguration
@EnableConfigurationProperties
public class EventPublishingConfigurationPropertiesBeanPropertyChangedListenerTest {
Expand Down Expand Up @@ -74,52 +76,52 @@ public void init() {

@Test
public void testJacksonProperties() {
assertNull(jacksonProperties.getDateFormat());
assertNull(jacksonProperties.getLocale());

context.addApplicationListener((ApplicationListener<ConfigurationPropertiesBeanPropertyChangedEvent>) event -> {
ConfigurationProperty configurationProperty = event.getConfigurationProperty();
String propertyName = event.getPropertyName();
if ("dateFormat".equals(propertyName)) {
if ("locale".equals(propertyName)) {
assertEquals(jacksonProperties, event.getSource());
assertNull(event.getOldValue());
assertEquals("yyyy-MM-dd HH:mm:ss", event.getNewValue());
assertEquals("spring.jackson.date-format", configurationProperty.getName().toString());
assertEquals(event.getNewValue(), configurationProperty.getValue());
assertEquals(SIMPLIFIED_CHINESE, event.getNewValue());
assertEquals("spring.jackson.locale", configurationProperty.getName().toString());
assertEquals(event.getNewValue().toString(), configurationProperty.getValue());
}
});

mockPropertySource.setProperty("spring.jackson.dateFormat", "yyyy-MM-dd HH:mm:ss");
mockPropertySource.setProperty("spring.jackson.locale", "zh_CN");
beanFactory.destroyBean(jacksonProperties);
beanFactory.initializeBean(jacksonProperties, "spring.jackson-jacksonProperties");
assertEquals("yyyy-MM-dd HH:mm:ss", jacksonProperties.getDateFormat());
beanFactory.initializeBean(jacksonProperties, getBeanName(jacksonProperties));
assertEquals(SIMPLIFIED_CHINESE, jacksonProperties.getLocale());
}

@Test
public void testServerProperties() {
assertNull(serverProperties.getPort());

String newPortPropertyValue = "9527";

context.addApplicationListener((ApplicationListener<ConfigurationPropertiesBeanPropertyChangedEvent>) event -> {
ConfigurationProperty configurationProperty = event.getConfigurationProperty();
String propertyName = event.getPropertyName();
if ("error.path".equals(propertyName)) {
assertEquals(serverProperties, event.getSource());
assertEquals("/error", event.getOldValue());
assertEquals("/error-page", event.getNewValue());
assertEquals("server.error.path", configurationProperty.getName().toString());
assertEquals(event.getNewValue(), configurationProperty.getValue());
} else if ("compression.enabled".equals(propertyName)) {
if ("port".equals(propertyName)) {
assertEquals(serverProperties, event.getSource());
assertEquals(false, event.getOldValue());
assertEquals(true, event.getNewValue());
assertEquals("server.compression.enabled", configurationProperty.getName().toString());
assertEquals("true", configurationProperty.getValue());
assertNull(event.getOldValue());
assertEquals(valueOf(newPortPropertyValue), event.getNewValue());
assertEquals(valueOf((String) configurationProperty.getValue()), event.getNewValue());
}
});

mockPropertySource.setProperty("server.error.path", "/error-page");
mockPropertySource.setProperty("server.compression.enabled", "true");
mockPropertySource.setProperty("server.port", newPortPropertyValue);
beanFactory.destroyBean(serverProperties);
beanFactory.initializeBean(serverProperties, "server-serverProperties");
beanFactory.initializeBean(serverProperties, getBeanName(serverProperties));

}

private String getBeanName(Object configurationPropertiesBean) {
Class<?> beanClass = configurationPropertiesBean.getClass();
String[] beanNames = this.context.getBeanNamesForType(beanClass);
return beanNames[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ io.microsphere.spring.context.event.BeanTimeStatistics

# BeanFactoryListener
io.microsphere.spring.context.event.BeanFactoryListener=\
io.microsphere.spring.context.event.LoggingBeanFactoryListener,\
io.microsphere.spring.context.event.ParallelPreInstantiationSingletonsBeanFactoryListener
io.microsphere.spring.context.event.LoggingBeanFactoryListener
27 changes: 27 additions & 0 deletions microsphere-spring-boot-actuator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -68,4 +74,25 @@

</dependencies>

<profiles>
<profile>
<id>spring-boot-2.1</id>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.3.20</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.25.RELEASE</version>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics;
import io.micrometer.core.instrument.internal.TimedScheduledExecutorService;
import io.microsphere.concurrent.DelegatingScheduledExecutorService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.SmartInitializingSingleton;
Expand All @@ -38,7 +37,7 @@
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
* @see ThreadPoolTaskScheduler
* @see ExecutorServiceMetrics
* @see TimedScheduledExecutorService
* @see io.micrometer.core.instrument.internal.TimedScheduledExecutorService
* @since 1.0.0
*/
public class MonitoredThreadPoolTaskScheduler extends ThreadPoolTaskScheduler implements ApplicationContextAware, SmartInitializingSingleton {
Expand Down
78 changes: 78 additions & 0 deletions microsphere-spring-boot-compatible/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-parent</artifactId>
<version>${revision}</version>
<relativePath>../microsphere-spring-boot-parent/pom.xml</relativePath>
</parent>

<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-compatible</artifactId>
<version>${revision}</version>
<packaging>jar</packaging>

<name>Microsphere :: Spring Boot :: Compatible</name>
<description>Microsphere Spring Boot Compatible</description>

<dependencies>

<!-- Spring Boot (prevent forking anything) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<optional>true</optional>
</dependency>

<!-- Spring Framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<optional>true</optional>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>


<profiles>
<profile>
<id>spring-boot-2.1</id>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.25.RELEASE</version>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Loading

0 comments on commit 30ced67

Please sign in to comment.