@@ -269,9 +269,12 @@ public void checkAndUpdateSubConfigs() {
269269 // Config Center should always being started first.
270270 startConfigCenter ();
271271 checkDefault ();
272- checkApplication ();
273- checkRegistry ();
274272 checkProtocol ();
273+ checkApplication ();
274+ // if protocol is not injvm checkRegistry
275+ if (!isOnlyInJvm ()) {
276+ checkRegistry ();
277+ }
275278 this .refresh ();
276279 checkMetadataReport ();
277280
@@ -327,6 +330,15 @@ public void checkAndUpdateSubConfigs() {
327330 checkMock (interfaceClass );
328331 }
329332
333+ /**
334+ * Determine if it is injvm
335+ *
336+ * @return
337+ */
338+ private boolean isOnlyInJvm () {
339+ return getProtocols ().size () == 1 && Constants .LOCAL_PROTOCOL .equalsIgnoreCase (getProtocols ().get (0 ).getName ());
340+ }
341+
330342 public synchronized void export () {
331343 checkAndUpdateSubConfigs ();
332344
@@ -539,11 +551,15 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
539551 }
540552 // export to remote if the config is not local (export to local only when config is local)
541553 if (!Constants .SCOPE_LOCAL .equalsIgnoreCase (scope )) {
542- if (logger .isInfoEnabled ()) {
554+ if (! isOnlyInJvm () && logger .isInfoEnabled ()) {
543555 logger .info ("Export dubbo service " + interfaceClass .getName () + " to url " + url );
544556 }
545557 if (CollectionUtils .isNotEmpty (registryURLs )) {
546558 for (URL registryURL : registryURLs ) {
559+ //if protocol is only injvm ,not register
560+ if (Constants .LOCAL_PROTOCOL .equalsIgnoreCase (url .getProtocol ())) {
561+ continue ;
562+ }
547563 url = url .addParameterIfAbsent (Constants .DYNAMIC_KEY , registryURL .getParameter (Constants .DYNAMIC_KEY ));
548564 URL monitorUrl = loadMonitor (registryURL );
549565 if (monitorUrl != null ) {
@@ -586,18 +602,19 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
586602 }
587603
588604 @ SuppressWarnings ({"unchecked" , "rawtypes" })
605+ /**
606+ * always export injvm
607+ */
589608 private void exportLocal (URL url ) {
590- if (!Constants .LOCAL_PROTOCOL .equalsIgnoreCase (url .getProtocol ())) {
591- URL local = URLBuilder .from (url )
592- .setProtocol (Constants .LOCAL_PROTOCOL )
593- .setHost (LOCALHOST_VALUE )
594- .setPort (0 )
595- .build ();
596- Exporter <?> exporter = protocol .export (
597- proxyFactory .getInvoker (ref , (Class ) interfaceClass , local ));
598- exporters .add (exporter );
599- logger .info ("Export dubbo service " + interfaceClass .getName () + " to local registry" );
600- }
609+ URL local = URLBuilder .from (url )
610+ .setProtocol (Constants .LOCAL_PROTOCOL )
611+ .setHost (LOCALHOST_VALUE )
612+ .setPort (0 )
613+ .build ();
614+ Exporter <?> exporter = protocol .export (
615+ proxyFactory .getInvoker (ref , (Class ) interfaceClass , local ));
616+ exporters .add (exporter );
617+ logger .info ("Export dubbo service " + interfaceClass .getName () + " to local registry url : " + local );
601618 }
602619
603620 private Optional <String > getContextPath (ProtocolConfig protocolConfig ) {
@@ -803,7 +820,7 @@ private void createProviderIfAbsent() {
803820 if (provider != null ) {
804821 return ;
805822 }
806- setProvider (
823+ setProvider (
807824 ConfigManager .getInstance ()
808825 .getDefaultProvider ()
809826 .orElseGet (() -> {
@@ -834,15 +851,15 @@ private void convertProtocolIdsToProtocols() {
834851
835852 if (StringUtils .isEmpty (protocolIds )) {
836853 if (CollectionUtils .isEmpty (protocols )) {
837- setProtocols (
838- ConfigManager .getInstance ().getDefaultProtocols ()
839- .filter (CollectionUtils ::isNotEmpty )
840- .orElseGet (() -> {
841- ProtocolConfig protocolConfig = new ProtocolConfig ();
842- protocolConfig .refresh ();
843- return new ArrayList <>(Arrays .asList (protocolConfig ));
844- })
845- );
854+ setProtocols (
855+ ConfigManager .getInstance ().getDefaultProtocols ()
856+ .filter (CollectionUtils ::isNotEmpty )
857+ .orElseGet (() -> {
858+ ProtocolConfig protocolConfig = new ProtocolConfig ();
859+ protocolConfig .refresh ();
860+ return new ArrayList <>(Arrays .asList (protocolConfig ));
861+ })
862+ );
846863 }
847864 } else {
848865 String [] arr = Constants .COMMA_SPLIT_PATTERN .split (protocolIds );
0 commit comments