Skip to content

Commit 8468cce

Browse files
committed
Refactor code and update documentation
1 parent 6cd6f75 commit 8468cce

File tree

6 files changed

+31
-40
lines changed

6 files changed

+31
-40
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@ private void setDriverClass(ComboPooledDataSource dataSource, String driverClass
698698
*/
699699
private static class SimpleDataSourceProperties extends MappedDataSourceProperties<SimpleDriverDataSource> {
700700

701-
@SuppressWarnings("unchecked")
702701
SimpleDataSourceProperties() {
703702
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
704703
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class, (dataSource) -> dataSource.getDriver().getClass(),

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JsonValueWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ else if (value instanceof Map<?, ?> map) {
106106
else if (value instanceof Number) {
107107
append(value.toString());
108108
}
109-
else if (value instanceof Boolean) {
110-
append(Boolean.TRUE.equals(value) ? "true" : "false");
109+
else if (value instanceof Boolean bool) {
110+
append(bool ? "true" : "false");
111111
}
112112
else {
113113
writeString(value);

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ protected void loadConfiguration(LoggingInitializationContext initializationCont
238238

239239
private void load(LoggingInitializationContext initializationContext, String location, LogFile logFile) {
240240
List<String> overrides = getOverrides(initializationContext);
241-
if (initializationContext != null) {
242-
applySystemProperties(initializationContext.getEnvironment(), logFile);
243-
}
241+
applySystemProperties(initializationContext.getEnvironment(), logFile);
244242
loadConfiguration(location, logFile, overrides);
245243
}
246244

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/context/RSocketPortInfoApplicationContextInitializer.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,49 +51,43 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
5151
applicationContext.addApplicationListener(new Listener(applicationContext));
5252
}
5353

54-
private static class Listener implements ApplicationListener<RSocketServerInitializedEvent> {
54+
private record Listener(ConfigurableApplicationContext applicationContext) implements ApplicationListener<RSocketServerInitializedEvent> {
5555

56-
private static final String PROPERTY_NAME = "local.rsocket.server.port";
56+
private static final String PROPERTY_NAME = "local.rsocket.server.port";
5757

58-
private static final String PROPERTY_SOURCE_NAME = "server.ports";
59-
60-
private final ConfigurableApplicationContext applicationContext;
61-
62-
Listener(ConfigurableApplicationContext applicationContext) {
63-
this.applicationContext = applicationContext;
64-
}
58+
private static final String PROPERTY_SOURCE_NAME = "server.ports";
6559

6660
@Override
67-
public void onApplicationEvent(RSocketServerInitializedEvent event) {
68-
if (event.getServer().address() != null) {
69-
setPortProperty(this.applicationContext, event.getServer().address().getPort());
61+
public void onApplicationEvent(RSocketServerInitializedEvent event) {
62+
if (event.getServer().address() != null) {
63+
setPortProperty(this.applicationContext, event.getServer().address().getPort());
64+
}
7065
}
71-
}
7266

73-
private void setPortProperty(ApplicationContext context, int port) {
74-
if (context instanceof ConfigurableApplicationContext configurableContext) {
75-
setPortProperty(configurableContext.getEnvironment(), port);
67+
private void setPortProperty(ApplicationContext context, int port) {
68+
if (context instanceof ConfigurableApplicationContext configurableContext) {
69+
setPortProperty(configurableContext.getEnvironment(), port);
70+
}
71+
if (context.getParent() != null) {
72+
setPortProperty(context.getParent(), port);
73+
}
7674
}
77-
if (context.getParent() != null) {
78-
setPortProperty(context.getParent(), port);
75+
76+
private void setPortProperty(ConfigurableEnvironment environment, int port) {
77+
MutablePropertySources sources = environment.getPropertySources();
78+
PropertySource<?> source = sources.get(PROPERTY_SOURCE_NAME);
79+
if (source == null) {
80+
source = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<>());
81+
sources.addFirst(source);
82+
}
83+
setPortProperty(port, source);
7984
}
80-
}
8185

82-
private void setPortProperty(ConfigurableEnvironment environment, int port) {
83-
MutablePropertySources sources = environment.getPropertySources();
84-
PropertySource<?> source = sources.get(PROPERTY_SOURCE_NAME);
85-
if (source == null) {
86-
source = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<>());
87-
sources.addFirst(source);
86+
@SuppressWarnings("unchecked")
87+
private void setPortProperty(int port, PropertySource<?> source) {
88+
((Map<String, Object>) source.getSource()).put(PROPERTY_NAME, port);
8889
}
89-
setPortProperty(port, source);
90-
}
9190

92-
@SuppressWarnings("unchecked")
93-
private void setPortProperty(int port, PropertySource<?> source) {
94-
((Map<String, Object>) source.getSource()).put(PROPERTY_NAME, port);
9591
}
9692

97-
}
98-
9993
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/reactive/ApplicationContextServerWebExchangeMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/**
3030
* {@link ApplicationContext} backed {@link ServerWebExchangeMatcher}. Can work directly
3131
* with the {@link ApplicationContext}, obtain an existing bean or
32-
* {@link AutowireCapableBeanFactory#createBean(Class, int, boolean) create a new bean}
32+
* {@link AutowireCapableBeanFactory#createBean(Class) create a new bean}
3333
* that is autowired in the usual way.
3434
*
3535
* @param <C> the type of the context that the match method actually needs to use. Can be

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/security/servlet/ApplicationContextRequestMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* {@link ApplicationContext} backed {@link RequestMatcher}. Can work directly with the
3232
* {@link ApplicationContext}, obtain an existing bean or
33-
* {@link AutowireCapableBeanFactory#createBean(Class, int, boolean) create a new bean}
33+
* {@link AutowireCapableBeanFactory#createBean(Class) create a new bean}
3434
* that is autowired in the usual way.
3535
*
3636
* @param <C> the type of the context that the match method actually needs to use. Can be

0 commit comments

Comments
 (0)