Dubbo入门案例

有关Dubbo的相关介绍, 请参考官方文档,地址:http://dubbo.io/

下面主要介绍如何用maven搭建一个dubbo的demo,Dubbo简单的来说就是由,服务提供者,服务消费者和注册中心构成


上面这张图是从官网上截的图,哈哈

闲话不多说,直接上代码

1) 抽取出公共的代码:如domain,和到需要暴露的接口等


public class User  implements Serializable{
	private String name;
	private int age;
	private String sex;
	
	
	public User(String name, int age, String sex) {
		this.name = name;
		this.age = age;
		this.sex = sex;
	}
	public User() {
	}
	
	//省略getter/setter

public interface DemoService {
	 String sayHello(String name);
	 List getUsers();
}


服务提供方:



import java.util.ArrayList;
import java.util.List;

import com.baofoo.dubbotest.domian.User;
import com.baofoo.dubbotest.server.DemoService;

public class DemoServiceImpl implements DemoService {

	public List getUsers() {
		List<User> list =new ArrayList<User>();
		User u1=new User("AAA", 12, "M");
		User u2=new User("BBB", 13, "F");
		User u3=new User("CCC", 12, "M");
		list.add(u1);
		list.add(u2);
		list.add(u3);
		return list;
	}

	public String sayHello(String name) {
		
		return "Hello "+ name;
	}

}
apploicationContext.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: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-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	<!-- 具体的实体bean -->
	<bean id="demoService" class="com.baofoo.server.impl.DemoServiceImpl" />
     
     <!-- 提供方应用信息,用于计算依赖关系 -->
     <dubbo:application name="demo_provider"/>
      
      <!-- 使用zookeeper注册中心暴露服务地址 -->
       <dubbo:registry address="zookeeper://10.0.20.175:2181"  />
       
       <!-- 声明需要暴露的服务接口 -->
       <dubbo:service interface="com.baofoo.dubbotest.server.DemoService" ref="demoService"></dubbo:service>
     
</beans>

public class Provider {
	public static void main(String[] args) throws IOException {
		ClassPathXmlApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");
		context.start();
		System.in.read(); 为保证服务一直开着,利用输入流的阻塞来模拟  
	}
}


服务消费方:



<?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-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	
	<!-- 通过Spring配置引用远程服务 -->
	<!-- 消息方应用名,用于计算依赖关系,不匹配条件,不要与提供方一样 -->
	<dubbo:application name="demo_consume"/>
	
	<!-- 使用zookeeper注册中心暴露服务地址 -->
	<dubbo:registry address="zookeeper://10.0.20.175:2181" />
	
	<!-- 生成远程代理,可以像使用本地bean一样使用demoService -->
	
	<dubbo:reference id="demoService"  interface="com.baofoo.dubbotest.server.DemoService" />
</beans>

public class ConSumer {
	public static void main(String[] args) throws IOException {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"applicationContext-customer.xml");
		context.start();

		DemoService demoService = (DemoService) context.getBean("demoService");

		String hello = demoService.sayHello("AAA");
		System.out.println(hello);

		List<User> list = demoService.getUsers();
		for (User u : list) {
			System.out.println(u);
		}

		System.in.read();
	}
}

先运行 provider,启动服务,在运行 ConSumer



源代码下载:dubbo-demo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算法来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算法(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算法会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测试面试题软件测
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值