一、redis安装
1、redis官网地址:http://redis.io/
2、redis下载:
wget http://download.redis.io/releases/redis-3.0.6.tar.gz
3、redis安装
- 解压 redis-3.0.6.tar.gz ,并进入解压目录
tar -zxvf redis-3.0.6.tar.gz
cd redis-3.0.6
- 编译安装。指定redis安装目录为/usr/local/redis
make PREFIX=/usr/local/redis install
- 创建pid文件和配置文件目录
mkdir run conf
- 拷贝配置文件到配置文件目录中
cp /usr/local/src/redis-3.0.6/redis.conf /usr/local/redis/conf/
- 编辑配置文件redis.conf
- 服务自启动的配置
cp /usr/local/src/redis-3.0.6/utils/redis_init_script /etc/rc.d/init.d/redis
- 注册服务
chkconfig --add redis
- 以服务方式启动redis
service redis start/stop
- 将redis所生成命令加入到PATH中
echo "export PATH=/usr/local/redis/bin:$PATH">>/etc/profile
source /etc/profile
- 测试redis
[root@192 conf]# redis-cli
127.0.0.1:6379> keys *
(empty list or set)
二、dubbo 的demo编写
1、新建一个简单的maven工程,pom文件如下:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency>
2、建立服务类
接口文件:
package com.xiaoqiang.dubbotest.demo1.service;
public interface IMyService {
public String hello(String name);
}
服务实现类:
package com.xiaoqiang.dubbotest.demo1.service.impl;
import org.springframework.stereotype.Component;
import com.xiaoqiang.dubbotest.demo1.service.IMyService;
@Component("myServiceImpl")
public class MyServiceImpl implements IMyService {
@Override
public String hello(String name) {
return "hello"+name;
}
}
3、配置文件:
<?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:context="http://www.springframework.org/schema/context"
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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 注解包扫描位置: -->
<context:component-scan base-package="com.xiaoqiang.dubbotest.demo1.service.*" />
<!-- 接入dubbo的应用程序名称 -->
<dubbo:application name="ws-demo" />
<!-- 注册仓库地址:-->
<dubbo:registry address="redis://192.168.0.108:6379" />
<!-- 使用dubbo协议, 在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<dubbo:service interface="com.xiaoqiang.dubbotest.demo1.service.IMyService" ref="myServiceImpl"/>
</beans>
4、服务启动类
package com.xiaoqiang.dubbotest.demo1.server;
import org.apache.log4j.BasicConfigurator;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ServerBootstrap {
static {
BasicConfigurator.configure();
}
public static void main(String[] args) throws Exception {
final Object obj = new Object();
ClassPathXmlApplicationContext cp = new ClassPathXmlApplicationContext(
new String[] { "com/xiaoqiang/dubbotest/demo1/server/application-service.xml" });
synchronized (obj) {
obj.wait();
}
}
}
三、dubbo的jar包替换
1 、进入dubbo官网下载地址:https://github.com/alibaba/dubbo,下载相应的zip包
2、将dubbo所依赖的包的配置加入pom文件中
将下载下来dubbo-master解压,将dubbo-master目录下的pom文件中的依赖jar包和配置文件拷贝到上面建立
工程的pom文件中,如下图:
3 下载工程中所以jar包对应的源代码,(你可以通过命令选择下载)
右键工程---->选择Maven4MyEclipse---->Download Sources
4 将下载下来dubbo源代码包dubbo-2.5.3-sources.jar解压,并将解压文件拷贝到上面工程的src/main/java目录中
5 注视掉上面工程对dubbo的依赖
<!--
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
</dependency> -->
6 以后我们可以直接在dubbo源代码中调试,修改信息。
7 下图为新修改dubbo工程的目录结构