Now has successfully implemented a Eureeka service startup and micro-service registration configuration operations, but now the program has a problem, your own company's Eureka Service should be able to register the service can only be satisfied with the certification requirements of the micro-services, All this comes before the Eureka inside the configuration is missing a critical step: Security authentication, so the Eureka should be configured on a secure authentication process.
"microcloud-eureka-7001" modifies the Pom.xml configuration file, introducing the Springsecurity dependency package.
<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" >
<parent>
<artifactId>microcloud</artifactId>
<groupId>com.gwolf</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.gwolf</groupId>
<artifactId>microcloud-eureka-7001</artifactId>
<packaging>jar </packaging>
<name>microcloud-eureka-7001</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
</project>
-
"microcloud-eureka-7001" Once the security development package has been imported into our project, Every time the micro-service is started automatically generate a password, and this password because it will change, so generally do not use, so to modify the Application.yml configuration file, append password configuration items.
Server:
port:7001
Eureka:
instance: #eureka实例定义
hostname : eureka-7001.com #设置清理的间隔时间, the default time to use a single unit of milliseconds (default is 60 seconds)
client: #客户端进行Eureka注册的配置
SERVICE-URL:&NBSP
Defaultzone:http://eureka-7001.com:7001/eureka
Register-with-eureka:false #当前的微服务不注册到eureka之中
Fetch-registry:false
Server:
Enable-self-preservation:false #是否要设置成保护模式
eviction-interval-timer-in-ms:60000 #不通过eureka获取注册信息
Spring:
application:
name:microcloud-eureka-7001
Security:
User:
Name:eureka
Password:eureka
-
Access Eureka at this time the service address is: http://eureka:[email protected]:7001/, Requires a user name and password to be entered.
-
"microcloud-eureka-7001" all of the places registered to the Eureka Service are prefixed with a username and password.
Server:
port:7001
Eureka:
instance: #eureka实例定义
hostname : eureka-7001.com #设置清理的间隔时间, the default time to use a single unit of milliseconds (default is 60 seconds)
client: #客户端进行Eureka注册的配置
service-url:
DEFAULTZONE:HTTP://EUREKA:[EMAIL&NBSP;PROTECTED]:7001/ Eureka
Register-with-eureka:false #当前的微服务不注册到eureka之中
Fetch-registry:false
Server:
Enable-self-preservation:false #是否要设置成保护模式
eviction-interval-timer-in-ms:60000 #不通过eureka获取注册信息
Spring:
Application:
name:microcloud-eureka-7001
Security:
User:
Name:eureka
Password:eureka
"microcloud-provider-dept-8001" modifies the APPLICATION.YML configuration file for authorization configuration.
Server
port:8001
MyBatis
Config-location:classpath:mybatis/mybatis.cfg.xml # mybatis configuration file location path
TYPE-ALIASES-PACKAGE:COM.GWOLF.VO # defines the package for all Operation class aliases
Mapper-locations: # All Mapper mapping files
-Classpath:mybatis/mapper/**/*.xml
Spring
DataSource
Type:com.alibaba.druid.pool.DruidDataSource # Configuring the type of operation for the data source currently being used
Driver-class-name:com.mysql.cj.jdbc.driver # Configuring the MySQL driver class
URL:JDBC:MYSQL://LOCALHOST:3306/MLDN_1?SERVERTIMEZONE=UTC # Database Connection address
Username:root # Database User name
Password:root # Database Connection password
DBCP2: # Database Connection Pool configuration
Min-idle:5 # Minimum number of maintenance connections for the database connection pool
Initial-size:5 # Initialization of the number of connections provided
Max-total:5 # Maximum number of connections
MAX-WAIT-MILLIS:200 # The maximum timeout time to wait for a connection to get
Application:
Name:microcloud-provider-dept
Eureka
Client: #客户端进行Eureka注册的配置
Service-url:
Defaultzone:http://eureka:[email Protected]:7001/eureka
Instance
Instance-id:dept-8001.com #在信息列表中显示主机名称
Prefer-ip-address:true #访问的路径变为IP地址
Lease-renewal-interval-in-seconds:2 #设置心跳的时间间隔 (default is 30 seconds)
Lease-expiration-duration-in-seconds:5 #如果现在超过了5秒的间隔 (default 90 seconds)
Info
App.name:gwolf-microcloud
Company.name:www.gwolf.com
Build.artifactid: $project. artifactid$
Build.version: $project. version$
Start the Eureka Registration service and departmental microservices to see if the microservices are registered successfully after security authentication.