标签:log4 github prope 资源 width cti maven工程 nec 添加
src
目录在这个provider中修改pom文件坐标
<dependencies>
<!--引入公共模块项目-->
<dependency>
<groupId>cn.kgc</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--这是微服dubbo的核心服务包-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<!--这是zookeeper的服务操作包 但主要这里的版本最好和你的zookeeper版本一致-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!--这里是zookeeper的zkCli的操作包 我们读写服务全靠这个包-->
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
application.properties
修改需要的url参数和分页插件参数
server.port=9090
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/kgc
spring.datasource.username=root
spring.datasource.password=ok
mybatis.type-aliases-package=cn.kgc.vo
mybatis.mapper-locations=mapper/*.xml
pagehelper.helper-dialect=mysql
spring-provider.xml
根据需要修改用户服务接口
中的参数,作用是将service的接口注入到Zookeeper
中去
<?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="myprovider" />
<!-- 使用zookeeper注册中心暴露服务地址,我的zookeeper是架在本地的 -->
<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" timeout="60000"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 用户服务接口 -->
<dubbo:service interface="cn.kgc.service.TableToOneService" ref="tableToOneService"/>
<bean id="tableToOneService" class="cn.kgc.service.TableToOneServiceImpl"/>
<dubbo:service interface="cn.kgc.service.TableToManyService" ref="tableToManyService"/>
<bean id="tableToManyService" class="cn.kgc.service.TableToManyServiceImpl"/>
</beans>
spring-consumer.xml
按需修改service名
<?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="dubbo-consumer"/>
<dubbo:registry check="false" address="zookeeper://127.0.0.1:2181"/>
<dubbo:reference interface="cn.kgc.service.TableToOneService" id="tableToOneService"/>
<dubbo:reference interface="cn.kgc.service.TableToManyService" id="tableToManyService"/>
</beans>
全部代码写完
然后开启Zookeeper服务器,然后开启provider启动类,再开启consumer启动类,最后用postman检测接口是否通畅,根据错误信息修改代码..
整体流程
结束
标签:log4 github prope 资源 width cti maven工程 nec 添加
原文地址:https://www.cnblogs.com/jsccc520/p/12006237.html