When using local discovery mode (shenyu.discovery.type=local), the SpringMvc client fails to complete URI registration.
Root Cause
AbstractContextRefreshedEventListener originally declared isDiscoveryLocalMode as a final member field, initialized once in the constructor via props.getProperty(ShenyuClientConstants.DISCOVERY_LOCAL_MODE_KEY). That discoveryLocalMode property, however, is written into props by ShenyuSpringMvcClientConfiguration before it constructs the SpringMvcClientEventListener bean.
Due to a timing race between bean instantiation and the ContextRefreshedEvent firing—AbstractContextRefreshedEventListener#onApplicationEvent may execute before ShenyuSpringMvcClientConfiguration has finished populating props—the discoveryLocalMode property read at construction time is empty, so isDiscoveryLocalMode is always false. As a result, the local-registration branch inside onApplicationEvent is skipped, and the local SpringMvc client never initiates URI registration.
Solution
Remove the immutable field; read at event time instead: Deleted the isDiscoveryLocalMode field and its constructor initialization in AbstractContextRefreshedEventListener. Instead, onApplicationEvent now reads shenyu.discovery.type directly from the Spring Environment (defaulting to local) and evaluates the flag on the fly. This fully decouples discovery-mode evaluation from bean-construction / props-population timing, guaranteeing the correct environment config is consulted no matter when the listener callback fires.
Keep ShenyuSpringMvcClientConfiguration logic intact: The second commit restores the code that writes discoveryLocalMode into props in the configuration class, keeping the fix minimal—only the core listener changes, leaving other flows that may depend on this prop unaffected.
Test & Checkstyle Fixes
SpringMvcClientEventListenerTest, TarsServiceBeanPostProcessorTest: Added mocks for applicationContext.getEnvironment() and the shenyu.discovery.type property to align with the new runtime-read logic.
Fixed indentation of the buildApiSuperPath assertion continuation lines so Checkstyle passes.
Scope
Test changes: SpringMvcClientEventListenerTest.java, TarsServiceBeanPostProcessorTest.java
Compatibility: Only the read timing changes; the judgment logic and default value (local) remain unchanged, with no impact on non-local discovery modes.
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Local SpringMvc Client Fails to Register
Symptom
When using local discovery mode (shenyu.discovery.type=local), the SpringMvc client fails to complete URI registration.
Root Cause
AbstractContextRefreshedEventListener originally declared isDiscoveryLocalMode as a final member field, initialized once in the constructor via props.getProperty(ShenyuClientConstants.DISCOVERY_LOCAL_MODE_KEY). That discoveryLocalMode property, however, is written into props by ShenyuSpringMvcClientConfiguration before it constructs the SpringMvcClientEventListener bean.
Due to a timing race between bean instantiation and the ContextRefreshedEvent firing—AbstractContextRefreshedEventListener#onApplicationEvent may execute before ShenyuSpringMvcClientConfiguration has finished populating props—the discoveryLocalMode property read at construction time is empty, so isDiscoveryLocalMode is always false. As a result, the local-registration branch inside onApplicationEvent is skipped, and the local SpringMvc client never initiates URI registration.
Solution
Test & Checkstyle Fixes
Scope
Make sure that: