@@ -51,43 +51,49 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
51
51
applicationContext .addApplicationListener (new Listener (applicationContext ));
52
52
}
53
53
54
- private record Listener ( ConfigurableApplicationContext applicationContext ) implements ApplicationListener <RSocketServerInitializedEvent > {
54
+ private static class Listener implements ApplicationListener <RSocketServerInitializedEvent > {
55
55
56
- private static final String PROPERTY_NAME = "local.rsocket.server.port" ;
56
+ private static final String PROPERTY_NAME = "local.rsocket.server.port" ;
57
57
58
- private static final String PROPERTY_SOURCE_NAME = "server.ports" ;
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
+ }
59
65
60
66
@ Override
61
- public void onApplicationEvent (RSocketServerInitializedEvent event ) {
62
- if (event .getServer ().address () != null ) {
63
- setPortProperty (this .applicationContext , event .getServer ().address ().getPort ());
64
- }
67
+ public void onApplicationEvent (RSocketServerInitializedEvent event ) {
68
+ if (event .getServer ().address () != null ) {
69
+ setPortProperty (this .applicationContext , event .getServer ().address ().getPort ());
65
70
}
71
+ }
66
72
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
- }
73
+ private void setPortProperty (ApplicationContext context , int port ) {
74
+ if (context instanceof ConfigurableApplicationContext configurableContext ) {
75
+ setPortProperty (configurableContext .getEnvironment (), port );
74
76
}
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 );
77
+ if (context .getParent () != null ) {
78
+ setPortProperty (context .getParent (), port );
84
79
}
80
+ }
85
81
86
- @ SuppressWarnings ("unchecked" )
87
- private void setPortProperty (int port , PropertySource <?> source ) {
88
- ((Map <String , Object >) source .getSource ()).put (PROPERTY_NAME , port );
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 );
89
88
}
89
+ setPortProperty (port , source );
90
+ }
90
91
92
+ @ SuppressWarnings ("unchecked" )
93
+ private void setPortProperty (int port , PropertySource <?> source ) {
94
+ ((Map <String , Object >) source .getSource ()).put (PROPERTY_NAME , port );
91
95
}
92
96
97
+ }
98
+
93
99
}
0 commit comments