添加测试模块

pull/98/head
youbaokun 5 years ago
parent c3e1562478
commit 528baa4996

@ -224,6 +224,7 @@
<module>ruoyi-modules</module>
<module>ruoyi-api</module>
<module>ruoyi-common</module>
<module>xuexi-parent</module>
</modules>
<packaging>pom</packaging>

@ -0,0 +1,43 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xuexi-parent</artifactId>
<groupId>com.ruoyi</groupId>
<version>2.5.0</version>
</parent>
<artifactId>cloud-common</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<!-- jpa -->
<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.56</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,27 @@
package com.ybk.domain;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity(name = "shop_order")
@Data
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long oid;
private Integer uid;
private String username;
private Integer pid;
private String pname;
private Double pprice;//价格
private String stock; //库存
private Integer number;//购买数量
}

@ -0,0 +1,19 @@
package com.ybk.domain;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity(name = "shop_product")
@Data
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer pid;
private String pname;
private Double pprice;//价格
private String stock; //库存
}

@ -0,0 +1,19 @@
package com.ybk.domain;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity(name = "shop_user")
@Data
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer uid;
private String username;
private String password;
private String telephone;
}

@ -0,0 +1,42 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xuexi-parent</artifactId>
<groupId>com.ruoyi</groupId>
<version>2.5.0</version>
</parent>
<artifactId>cloud-order</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>cloud-common</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,28 @@
package com.ybk;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableDiscoveryClient //开启ribbon
@EnableFeignClients //开启Feign
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

@ -0,0 +1,41 @@
package com.ybk.controller;
import com.ybk.domain.Product;
import com.ybk.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.List;
@RestController
public class OrderController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private ProductService productService;
@RequestMapping(value = "/product/{pid}")
public void order(@PathVariable("pid") Integer pid) {
System.out.println("调用下单服务成功---" + pid);
List<ServiceInstance> instances = discoveryClient.getInstances("servier-product");
// ServiceInstance serviceInstance = instances.get(0);
// Product forObject = restTemplate.getForObject("http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + "/product/" + pid, Product.class);
// System.out.println("查询到商品信息---" + forObject);
//ribbon实现负载均衡
// Product forObject1 = restTemplate.getForObject("http://servier-product/product/" + pid, Product.class);
//System.out.println("查询到商品信息11---" + forObject1);
Product product = productService.findProduct(pid);
System.out.println("查询到商品信息11---" + product);
}
}

@ -0,0 +1,7 @@
package com.ybk.dao;
import com.ybk.domain.Order;
import org.springframework.data.jpa.repository.JpaRepository;
public interface OrderDao extends JpaRepository<Order, Integer> {
}

@ -0,0 +1,4 @@
package com.ybk.service;
public interface OrderService {
}

@ -0,0 +1,14 @@
package com.ybk.service;
import com.ybk.domain.Product;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@FeignClient(value = "servier-product",
fallback = ProductServiceFallback.class)
public interface ProductService {
@RequestMapping("/product/{pid}")
Product findProduct(@PathVariable("pid") Integer pid);
}

@ -0,0 +1,18 @@
package com.ybk.service;
import com.ybk.domain.Product;
import org.springframework.stereotype.Service;
/**
*
*/
@Service
public class ProductServiceFallback implements ProductService{
@Override
public Product findProduct(Integer pid) {
//容错逻辑
Product product = new Product();
return product;
}
}

@ -0,0 +1,8 @@
package com.ybk.service.impl;
import com.ybk.service.OrderService;
import org.springframework.stereotype.Service;
@Service
public class OrderServiceImpl implements OrderService {
}

@ -0,0 +1,24 @@
server:
port: 8091
spring:
application:
name: servier-order
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.50.129:3306/xuexi-parent?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: root
password: root
jpa:
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
cloud:
nacos:
discovery:
server-addr: 192.168.50.129:8848/
servier-product:
ribbon:
NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
feign:
sentinel:
enabled: true

@ -0,0 +1,34 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xuexi-parent</artifactId>
<groupId>com.ruoyi</groupId>
<version>2.5.0</version>
</parent>
<artifactId>cloud-product</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>cloud-common</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,15 @@
package com.ybk;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class);
}
}

@ -0,0 +1,19 @@
package com.ybk.controller;
import com.ybk.domain.Product;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ProductController {
@RequestMapping(value = "/product/{pid}")
public Product product(@PathVariable("pid") Integer pid) {
System.out.println("调用商品服务成功---" + pid);
Product product = new Product();
product.setPid(pid);
product.setPname("测试商品");
return product;
}
}

@ -0,0 +1,8 @@
package com.ybk.dao;
import com.ybk.domain.Product;
import com.ybk.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProductDao extends JpaRepository<Product, Integer> {
}

@ -0,0 +1,4 @@
package com.ybk.service;
public interface ProductService {
}

@ -0,0 +1,8 @@
package com.ybk.service.impl;
import com.ybk.service.ProductService;
import org.springframework.stereotype.Service;
@Service
public class ProductServiceImpl implements ProductService {
}

@ -0,0 +1,18 @@
server:
port: 8081
spring:
application:
name: servier-product
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.50.129:3306/xuexi-parent?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: root
password: root
jpa:
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
cloud:
nacos:
discovery:
server-addr: 192.168.50.129:8848/

@ -0,0 +1,35 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xuexi-parent</artifactId>
<groupId>com.ruoyi</groupId>
<version>2.5.0</version>
</parent>
<artifactId>cloud-user</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>cloud-common</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,15 @@
package com.ybk;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class);
}
}

@ -0,0 +1,7 @@
package com.ybk.controller;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UserController {
}

@ -0,0 +1,7 @@
package com.ybk.dao;
import com.ybk.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserDao extends JpaRepository<User, Integer> {
}

@ -0,0 +1,4 @@
package com.ybk.service;
public interface UserService {
}

@ -0,0 +1,8 @@
package com.ybk.service.impl;
import com.ybk.service.UserService;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
}

@ -0,0 +1,18 @@
server:
port: 8071
spring:
application:
name: servier-user
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.50.129:3306/xuexi-parent?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
username: root
password: root
jpa:
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
cloud:
nacos:
discovery:
server-addr: 192.168.50.129:8848/

@ -0,0 +1,28 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi</artifactId>
<version>2.5.0</version>
</parent>
<artifactId>xuexi-parent</artifactId>
<packaging>pom</packaging>
<!-- 配置聚合 -->
<modules>
<module>cloud-common</module>
<module>cloud-user</module>
<module>cloud-product</module>
<module>cloud-order</module>
</modules>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Loading…
Cancel
Save