|
@@ -12,6 +12,8 @@ import org.springframework.boot.context.ApplicationPidFileWriter;
|
|
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.net.InetAddress;
|
|
|
+import java.net.UnknownHostException;
|
|
|
|
|
|
/*import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
import org.springframework.cloud.openfeign.EnableFeignClients;*/
|
|
@@ -36,9 +38,13 @@ public class ShopApiApplication extends SpringBootServletInitializer {
|
|
|
@Value("${spring.application.name}")
|
|
|
private String applicationName;
|
|
|
|
|
|
+ @Value("${nacos.discovery.register.group-name}")
|
|
|
+ private String groupName;
|
|
|
+
|
|
|
@PostConstruct
|
|
|
- public void registerInstance() throws NacosException {
|
|
|
- namingService.registerInstance(applicationName, "127.0.0.1", serverPort);
|
|
|
+ public void registerInstance() throws NacosException, UnknownHostException {
|
|
|
+ InetAddress address = InetAddress.getLocalHost();
|
|
|
+ namingService.registerInstance(applicationName, groupName,address.getHostAddress(), serverPort);
|
|
|
}
|
|
|
|
|
|
@Override
|