注:实体类和JSP页面省略
服务提供方相关代码如下:
springboot-server的 POM文件
<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.cn</groupId>
<artifactId>springboot-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.27</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-intf</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-po</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.11</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
</dependencies>
<build>
<finalName>springboot-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
dao层类
package com.cn.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.cn.po.push.PushManageTaskInfo;
import com.cn.po.push.request.PushManageTaskRequest;
@Mapper
public interface PushManageTaskDao
{
public List<PushManageTaskInfo> queryPushManageInfoList();
public List<PushManageTaskInfo> queryPushManageInfo(PushManageTaskRequest request);
}
PushManageTaskService实现类
package com.cn.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cn.dao.PushManageTaskDao;
import com.cn.intf.push.IPushManageTaskService;
import com.cn.po.push.PushManageTaskInfo;
import com.cn.po.push.request.PushManageTaskRequest;
import com.cn.po.push.response.PushManageTaskResponse;
import com.cn.po.push.response.PushManageTaskVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service("pushManageTaskService")
public class PushManageTaskService implements IPushManageTaskService
{
@Autowired
private PushManageTaskDao pushManageTaskDao;
@Override
public List<PushManageTaskInfo> queryPushManageInfoList()
{
return pushManageTaskDao.queryPushManageInfoList();
}
@Override
public PushManageTaskResponse selectPushManageInfo(PushManageTaskRequest request)
{
PushManageTaskResponse response = new PushManageTaskResponse();
List<PushManageTaskVo> pushManageResult=new ArrayList<PushManageTaskVo>();
PageHelper.startPage(request.getPage().intValue(), request.getPageSize().intValue());
List<PushManageTaskInfo> retList=pushManageTaskDao.queryPushManageInfo(request);
PageInfo<PushManageTaskInfo> pageQuery=new PageInfo<PushManageTaskInfo>(retList);
for(PushManageTaskInfo pushInfo : retList)
{
PushManageTaskVo resVo = new PushManageTaskVo();
BeanUtils.copyProperties(pushInfo, resVo);
pushManageResult.add(resVo);
}
response.setPushManageResult(pushManageResult);
response.setTotalResults(pageQuery.getTotal());
return response;
}
}
pushManageTaskMapper.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cn.dao.PushManageTaskDao">
<resultMap id="pushListResultMap" type="com.cn.po.push.PushManageTaskInfo">
<result column="task_id" property="taskId" jdbcType="VARCHAR" />
<result column="push_type" property="pushType" jdbcType="VARCHAR" />
<result column="state" property="state" jdbcType="VARCHAR" />
<result column="product" property="product" jdbcType="VARCHAR" />
<result column="send_total" property="sendTotal" jdbcType="INTEGER" />
<result column="arrival_total" property="arrivalTotal" jdbcType="INTEGER" />
<result column="click_total" property="clickTotal" jdbcType="INTEGER" />
<result column="platform" property="platform" jdbcType="VARCHAR" />
</resultMap>
<select id="queryPushManageInfoList" resultMap="pushListResultMap">
SELECT task_id,
push_type,
state,
product,
send_total,
arrival_total,
click_total,
platform
FROM wifi_push_manage_task
</select>
<select id="queryPushManageInfo" resultMap="pushListResultMap" parameterType="com.cn.po.push.request.PushManageTaskRequest">
SELECT task_id,
push_type,
state,
product,
send_total,
arrival_total,
click_total,
platform
FROM wifi_push_manage_task AS pushtask
</select>
</mapper>
application.properties属性文件
server.port=8001
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=libingbing
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
mybatis.mapperLocations=classpath:mapper/*.xml
zookeeper.registry.center=127.0.0.1:2181
dubbo.port=20880
dubbo-provider.xml提供服务方
[size=medium<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="springboot-server"/>
<dubbo:registry protocol="zookeeper" address="${zookeeper.registry.center}" />
<dubbo:protocol name="dubbo" port="${dubbo.port}" />
<bean id="pushManageTaskService" class="com.cn.service.PushManageTaskService"/>
<dubbo:service ref="pushManageTaskService" interface="com.cn.intf.push.IPushManageTaskService" timeout="10000" />
<dubbo:annotation/>
</beans>[/size]
ApplicationServer类——服务提供方启动类
package com.cn;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ImportResource;
/**
* springboot程序启动类
* @author libingbing
* @version [版本号, 2018年3月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@SpringBootApplication
@ImportResource(locations={"dubbo-provider.xml"})
@MapperScan(basePackages={"com.cn.dao"})
public class ApplicationServer extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(ApplicationServer.class, args);
System.out.println("======ApplicationServer start success======");
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(this.getClass());
}
}
服务消费方相关代码
springboot-web的POM文件
<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.cn</groupId>
<artifactId>springboot-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.27</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-intf</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-po</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.5.10.RELEASE</version> <scope>provided</scope> </dependency> -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.11</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
</dependencies>
<build>
<finalName>springboot-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
PushManageController类
package com.cn.web;
import java.util.List;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSONObject;
import com.cn.intf.push.IPushManageTaskService;
import com.cn.po.push.PushManageTaskInfo;
import com.cn.po.push.request.PushManageTaskRequest;
import com.cn.po.push.response.PushManageTaskResponse;
@Controller
@RequestMapping(value = "/push")
public class PushManageController
{
@Autowired
private IPushManageTaskService pushManageTaskService;
@RequestMapping(value="/pushList",method={RequestMethod.POST,RequestMethod.GET})
public ModelAndView pushManageList()
{
List<PushManageTaskInfo> pushList = pushManageTaskService.queryPushManageInfoList();
ModelAndView mview=new ModelAndView("pushList");
mview.addObject("pushList", pushList);
return mview;
}
@RequestMapping(value = "/pushInfo", method = {RequestMethod.POST,RequestMethod.GET})
@ResponseBody
public PushManageTaskResponse pushManageInfo()
{
PushManageTaskRequest request=new PushManageTaskRequest();
request.setPage(1L);
request.setPageSize(20L);
PushManageTaskResponse response=pushManageTaskService.selectPushManageInfo(request);
String resJson=JSONObject.toJSONString(response);
System.out.println("=====resJson:"+resJson);
return response;
}
}
服务消费方的application.properties属性文件配置
server.port=8002
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
zookeeper.registry.center=127.0.0.1:2181
dubbo.port=20880
dubbo-consumer.xml文件
[size=medium<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="springboot-web" />
<dubbo:registry protocol="zookeeper" address="${zookeeper.registry.center}" />
<dubbo:protocol name="dubbo" port="${dubbo.port}" />
<dubbo:reference id="pushManageTaskService" interface="com.cn.intf.push.IPushManageTaskService" />
</beans> [/size]
Application服务消费方启动类
package com.cn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication(scanBasePackages={"com.cn.web"})
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@ImportResource(locations="classpath:dubbo-consumer.xml")
public class Application extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
System.out.println("======Application start success======");
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(this.getClass());
}
}
注:1、先启动zookeeper
2、将已经打好包的 springboot-server.jar,执行启动startup.bat(这里省略启动脚本命令)脚本
3、将已经打好包的 springboot-web.war包放到 tomcat的webapp目录下,启动tomcat 即可
4、用浏览器访问服务地址:http://IP地址:tomcat端口号/WAR包名字/RESTFUL服务URL
服务提供方相关代码如下:
springboot-server的 POM文件
<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.cn</groupId>
<artifactId>springboot-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.27</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-intf</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-po</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.11</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
</dependencies>
<build>
<finalName>springboot-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
dao层类
package com.cn.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.cn.po.push.PushManageTaskInfo;
import com.cn.po.push.request.PushManageTaskRequest;
@Mapper
public interface PushManageTaskDao
{
public List<PushManageTaskInfo> queryPushManageInfoList();
public List<PushManageTaskInfo> queryPushManageInfo(PushManageTaskRequest request);
}
PushManageTaskService实现类
package com.cn.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cn.dao.PushManageTaskDao;
import com.cn.intf.push.IPushManageTaskService;
import com.cn.po.push.PushManageTaskInfo;
import com.cn.po.push.request.PushManageTaskRequest;
import com.cn.po.push.response.PushManageTaskResponse;
import com.cn.po.push.response.PushManageTaskVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service("pushManageTaskService")
public class PushManageTaskService implements IPushManageTaskService
{
@Autowired
private PushManageTaskDao pushManageTaskDao;
@Override
public List<PushManageTaskInfo> queryPushManageInfoList()
{
return pushManageTaskDao.queryPushManageInfoList();
}
@Override
public PushManageTaskResponse selectPushManageInfo(PushManageTaskRequest request)
{
PushManageTaskResponse response = new PushManageTaskResponse();
List<PushManageTaskVo> pushManageResult=new ArrayList<PushManageTaskVo>();
PageHelper.startPage(request.getPage().intValue(), request.getPageSize().intValue());
List<PushManageTaskInfo> retList=pushManageTaskDao.queryPushManageInfo(request);
PageInfo<PushManageTaskInfo> pageQuery=new PageInfo<PushManageTaskInfo>(retList);
for(PushManageTaskInfo pushInfo : retList)
{
PushManageTaskVo resVo = new PushManageTaskVo();
BeanUtils.copyProperties(pushInfo, resVo);
pushManageResult.add(resVo);
}
response.setPushManageResult(pushManageResult);
response.setTotalResults(pageQuery.getTotal());
return response;
}
}
pushManageTaskMapper.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cn.dao.PushManageTaskDao">
<resultMap id="pushListResultMap" type="com.cn.po.push.PushManageTaskInfo">
<result column="task_id" property="taskId" jdbcType="VARCHAR" />
<result column="push_type" property="pushType" jdbcType="VARCHAR" />
<result column="state" property="state" jdbcType="VARCHAR" />
<result column="product" property="product" jdbcType="VARCHAR" />
<result column="send_total" property="sendTotal" jdbcType="INTEGER" />
<result column="arrival_total" property="arrivalTotal" jdbcType="INTEGER" />
<result column="click_total" property="clickTotal" jdbcType="INTEGER" />
<result column="platform" property="platform" jdbcType="VARCHAR" />
</resultMap>
<select id="queryPushManageInfoList" resultMap="pushListResultMap">
SELECT task_id,
push_type,
state,
product,
send_total,
arrival_total,
click_total,
platform
FROM wifi_push_manage_task
</select>
<select id="queryPushManageInfo" resultMap="pushListResultMap" parameterType="com.cn.po.push.request.PushManageTaskRequest">
SELECT task_id,
push_type,
state,
product,
send_total,
arrival_total,
click_total,
platform
FROM wifi_push_manage_task AS pushtask
</select>
</mapper>
application.properties属性文件
server.port=8001
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=libingbing
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
mybatis.mapperLocations=classpath:mapper/*.xml
zookeeper.registry.center=127.0.0.1:2181
dubbo.port=20880
dubbo-provider.xml提供服务方
[size=medium<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="springboot-server"/>
<dubbo:registry protocol="zookeeper" address="${zookeeper.registry.center}" />
<dubbo:protocol name="dubbo" port="${dubbo.port}" />
<bean id="pushManageTaskService" class="com.cn.service.PushManageTaskService"/>
<dubbo:service ref="pushManageTaskService" interface="com.cn.intf.push.IPushManageTaskService" timeout="10000" />
<dubbo:annotation/>
</beans>[/size]
ApplicationServer类——服务提供方启动类
package com.cn;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ImportResource;
/**
* springboot程序启动类
* @author libingbing
* @version [版本号, 2018年3月8日]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
@SpringBootApplication
@ImportResource(locations={"dubbo-provider.xml"})
@MapperScan(basePackages={"com.cn.dao"})
public class ApplicationServer extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(ApplicationServer.class, args);
System.out.println("======ApplicationServer start success======");
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(this.getClass());
}
}
服务消费方相关代码
springboot-web的POM文件
<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.cn</groupId>
<artifactId>springboot-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.27</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-intf</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cn</groupId>
<artifactId>springboot-po</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.10.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.5.10.RELEASE</version> <scope>provided</scope> </dependency> -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.11</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
</dependencies>
<build>
<finalName>springboot-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
PushManageController类
package com.cn.web;
import java.util.List;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSONObject;
import com.cn.intf.push.IPushManageTaskService;
import com.cn.po.push.PushManageTaskInfo;
import com.cn.po.push.request.PushManageTaskRequest;
import com.cn.po.push.response.PushManageTaskResponse;
@Controller
@RequestMapping(value = "/push")
public class PushManageController
{
@Autowired
private IPushManageTaskService pushManageTaskService;
@RequestMapping(value="/pushList",method={RequestMethod.POST,RequestMethod.GET})
public ModelAndView pushManageList()
{
List<PushManageTaskInfo> pushList = pushManageTaskService.queryPushManageInfoList();
ModelAndView mview=new ModelAndView("pushList");
mview.addObject("pushList", pushList);
return mview;
}
@RequestMapping(value = "/pushInfo", method = {RequestMethod.POST,RequestMethod.GET})
@ResponseBody
public PushManageTaskResponse pushManageInfo()
{
PushManageTaskRequest request=new PushManageTaskRequest();
request.setPage(1L);
request.setPageSize(20L);
PushManageTaskResponse response=pushManageTaskService.selectPushManageInfo(request);
String resJson=JSONObject.toJSONString(response);
System.out.println("=====resJson:"+resJson);
return response;
}
}
服务消费方的application.properties属性文件配置
server.port=8002
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
zookeeper.registry.center=127.0.0.1:2181
dubbo.port=20880
dubbo-consumer.xml文件
[size=medium<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="springboot-web" />
<dubbo:registry protocol="zookeeper" address="${zookeeper.registry.center}" />
<dubbo:protocol name="dubbo" port="${dubbo.port}" />
<dubbo:reference id="pushManageTaskService" interface="com.cn.intf.push.IPushManageTaskService" />
</beans> [/size]
Application服务消费方启动类
package com.cn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication(scanBasePackages={"com.cn.web"})
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@ImportResource(locations="classpath:dubbo-consumer.xml")
public class Application extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
System.out.println("======Application start success======");
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder)
{
return builder.sources(this.getClass());
}
}
注:1、先启动zookeeper
2、将已经打好包的 springboot-server.jar,执行启动startup.bat(这里省略启动脚本命令)脚本
3、将已经打好包的 springboot-web.war包放到 tomcat的webapp目录下,启动tomcat 即可
4、用浏览器访问服务地址:http://IP地址:tomcat端口号/WAR包名字/RESTFUL服务URL
发表评论
-
springboot assembly打ZIP包
2018-12-01 16:10 9071、修改pom文件 <plugin> &l ... -
springboot添加PageHelper分页查询插件
2018-07-26 17:38 1445springboot添加PageHelper分页查询插件 1 ... -
springboot微服务打WAR包部署
2018-07-03 13:45 11731、修改项目的POM文件 修改项目的打包形式为 WAR包 去 ... -
springboot微服务打包JAR包部署
2018-06-29 15:52 2788Springboot微服务打包JAR操作如下: Main方法 ... -
springboot集成mybatis
2018-02-07 17:23 577PushManageTaskInfo实体类 package c ...
相关推荐
【标题】"springboot+dubbo+zookeeper+mybatis微服务demo"揭示了这个项目的核心技术栈,它是一个基于Spring Boot、Dubbo、Zookeeper和MyBatis实现的微服务示例。下面将详细阐述这些技术及其在微服务架构中的作用。 ...
在《Springboot + Mybatis+Dubbo+Zookeeper+nginx+redis+HTML.docx》这份文档中,作者详细介绍了如何集成并使用Spring Boot、MyBatis、Dubbo、Zookeeper、Nginx以及Redis等多种技术,构建一个高效稳定的应用系统。...
自己手动搭建的nginx+springboot+zookeeper+dubbo+mybatis+dubboadmin,nginx做前后端分离,负载均衡,springboot+zookeeper+dubbo做后端接口,mybatis为数据库持久化层,dubboadmin做监控中心,解压直接用idea导入...
这个项目组合"Springboot+dubbo+zookeeper+swagger+mybatisplus+mysql"正是为了实现这样的目标而设计的。让我们逐一深入探讨这些技术组件及其在系统中的作用。 首先,Spring Boot是Spring框架的一个精简版,它旨在...
在IT行业中,SpringBoot、Dubbo和MyBatis-Plus是三个非常重要的开源框架,它们分别专注于简化Spring应用开发、实现高性能的服务治理以及提供增强的MyBatis功能。本篇文章将详细探讨如何将这三个框架集成在一起,以...
【描述】"springboot+dubbo+mybatis+mybatis-plus+mysql的web层demo"进一步指出了这个项目在数据访问层的实现方式。Mybatis是流行的持久层框架,它简化了SQL操作,而Mybatis-Plus则是在Mybatis基础上的一个增强工具...
Spring MVC + Dubbo + MyBatis + ZooKeeper 这是一个经典的微服务架构组合,用于构建高效、可扩展的分布式系统。下面将详细解释这四个组件及其在实际项目中的作用。 **Spring MVC** Spring MVC 是 Spring 框架的一...
本文将深入探讨如何将SpringBoot、Dubbo、Zookeeper和MyBatis这四个关键技术进行集成,构建高效且可扩展的微服务架构。 **SpringBoot** SpringBoot是由Pivotal团队提供的全新框架,它旨在简化Spring应用的初始搭建...
在现代企业级应用开发中,SpringBoot、Dubbo和Zookeeper是三个非常关键的技术组件,它们各自扮演着不同的角色,并且协同工作以构建高性能、可扩展的服务架构。本项目通过"springboot+dubbo+zk"的组合,实现了基于...
使用springboot+dubbo+zookeeper+fluent-mybatis+swagger+mysql搭建的简单案例
综上所述,"springboot-dubbox-master" 压缩包文件很可能包含了一个完整的 SpringBoot 应用,其中集成了 Dubbo 服务治理、Zookeeper 注册发现、Redis 缓存以及 MyBatis 持久层框架。这个基础管理系统可以作为一个...
基于SpringBoot+Dubbo+RocketMQ的微服务订单支付系统 项目经过严格测试,确保可以运行! 应用技术: SpringBoot Mybatis Dubbo RocketMQ Zookeeper MySQL 应用工具: Twitter-Snowflake RestTemplate 注意事项: ...
【标题】"eclipse springboot+dubbo+zk+mybatis restful编程风格"涉及的关键技术栈包括了Eclipse IDE、Spring Boot、Dubbo、Zookeeper以及MyBatis,并且采用了RESTful编程风格。这些组件共同构成了一个高效、可扩展...
dubbo+springboot+zookeeper+mybatis+mysql 基本架构,关于详细描述可以去看下我的这篇文章https://blog.csdn.net/weixin_44288283/article/details/101027797
总的来说,这个项目展示了如何在SpringBoot环境下利用Dubbo进行服务治理,通过ZooKeeper实现服务的注册与发现,并结合MyBatis-Plus进行数据库操作,构建一个完整的微服务架构。对于学习和实践分布式系统开发的开发者...
标题 "Springmvc+dubbo+mybatis+mysql+redis" 描述了一个基于Java技术栈的分布式微服务架构。在这个系统中,SpringMVC作为前端控制器处理HTTP请求,Dubbo用于服务治理,MyBatis是持久层框架,MySQL是关系型数据库,...
基于springboot+mybatis+elasticsearch的仿牛客网题库后台系统 使用SpringBoot后台框架集成Mybatis,Druid连接池,ES搜索引擎 dubbo,zookeeper分布式管理实现的一个题库后台管理系统 基于springboot+mybatis+elastic...
在本项目中,"SpringBoot+Dubbo+Mybatis亲测"是一个综合性的技术实践,主要结合了Spring Boot、Dubbo和Mybatis三大框架来构建一个微服务应用。以下是关于这三个核心组件及其交互的详细解释: 1. **Spring Boot**: ...
在本项目实例中,我们探讨的是如何整合SpringBoot、Dubbo、Redis以及RabbitMQ来构建一个高效、可扩展的Java应用程序。以下是对这些技术及其整合的详细解释: 1. **SpringBoot**: SpringBoot是由Pivotal团队提供的...
该项目框架整合了SpringBoot+mybatis+zookeeper+dubbo+mysql+redis,项目大体由生产者provider、消费者customer和公共类common三部分组成,是目前分布式开发前后端分离的流行框架。