jdk8配置dubbo2.5.4
来源:互联网 发布:手机c语言编程软件ios 编辑:程序博客网 时间:2024/06/03 23:38
由于喜欢尝鲜,于是在Java9出来以后就马上把jdk换成了jdk1.9,结果最近刚学dubbo的时候一直都配置不成功,于是退回jdk1.8。一下就是配置dubbo的过程
安装Zookeeper
- 下载Zookeeper,然后把conf目录下的
zoo.sample.cfg
改为zoo.cfg
- 修改
zoo.cfg
,将dataDir修改为指定目录
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/eros/data/zookeeper
clientPort=2181
maxClientCnxns=60
安装tomcat
下载dubbo-admin包
如果是使用jdk8的话,可以在网上下载别人已经修改好的包,jdk1.8-dubbo-admin
下载完成后将war包放在tomcat的webapps目录下
启动Zookeeper服务器
sudo ./zkServer.sh start
启动tomcat
sudo ./startup.sh
访问http://localhost:8080/
观察是否启动成功
在浏览器输入http://localhost:8080/dubbo-admin-2.5.4/
,用户名和密码都是root
在Common模块中定义所有要暴露的接口
public interface IService { int calculate(int x,int y);}
启动Server
dubbo.xml
<?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"> <bean id="providerImpl" class="org.eros.dubbo.server.service.ProviderServiceImpl"/> <!-- 用dubbo协议在19091端口暴露服务 --> <dubbo:protocol name="dubbo" port="19091"/> <!-- 使用zookeeper注册中心暴露服务地址 --> <dubbo:registry address="zookeeper://127.0.0.1:2181"/> <!-- 提供方应用信息,用于计算依赖关系 --> <dubbo:application name="ProviderService"/> <dubbo:service interface="org.eros.dubbo.common.entity.IService" ref="providerImpl" timeout="100000"/></beans>
Spring配置类
@Configuration@ComponentScan@ImportResource("classpath:dubbo.xml")@EnableAspectJAutoProxypublic class Configure {}
接口的具体实现
public class ProviderServiceImpl implements IService{ @Override public int calculate(int x, int y) { return x+y; }}
import java.io.IOException;public class Main { private static final Logger logger= LogManager.getLogger(Main.class); public static void main(String[] args) { AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(Configure.class); context.start(); logger.debug("提供者服务已注册成功!"); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } }}
查看控制台
启动客户端
dubbo.xml
<?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="consumer"/> <dubbo:registry address="zookeeper://127.0.0.1:2181"/> <dubbo:reference interface="org.eros.dubbo.common.entity.IService" id="providerService" timeout="100000" check="false"/></beans>
Spring配置文件
@Configuration@ComponentScan@ImportResource("classpath:dubbo.xml")public class Configure {}
public class Main { private static final Logger logger= LogManager.getLogger(Main.class); public static void main(String[] args) { AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(Configure.class); context.start(); IService providerService= (IService) context.getBean("providerService"); int result=providerService.calculate(3,7); logger.debug("result is "+result); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } }}
查看控制台
附:
Server.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>DubboDemo</artifactId> <groupId>org.eros</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>Server</artifactId> <properties> <junit.version>4.12</junit.version> <druid.version>1.1.3</druid.version> <spring.version>4.3.11.RELEASE</spring.version> <hibernate.version>5.2.10.Final</hibernate.version> <redis.version>2.9.0</redis.version> <mysql.version>6.0.6</mysql.version> <log4j.version>2.9.1</log4j.version> <springdata.version>1.11.7.RELEASE</springdata.version> <springdata-redis.version>1.8.7.RELEASE</springdata-redis.version> <fastjson.version>1.2.38</fastjson.version> <zookeeper.version>3.4.10</zookeeper.version> <dubbo.version>2.5.4</dubbo.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.11</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-test --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${redis.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>${springdata-redis.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>${springdata.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <artifactId>Common</artifactId> <groupId>org.eros</groupId> <version>1.0-SNAPSHOT</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/dubbo --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> <exclusions> <exclusion> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>${zookeeper.version}</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency> <!-- https://mvnrepository.com/artifact/com.101tec/zkclient --> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.10</version> </dependency> </dependencies></project>
client.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/maven-v4_0_0.xsd"> <parent> <artifactId>DubboDemo</artifactId> <groupId>org.eros</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>Client</artifactId> <packaging>war</packaging> <name>Client Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <junit.version>4.12</junit.version> <druid.version>1.1.3</druid.version> <spring.version>4.3.11.RELEASE</spring.version> <hibernate.version>5.2.10.Final</hibernate.version> <redis.version>2.9.0</redis.version> <mysql.version>6.0.6</mysql.version> <servlet.version>4.0.0</servlet.version> <fastjson.version>1.2.38</fastjson.version> <jsp.version>2.3.1</jsp.version> <log4j.version>2.9.1</log4j.version> <springdata.version>1.11.7.RELEASE</springdata.version> <springdata-redis.version>1.8.7.RELEASE</springdata-redis.version> <zookeeper.version>3.4.10</zookeeper.version> <dubbo.version>2.5.4</dubbo.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <artifactId>Common</artifactId> <groupId>org.eros</groupId> <version>1.0-SNAPSHOT</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.11</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-test --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${redis.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api --> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>${jsp.version}</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>${springdata-redis.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>${springdata.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>${log4j.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/dubbo --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> <exclusions> <exclusion> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>${zookeeper.version}</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> <exclusion> <groupId>io.netty</groupId> <artifactId>netty</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency> <!-- https://mvnrepository.com/artifact/com.101tec/zkclient --> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.10</version> </dependency> </dependencies> <build> <finalName>Client</finalName> </build></project>
阅读全文
0 0
- jdk8配置dubbo2.5.4
- Dubbo2
- 配置Eclipse支持JDK8
- JDK8安装与配置
- jdk8配置环境变量步骤
- JDK8环境变量的配置
- Centos7 JDK8安装配置
- Ubuntu下配置jdk8
- JDK8+Tomcat8配置https
- JDK8安装与配置
- Centos7安装配置JDK8
- Centos7 JDK8安装配置
- 配置Eclipse支持JDK8
- ubuntu下配置JDK8
- LINUX JDK8 安装配置
- Centos7 配置 JDK8
- centos7 jdk8配置
- ubuntu下安装、配置JDK8
- 微信小程序组件(四)text
- bzoj 3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二 RMQ
- js代码学习19---网页换皮肤
- 欢迎使用CSDN-markdown编辑器
- 16:矩阵剪刀石头布
- jdk8配置dubbo2.5.4
- BZOJ 4543: [POI2014]Hotel加强版 长链剖分
- matlab格式化文本读操作
- hdu1272&&1325--并查集判环及森林问题
- 阿里云系列(一)--win环境下部署Javaweb项目
- Selective Search
- 类的生命周期
- 用SS5在Linux上搭建Socks5 Proxy代理服务器
- java内部类,匿名内部类