SOA 框架优缺点
打车系统微服务
微服务结构图
实例
依赖
< parent>
< groupId> org. springframework. boot< / groupId>
< artifactId> spring- boot- starter- parent< / artifactId>
< version> 1.5 .10 . RELEASE< / version>
< relativePath / >
< / parent>
< dependencyManagement>
< dependencies>
< dependency>
< groupId> org. springframework. cloud< / groupId>
< artifactId> spring- cloud- dependencies< / artifactId>
< version> Edgware. SR2< / version>
< type> pom< / type>
< scope> import < / scope>
< / dependency>
< / dependencies>
< / dependencyManagement>
注册中心 appMain
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main ( String[ ] args) {
new SpringApplicationBuilder ( EurekaApplication. class ) . web ( true ) . run ( args) ;
}
}
application.yml
spring:
application:
name: userui
server:
port: 80
eureka:
instance:
hostname: localhost
#注册到注册中心的微服务都是IP地址
preferIpAddress: true
client:
#是否注册到注册中心
registerWithEureka: true
#是否抓取注册中心的注册信息
fetchRegistry: true
serviceUrl:
#微服务和客户端用来注册和发现的地址
defaultZone: http: / / 192.168 .174 .129 : 8761 / eureka/
用户微服务
application.yml
server:
port: 8881
eureka:
instance:
hostname: localhost
#注册到注册中心的微服务都是IP地址
preferIpAddress: true
client:
#是否注册到注册中心
registerWithEureka: true
#是否抓取注册中心的注册信息
fetchRegistry: false
serviceUrl:
#微服务和客户端用来注册和发现的地址
defaultZone: http: / / 192.168 .174 .129 : 8761 / eureka/
spring:
application:
name: ouyang
datasource:
driver- class - name: com. mysql. jdbc. Driver
url: jdbc: mysql: / / 192.168 .0 .250 / school
username: root
password: ps123456
用户微服务pom
<?xml version="1.0" encoding="UTF-8"?>
<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>SpringCloud</artifactId>
<groupId>cn.ps</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>SpringcCloud_UserServer</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!--将依赖一起打包,否则无法运行-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
用户微服务结果类
package cn. ps. entity;
import lombok. Data;
import lombok. NoArgsConstructor;
import java. util. List;
@Data
@NoArgsConstructor
public class Result {
private List data;
private int code;
private String msg;
}
用户微服务结果类
package cn. ps. entity;
import lombok. Data;
import lombok. NoArgsConstructor;
@Data
@NoArgsConstructor
public class Users {
private String userName;
private String sex;
}
用户微服务Mapper
package cn. ps;
import org. springframework. boot. autoconfigure. SpringBootApplication;
import org. springframework. boot. builder. SpringApplicationBuilder;
import org. springframework. cloud. netflix. eureka. EnableEurekaClient;
import org. springframework. web. bind. annotation. GetMapping;
import org. springframework. web. bind. annotation. RestController;
@SpringBootApplication
@EnableEurekaClient
@RestController
package cn. ps. mapper;
import cn. ps. entity. Users;
import com. baomidou. mybatisplus. core. mapper. BaseMapper;
import org. apache. ibatis. annotations. Mapper;
import org. apache. ibatis. annotations. Param;
import org. apache. ibatis. annotations. Select;
import java. util. List;
@Mapper
public interface UsersMapper extends BaseMapper {
@Select ( "select * from users where userName=#{userName} and sex=#{sex}" )
public List< Users> query ( @Param ( "userName" ) String userName, @Param ( "sex" ) String sex) ;
}
用户操作界面
登陆界面
< font size= "5" color= "990000" > 请登录< / font> < hr>
< form name= “frmManage” method= "post"
action= "rlogin" >
< font size= "3" color= "990000" >
< label> 姓& nbsp; & nbsp; 名< / label>
< input type= "text" name= "userName" > < br>
< label> 性& nbsp; & nbsp; 别< / label>
< input type= "text" name= "sex" > < br>
< input type= "submit" value= "登录" / >
< / font>
< / form>
打包
<!--将依赖一起打包,否则不会加依赖,无法运行-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
docker 运行
java - jar jar包名 运行jar项目
netstat - aon | gind '端口号' 查看端口被占用的进程
监控界面,查看已注册微服务
url 输入localhost:8761