mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #1384 from theonefx/master
fix issue: https://github.com/alibaba/spring-cloud-alibaba/issues/1383
This commit is contained in:
commit
0c39f71316
51
pom.xml
51
pom.xml
@ -349,6 +349,31 @@
|
|||||||
<reuseForks>false</reuseForks>
|
<reuseForks>false</reuseForks>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>flatten-maven-plugin</artifactId>
|
||||||
|
<version>${flatten-maven-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<updatePomFile>true</updatePomFile>
|
||||||
|
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>flatten</id>
|
||||||
|
<phase>process-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>flatten</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>flatten.clean</id>
|
||||||
|
<phase>clean</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>clean</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@ -406,32 +431,6 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>flatten-maven-plugin</artifactId>
|
|
||||||
<version>${flatten-maven-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<updatePomFile>true</updatePomFile>
|
|
||||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>flatten</id>
|
|
||||||
<phase>process-resources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>flatten</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>flatten.clean</id>
|
|
||||||
<phase>clean</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>clean</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@ -76,12 +76,17 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
|||||||
|
|
||||||
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
|
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
|
||||||
public Object getPort(ProceedingJoinPoint pjp) throws Throwable {
|
public Object getPort(ProceedingJoinPoint pjp) throws Throwable {
|
||||||
|
/**
|
||||||
|
* move setServerPort from onApplicationStarted() to here for this issue :
|
||||||
|
* https://github.com/alibaba/spring-cloud-alibaba/issues/1383
|
||||||
|
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||||
|
*/
|
||||||
|
setServerPort();
|
||||||
return serverPort != null ? serverPort : pjp.proceed();
|
return serverPort != null ? serverPort : pjp.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationStartedEvent.class)
|
@EventListener(ApplicationStartedEvent.class)
|
||||||
public void onApplicationStarted() {
|
public void onApplicationStarted() {
|
||||||
setServerPort();
|
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,10 +103,12 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
|||||||
* protocol is present.
|
* protocol is present.
|
||||||
*/
|
*/
|
||||||
private void setServerPort() {
|
private void setServerPort() {
|
||||||
|
if (serverPort == null) {
|
||||||
|
synchronized (DubboServiceRegistrationNonWebApplicationAutoConfiguration.class) {
|
||||||
if (serverPort == null) {
|
if (serverPort == null) {
|
||||||
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
||||||
urls.stream()
|
urls.stream().filter(
|
||||||
.filter(url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
||||||
.findFirst().ifPresent(url -> {
|
.findFirst().ifPresent(url -> {
|
||||||
serverPort = url.getPort();
|
serverPort = url.getPort();
|
||||||
});
|
});
|
||||||
@ -115,6 +122,8 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnBean(name = ZOOKEEPER_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME)
|
@ConditionalOnBean(name = ZOOKEEPER_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME)
|
||||||
@ -126,6 +135,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
|||||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||||
public void onServiceInstancePreRegistered(
|
public void onServiceInstancePreRegistered(
|
||||||
ServiceInstancePreRegisteredEvent event) {
|
ServiceInstancePreRegisteredEvent event) {
|
||||||
|
setServerPort();
|
||||||
registration.setPort(serverPort);
|
registration.setPort(serverPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user