SpringCloud-Discovery
1.Eurekaの設定
server:
port: 8761
spring:
application:
name: discoveryservice
eureka:
client:
register-with-eureka: false
fetch-registry: false
package com.example.discoveryservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryserviceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryserviceApplication.class, args);
}
}
2.ユーザー-サービス設定
server:
port: 8081
spring:
application:
name: user-service
eureka:
client:
register-with-eureka: true # 유레카에 등록할 할거다
fetch-registry: true # 외부에서 검색 가능하게 할거다
service-url: # 유레카 서버 위치가 어디인지 지정
defaultZone: http://127.0.0.1:8761/eureka
package com.example.userservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class UserServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UserServiceApplication.class, args);
}
}
-Dserver.port=8082
mvn spring-boot:run -Dspring-boot.run.jvmArguments='-Dserver.port=9003'
cmd
server:
port: 0 # 랜덤 포트로 하겠다.
spring:
application:
name: user-service
eureka:
instance:
instance-id: ${spring.cloud.client.hostname}:${spring.cloud.instance_id:${random.value}}
client:
register-with-eureka: true # 유레카에 등록할 할거다
fetch-registry: true # 외부에서 검색 가능하게 할거다
service-url: # 유레카 서버 위치가 어디인지 지정
defaultZone: http://127.0.0.1:8761/eureka
mvn clean(ターゲットを削除)mvn compile package(コンパイル後にパッケージを生成)
構築に成功したらjarファイルを作成
JAr実行:java-jar-DServer.port=9004 ./target/user-service-0.0.1-SNAPSHOT.jar
Reference
この問題について(SpringCloud-Discovery), 我々は、より多くの情報をここで見つけました https://velog.io/@jae_cheol/SpringCloud-Discoveryテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol