Skip to content

Fix/fix local springmvc client cant register success#12

Open
hengyuss wants to merge 2 commits into
apache:mainfrom
hengyuss:fix/fix_local_springmvc_client_cant_register_success
Open

Fix/fix local springmvc client cant register success#12
hengyuss wants to merge 2 commits into
apache:mainfrom
hengyuss:fix/fix_local_springmvc_client_cant_register_success

Conversation

@hengyuss

Copy link
Copy Markdown

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

  1. 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.
  2. 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
  • Core change: AbstractContextRefreshedEventListener.java
  • 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.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

hengyuss added 2 commits June 24, 2026 16:07
…xtRefreshedEventListener cause local springmvc client can't register success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant