pom.xml
<?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>
<groupId>com.qf</groupId>
<artifactId>shop_web</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
一、shop_user
1.shop_user
package com.qf.user_web;
import com.github.tobato.fastdfs.FdfsClientConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.EnableMBeanExport;
import org.springframework.context.annotation.Import;
import org.springframework.jmx.support.RegistrationPolicy;
@Import(FdfsClientConfig.class)
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@SpringBootApplication(scanBasePackages = "com.qf",exclude = DataSourceAutoConfiguration.class)
public class UserWebApplication {
public static void main(String[] args) {
SpringApplication.run(UserWebApplication.class, args);
}
}
2.controller
2.1 UserController
package com.qf.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.qf.common.entity.ResultEntity;
import com.qf.entity.User;
import com.qf.service.IUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* @Author: wenchaowen
* @Date: 2020/3/30 0030 15:16
* @Descripton:
*/
@Controller
@RequestMapping(value = "/user")
public class UserController {
@Reference
private IUserService userService;
/**
* 查找所有用户进行分页
* @param page
* @param map
* @return
*/
@RequestMapping(value = "/getUserPage")
public String getUserPage(Page<User> page, ModelMap map){
page = userService.getDubboPage(page);
map.put("url","user/getUserPage");
map.put("page",page);
return "user/userList";
}
/**
* 添加用户
* @param user
* @return
*/
@RequestMapping(value = "/addUser")
@ResponseBody
public ResultEntity addUser(User user){
int insert = userService.insert(user);
if (insert > 0){
return ResultEntity.SUCCESS();
}else {
return ResultEntity.FALL();
}
}
/**
* 根据id查找用户信息
* @param id
* @param map
* @return
*/
@RequestMapping(value = "/getUserById/{id}")
public String getUserById(@PathVariable Integer id,ModelMap map){
User user = userService.selectById(id);
map.put("user",user);
return "user/updateUser";
}
/**
* 修改用户信息
* @param user
* @return
*/
@RequestMapping(value = "/updateUser")
@ResponseBody
public ResultEntity updateUser(User user){
int update = userService.update(user);
if (update > 0){
return ResultEntity.SUCCESS();
}else {
return ResultEntity.FALL();
}
}
/**
* 根据id删除用户
* @param id
* @return
*/
@RequestMapping(value = "/deleteUserById/{id}")
@ResponseBody
public ResultEntity deleteUserById(@PathVariable Integer id){
int delete = userService.deleteById(id);
if (delete > 0){
return ResultEntity.SUCCESS();
}else {
return ResultEntity.FALL();
}
}
/**
* 批量删除
* @param ids
* @return
*/
@RequestMapping(value = "/batchDel")
@ResponseBody
public ResultEntity batchDel(@RequestParam("ids[]") List<Integer> ids){
System.out.println("ids = " + ids);
int deletes = userService.batchDel(ids);
System.out.println("deletes = " + deletes);
if (deletes > 0){
System.out.println(ResultEntity.SUCCESS());
return ResultEntity.SUCCESS();
}else {
System.out.println(ResultEntity.FALL());
return ResultEntity.FALL();
}
}
/**
* 根据用户名或者邮箱进行模糊查询
* @param page
* @param map
* @param username
* @param email
* @return
*/
@RequestMapping(value = "/selectUserEmailName")
public String selectUserEmailName(Page<User> page,ModelMap map,@RequestParam("username") String username,@RequestParam("email") String email){
//条件查询
EntityWrapper<User> ew = new EntityWrapper<User>();
if (username != null && username != "" && !username.equals("undefined")){
ew.like("username",username);
if (email != null && email != "" && !email.equals("undefined")){
ew.in("email",email);
page = userService.getUserNameEmailPage(page,ew,username,email);
}else{
page = userService.getUserNameEmailPage(page,ew,username,null);;
}
}else {
if (email != null && email != "" && !email.equals("undefined")){
ew.like("email",email);
page = userService.getUserNameEmailPage(page,ew,null,email);
}
}
map.put("username",username);
map.put("email",email);
map.put("page",page);
map.put("url","user/selectUserEmailName");
return "user/userList";
}
}
2.2 GoodController
package com.qf.controller;
import com.alibaba.dubbo.common.utils.IOUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.qf.common.entity.ResultEntity;
import com.qf.entity.Goods;
import com.qf.service.IGoodsService;
import com.qf.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* @Author: wenchaowen
* @Date: 2020/3/31 0031 21:26
* @Descripton:
*/
@Controller
@RequestMapping(value = "/goods")
public class GoodsController {
//图片的访问路径
//private String reqImgPath = "http://localhost:8080/upload/";
@Value("${upload.FdfsPath}")
private String FdfsPath;
//图片存在路径的目录
//private String uploadOpsPath = "E:\\ideaItemSet\\SpringDubbo\\1911_shop\\shop_web\\user_web\\src\\main\\resources\\static\\upload";
@Autowired
private FastFileStorageClient client;
@Reference
private IGoodsService goodsService;
@Reference
private ISearchService searchService;
/**
* 查找所有商品
* @param page
* @param map
* @return
*/
@RequestMapping(value = "/getGoodsPage")
public String getGoodsPage(Page<Goods> page, ModelMap map){
page = goodsService.getDubboPage(page);
map.put("page",page);
map.put("url","goods/getGoodsPage");
return "goods/goodsList";
}
/**
* 图片的存储
* @param file
* @return
*/
@RequestMapping(value = "/uploadFile")
@ResponseBody
public String uploadFile(MultipartFile file){
String fileName = file.getOriginalFilename();
String fileExtName = fileName.substring(fileName.lastIndexOf(".")+1); //文件后缀
StorePath storePath = null;
try {
storePath = client.uploadImageAndCrtThumbImage(file.getInputStream(), file.getSize(), fileExtName, null);
} catch (IOException e) {
e.printStackTrace();
}
/**
* opsFile.getAbsolutePath() 绝对路径
* file.getOriginalFilename() 图片名
*/
return FdfsPath+storePath.getFullPath();
}
/**
* 添加商品
* @param goods
* @return
*/
@RequestMapping(value = "/addGoods")
@ResponseBody
public ResultEntity addGoods(Goods goods){
//1.把商品添加到数据库
int insert = goodsService.insert(goods);
if (insert > 0){
return ResultEntity.SUCCESS();
}else{
return ResultEntity.FALL();
}
}
/**
* 删除单个商品
* @param id
* @return
*/
@RequestMapping(value = "/deleteGoodsById/{id}")
@ResponseBody
public ResultEntity deleteGoodsById(@PathVariable Integer id){
int delete = goodsService.deleteById(id);
if (delete > 0){
return ResultEntity.SUCCESS();
}else {
return ResultEntity.FALL();
}
}
/**
* 批量删除商品
* @param ids
* @return
*/
@RequestMapping(value = "/batchDel")
@ResponseBody
public ResultEntity batchDel(@RequestParam("ids[]") List<Integer> ids){
int deletes = goodsService.batchDel(ids);
if (deletes > 0){
return ResultEntity.SUCCESS();
}else {
return ResultEntity.FALL();
}
}
/**
* 查询单个商品信息
* @param id
* @param map
* @return
*/
@RequestMapping(value = "/getGoodsById/{id}")
public String getGoodsById(@PathVariable Integer id,ModelMap map){
Goods goods = goodsService.selectById(id);
System.out.println("goods = " + goods);
map.put("goods",goods);
return "goods/updateGoods";
}
/**
* 修改商品信息
* @param goods
* @return
*/
@RequestMapping(value = "/updateGoods")
@ResponseBody
public ResultEntity updateGoods(Goods goods){
System.out.println("goods = " + goods);
int update = goodsService.update(goods);
System.out.println("update = " + update);
if (update > 0){
return ResultEntity.SUCCESS();
}else {
return ResultEntity.FALL();
}
}
/**
* 根据商品名称模糊查询
* @param page
* @param map
* @param gname
* @return
*/
@RequestMapping(value = "/selectGoodsName")
public String selectGoodsName(Page<Goods> page, ModelMap map, @RequestParam("username") String gname){
System.out.println("gname = " + gname);
//条件查询
EntityWrapper<Goods> ew = new EntityWrapper<>();
ew.like("gname",gname);
System.out.println("ew = " + ew);
page = goodsService.getGoodsNamePage(page,ew);
System.out.println("page = " + page);
map.put("usrname",gname);
map.put("page",page);
map.put("url","goods/selectGoodsName");
return "goods/goodsList";
}
}
3.config
package com.qf.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @Author: wenchaowen
* @Date: 2020/3/30 0030 20:43
* @Descripton:
*/
@Configuration
public class WebMVCConfig implements WebMvcConfigurer {
/**
* 进行页面的跳转
* @param registry
*/
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("user/toAddUser").setViewName("user/addUser");
registry.addViewController("goods/toAddGoods").setViewName("goods/addGoods");
}
}
application.yml
dubbo:
application:
name: user_web
registry:
address: zookeeper://101.37.175.1:2181
consumer:
check: false
retries: 3
spring:
thymeleaf:
cache: false
prefix: classpath:/templates/
mvc:
static-path-pattern: /**
view:
prefix: /templates/
#自己定义的图片访问路径
upload:
FdfsPath: http://101.37.175.1:8080/
#FastDFS设置
fdfs:
tracker-list:
- 101.37.175.1:22122
connect-timeout: 2000
so-timeout: 2000
thumb-image:
width: 300
height: 300
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.qf</groupId>
<artifactId>user_web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>user_web</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.qf</groupId>
<artifactId>shop_service_api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>com.qf</groupId>
<artifactId>shop_common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.1-RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
二、seach_servcie
1.seach_service
package com.qf.shop_search;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(scanBasePackages = "com.qf",exclude = DataSourceAutoConfiguration.class)
public class ShopSearchApplication {
public static void main(String[] args) {
SpringApplication.run(ShopSearchApplication.class, args);
}
}
2. controller
package com.qf.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.plugins.Page;
import com.qf.entity.Goods;
import com.qf.service.ISearchService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* @Author: wenchaowen
* @Date: 2020/4/8 0008 9:56
* @Descripton:
*/
@Controller
@RequestMapping(value = "/search")
public class SearchController {
@Reference
private ISearchService searchService;
@RequestMapping(value = "/searchGoods")
public String searchGoods(Page<Goods> page,String key, ModelMap map){
System.out.println("key = " + key);
List<Goods> goodsList = searchService.searchGoodsListByKey(key);
System.out.println("goodsList = " + goodsList);
map.put("goodsList",goodsList);
map.put("page",page);
map.put("url","/search/searchGoods");
return "searchGoodsList";
}
}
application.yml
server:
port: 8082
dubbo:
application:
name: shop_search
registry:
address: zookeeper://101.37.175.1:2181
check: false
consumer:
check: false
retries: 3
spring:
thymeleaf:
cache: false
prefix: classpath:/templates/
mvc:
static-path-pattern: /**
view:
prefix: /templates/
rabbitmq:
host: 101.37.175.1
virtual-host: /
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.qf</groupId>
<artifactId>shop_search</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>shop_search</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.qf</groupId>
<artifactId>shop_service_api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
三、shop_item
1. shop_item
package com.qf.shop_item;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(scanBasePackages = "com.qf",exclude = DataSourceAutoConfiguration.class)
public class ShopItemApplication {
public static void main(String[] args) {
SpringApplication.run(ShopItemApplication.class, args);
}
}
2.controller
package com.qf.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.qf.entity.Goods;
import com.qf.service.IGoodsService;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: wenchaowen
* @Date: 2020/4/9 0009 19:30
* @Descripton:
*/
@Controller
@RequestMapping(value = "/item")
public class ItemController {
@Reference
private IGoodsService goodsService;
@Autowired
private Configuration configuration;
@RequestMapping(value = "/createHtml")
@ResponseBody
public String createGoodsHtml(Integer gid){
//1.先根据id查询商品信息
Goods goods = goodsService.selectById(gid);
//2.图片的集合
String[] split = goods.getGpic().split("\\|");
System.out.println("split = " + Arrays.toString(split));
//把数据放到map中
Map<String, Object> map = new HashMap<>();
map.put("goods", goods);
map.put("picList", split);
map.put("contextPath", "/");
Template template = null;
Writer writer = null;
try {
//3.得到模板
template = configuration.getTemplate("goodsItem.ftl");
//4.设置静态页面输出的目录
String staticPath = ItemController.class.getClassLoader().getResource("static").getPath();
File file = new File(staticPath + File.separator + "goods");
//不存在创建目录
if (!file.exists()) {
file.mkdir();
}
//生成页面
writer = new FileWriter(file.getAbsolutePath() + File.separator + gid + ".html");
template.process(map, writer);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
} finally {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return "ok";
}
}
3.config
package com.qf.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Author: wenchaowen
* @Date: 2020/4/10 0010 17:22
* @Descripton:
*/
@Configuration
public class RabbitMQConfig {
@Bean
public FanoutExchange fanoutExchange(){
return new FanoutExchange("goods_exchange");
}
@Bean
public Queue itemQueue(){
return new Queue("itemQueue");
}
@Bean
public Binding itemQueueToExchange(){
return BindingBuilder.bind(itemQueue()).to(fanoutExchange());
}
@Bean
public FanoutExchange fanoutExchangeUser(){
return new FanoutExchange("user_exchange");
}
@Bean
public Queue itemQueueUser(){
return new Queue("itemQueueUser");
}
@Bean
public Binding itemQueueToExchangeUser(){
return BindingBuilder.bind(itemQueueUser()).to(fanoutExchangeUser());
}
}
4.listener
package com.qf.listener;
import com.alibaba.dubbo.config.annotation.Reference;
import com.qf.controller.ItemController;
import com.qf.entity.Goods;
import com.qf.entity.User;
import com.qf.service.IGoodsService;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: wenchaowen
* @Date: 2020/4/10 0010 17:42
* @Descripton:
*/
@Configuration
public class ItemQueueListener {
@Reference
private IGoodsService goodsService;
@Autowired
private freemarker.template.Configuration configuration;
@RabbitListener(queues = "itemQueue")
public void itemQueue(Goods goods){
//2.图片的集合
String[] split = goods.getGpic().split("\\|");
System.out.println("split = " + Arrays.toString(split));
//把数据放到map中
Map<String, Object> map = new HashMap<>();
map.put("goods", goods);
map.put("picList", split);
map.put("contextPath", "/");
Template template = null;
Writer writer = null;
try {
//3.得到模板
template = configuration.getTemplate("goodsItem.ftl");
//4.设置静态页面输出的目录
String staticPath = ItemController.class.getClassLoader().getResource("static").getPath();
File file = new File(staticPath + File.separator + "goods");
//不存在创建目录
if (!file.exists()) {
file.mkdir();
}
//生成页面
writer = new FileWriter(file.getAbsolutePath() + File.separator + goods.getId() + ".html");
template.process(map, writer);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
} finally {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/*@RabbitListener(queues = "itemQueueUser")
public void itemQueueUser(User user){
//把数据放到map中
Map<String, Object> map = new HashMap<>();
map.put("user", user);
map.put("contextPath", "/");
Template template = null;
Writer writer = null;
try {
//3.得到模板
template = configuration.getTemplate("userItem.ftl");
//4.设置静态页面输出的目录
String staticPath = ItemController.class.getClassLoader().getResource("static").getPath();
File file = new File(staticPath + File.separator + "user");
//不存在创建目录
if (!file.exists()) {
file.mkdir();
}
//生成页面
writer = new FileWriter(file.getAbsolutePath() + File.separator + user.getId() + ".html");
template.process(map, writer);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
} finally {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}*/
}
application.yml
server:
port: 8083
dubbo:
application:
name: item_web
registry:
address: zookeeper://101.37.175.1:2181
check: false
consumer:
check: false
retries: 3
spring:
rabbitmq:
host: 101.37.175.1
virtual-host: /
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.qf</groupId>
<artifactId>shop_item</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>shop_item</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.qf</groupId>
<artifactId>shop_service_api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
<!-- 添加springboot的rabbitmq依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
四、shop_front
1.shop_front
package com.qf.shop_front;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ShopFrontApplication {
public static void main(String[] args) {
SpringApplication.run(ShopFrontApplication.class, args);
}
}
application.yml
spring:
thymeleaf:
cache: false
prefix: classpath:/templates/
server:
port: 8081
dubbo:
application:
name: shop_front # dubbo发布服务器名称
registry:
address: zookeeper://101.37.175.1:2181 #设置注册中心地址(zookeeper到地址) http://
pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.qf</groupId>
<artifactId>shop_front</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>shop_front</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>