Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

4. Service registration & service provider

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Official account: java Paradise

1. What is a service provider

Service provider (Service Provider): refers to the called party of the service (that is, the service that provides services for other services); the service provider, as an Eureka Client, performs service registration, renewal and offline operations to Eureka Server. The main data for registration include service name, machine ip, port number, domain name and so on.

From the diagram to Eureka, there are two service instances, Eureka Server and Eureka Client;, and Eureka Client is divided into two types: Service Provider (service provider) and Service Consumer (service consumer). If you have studied dubbo, you will find that this diagram is similar to the call diagram of dubbo.

2. Create a new meven project

4.0.0 spring-cloud sc-eureka-client-provider 0.0.1-SNAPSHOT jar sc-eureka-client-provider http://maven.apache.org org.springframework.boot spring-boot-starter-parent 2.0.4.RELEASE org.springframework.cloud spring-cloud-dependencies Finchley.RELEASE pom UTF-8 1.8 1.8 org.springframework.cloud spring-cloud-starter-netflix-eureka-client 2.0.1.RELEASE org.springframework.boot Spring-boot-starter-web org.apache.tomcat tomcat-jdbc com.zaxxer HikariCP mysql mysql-connector-java 6. 0.3 org.mybatis mybatis-spring 1.3.2 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2

3. Create a ProviderApplication.java class

Package sc.provider;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication@EnableEurekaClient@MapperScan (basePackages= "sc.provider.dao") public class ProviderApplication {public static void main (String [] args) {SpringApplication.run (ProviderApplication.class, args);}}

Comments for Mybatis MapperScan scan the package where the mapper file is located

4. Create an application.yml file

Server: port: 8200spring: application: name: sc-eureka-client-provider datasource: driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/sc?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8 username: root password: root type: com.zaxxer.hikari.HikariDataSource hikari: minimum-idle: 5 maximum-pool-size: 15 Auto-commit: true idle-timeout: 30000 pool-name: DatebookHikariCP max-lifetime: 1800000 connection-timeout: 30000 connection-test-query: SELECT 1eureka: client: registerWithEureka: true # whether to register yourself with the Eureka service Default is true fetchRegistry: true # whether to obtain registration information from Eureka. Default is true serviceUrl: defaultZone: http://localhost:5001/eureka/mybatis: mapperLocations: classpath:sc/provider/dao/*.xml # configLocation: classpath:mybatis-config.xml

After Spring Cloud 2.x, Hikari data source, a very efficient data source, is used by default.

5. For other related classes that need to be created, please see the following

6. Create the database sc and the corresponding table t_user (sql file in the sql step reference project)

7. Start Eureka, and the corresponding project is sc-eureka-server;, and then start sc-eureka-client-provider

Method 1:

Method 2:

8. Verify whether it is successful

Add:

Query:

List:

Update:

Delete:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report