spring-cloud eureka客户端不注册。spring-cloud搭建的项目,一个是eureka的服务端,然后另一个是服务提供者。但是这个服务提供者不注册。
配置文件如下:
eureka服务:pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.hydrakyoufeng</groupId>
<artifactId>hydrakyoufeng-sc</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>hydrakyoufeng-eureka</artifactId>
<name>hydrakyoufeng-eureka</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- eureka服务器 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
</dependency>
<!-- 容器,加上后euraka才能启动 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<!-- 安全依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
</project>
eureka服务的application.yml:
server:
#端口号 eureka服务器端口
port: 8083
spring:
application:
name: eureka
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/ci?serverTimezone=PRC&characterEncoding=utf-8&useSSL=true
username: xxx
password: xxx
maxActive: 20
maxIdle: 10
maxWaitMillis: -1
initialSize: 5
#main:
#allow-bean-definition-overriding: true
security: # 密码配置2.1之后这样配置
user:
name: Hydra
password: 19861213hkf
eureka:
client:
# 下面两个是非集群的配置
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://Hydra:19861213hkf@127.0.0.1:8083/eureka
#默认的访问风格(未设置用户名和密码时)
#defaultZone: http://localhost:8083/eureka/
然后是服务提供者(provider)的pom.xml:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<artifactId>hydrakyoufeng-provider</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>org.hydrakyoufeng</groupId>
<artifactId>hydrakyoufeng-sc</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<name>hydrakyoufeng-provider</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
</project>
然后是服务提供者(provider)的application.yml:
server:
#端口号 eureka服务器端口
port: 8083
spring:
application:
name: eureka
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/ci?serverTimezone=PRC&characterEncoding=utf-8&useSSL=true
username: xxx
password: xxxxx
maxActive: 20
maxIdle: 10
maxWaitMillis: -1
initialSize: 5
#main:
#allow-bean-definition-overriding: true
security: # 密码配置2.1之后这样配置
user:
name: Hydra
password: 19861213hkf
eureka:
client:
# 下面两个是非集群的配置
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://Hydra:19861213hkf@127.0.0.1:8083/eureka
#默认的访问风格(未设置用户名和密码时)
#defaultZone: http://localhost:8083/eureka/
两个都启动后,
然后开打127.0.0.1:8083/eureka 输入用户名和密码,界面如下(看不到注册的提供者):
最后是我两个app的启动类:
@SpringBootApplication
@EnableEurekaServer
public class EurekaStart {
public static void main(String[] args) {
SpringApplication.run(EurekaStart.class);
}
}
@EnableEurekaClient
@SpringBootApplication
@MapperScan("org.hydrakyoufeng.provider")
public class ProviderStart {
/**
* 启动j2se的springboot
* @param args
*/
public static void main(String[] args) {
SpringApplication.run(ProviderStart.class);
}
}
// 刚才代码贴掉了,这两个注解我是加了的。
我的提供者无法完成注册,日志没有任何注册相关的消息,也没有任何异常打印。