标签:string with 其他 自我保护 project 维护 directory cloud conf
// pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.noodles.springcloud</groupId>
<artifactId>microservicecloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>microservicecloud-eureka-7001</artifactId>
<dependencies>
<!-- eureka-server 服务端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<!-- 修改后立即生效,热部署 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
</project>
// application.yml
server:
port: 7001
eureka:
instance:
hostname: localhost #eureka服务端的实例名称
client:
register-with-eureka: false # false 表示不向注册中心注册自己
fetch-registry: false # false 表示自己就是注册中心,职责是维护服务实例,并不需要检索服务
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
#设置与Eureka Server交互的地址,查询和注册服务都需要依赖这个地址
// com.noodles.springcloud
// EurekaServer7001_App
@SpringBootApplication
@EnableEurekaServer // EurekaServer 服务器端启动类,接收其他微服务注册进来
public class EurekaServer7001_App {
public static void main(String[] args) {
SpringApplication.run(EurekaServer7001_App.class, args);
}
}
// 测试
// 访问: http://localhost:7001
// 修改microservicecloud-provider-dept-8001
// pom.xml 增加
<!-- 将微服务provider 注册进 eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
// application.yml 增加
eureka:
client: # 客户端注册进eureka服务列表内
service-url:
defaultZone: http://localhost:7001/eureka
// DeptProvider8001_App 主启动类
@SpringBootApplication
@EnableEurekaClient // 本服务启动后,自动注册进eureka服务中
public class DeptProvider8001_App {
public static void main(String[] args) {
SpringApplication.run(DeptProvider8001_App.class, args);
}
}
// 测试
// 先要启动 EurekaServer,然后启动 DeptProvicer8001_App
// 访问:http://localhost:7001/
// 主机映射名称修改
// 修改microservicecloud-provider-dept-8001
// application.xml
eureka:
client: # 客户端注册进eureka服务列表内
service-url:
defaultZone: http://localhost:7001/eureka
instance:
instance-id: microservicecloud-dept8001 # 主机映射名称
// 访问信息有IP信息提示
// 修改microservicecloud-provider-dept-8001
// application.xml
eureka:
client: # 客户端注册进eureka服务列表内
service-url:
defaultZone: http://localhost:7001/eureka
instance:
instance-id: microservicecloud-dept8001 # 主机映射名称
prefer-ip-address: true # 访问路径可以显示IP地址
// 微服务info内容详细信息
// 修改microservicecloud-provider-dept-8001
// pom.xml
<!-- actutator 监控信息完善 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
// 修改父工程 microservicecloud
// pom.xml
<!-- dependencyManagement -->
<build>
<finalName>microservicecloud</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<delimiters>
<delimit>$</delimit>
</delimiters>
</configuration>
</plugin>
</plugins>
</build>
<!-- modules -->
// 修改microservicecloud-provider-dept-8001
// application.yml
info:
app.name: noodles-microservicecloud
company.name: www.google.com
build.artifactId: $project.artifactId$
build.version: $project.version$
// 修改 microservicecloud-eureka-7001
// 将自我保护机制关闭(不推荐)
// application.yml
eureka:
server:
enable-self-preservation: false
参考资料:
标签:string with 其他 自我保护 project 维护 directory cloud conf
原文地址:https://www.cnblogs.com/linkworld/p/9189744.html