Modify microservicecloud-provider-dept-8001
1. Modify pom
add content
<!-- 将微服务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>
Complete content
<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.atguigu.springcloud</groupId> <artifactId>microservicecloud</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>microservicecloud-provider-dept-8001</artifactId> < The Dependencies > <-! Introduction of generic api own custom package, you can use Dept department the Entity -> < dependency > < groupId > com.atguigu.springcloud </ groupId > < artifactId > microservicecloud-api </ artifactId > < Version > $ {project.version} </ Version > </ dependency > <-! micro registered into the service provider side Eureka -> < dependency > < the 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> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</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> </dependency> <!-- 修改后立即生效,热部署 --> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> </dependencies> </project>
2 Modify yml
Content
eureka:
client: # client registration into the list of services within eureka
service-url:
defaultZone: http://localhost:7001/eureka
Full content
server:
port: 8001
mybatis:
config-location: classpath: mybatis / mybatis.cfg.xml # mybatis configuration path to the file
type-aliases-package: com.atguigu.springcloud.entities # Entity alias classes where all packages
mapper-locations:
- classpath:. Mybatis / mapper / ** / * xml # mapper mapping file
spring:
application:
name: microservicecloud-dept
datasource:
type: com.alibaba.druid.pool.DruidDataSource # type of the current data source operand
driver-class-name: org.gjt.mm.mysql.Driver # mysql driver package
url: jdbc: mysql: // localhost: 3306 / cloudDB01 # database name
username: root
password: 123456
dbcp2:
min-idle: 5 # database connection pool maintained the minimum number of connections
initial-size: 5 # initialization connections
max-total: 5 # maximum number of connections
max-wait-millis: 200 # maximum wait for a connection timeout acquired
eureka:
client: # client registration into the list of services within eureka
service-url:
defaultZone: http://localhost:7001/eureka
3.DeptProvider8001_App main startup class
package com.atguigu.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient // After this service starts automatically registered into the eureka service public class DeptProvider8001_App { public static void main(String[] args) { SpringApplication.run(DeptProvider8001_App.class, args); } }
4. Test
First to start EurekaServer
http://localhost:7001/
Micro-service registered name Configuration Description