dobbu入门
来源:互联网 发布:福州网络推广 编辑:程序博客网 时间:2024/06/07 01:57
整个项目分三个工程:interface,server,web
一、interface 工程
- interface pom的依赖:
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>0.1</version> </dependency>
- dto 与接口定义:
public class UserDTO implements Serializable{ private static final long serialVersionUID = -6159390245100691517L; private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; }}
- 接口定义:
public interface UserService { public UserDTO findUserById(long id);}
二、server工程
- server工程依赖interface工程
- 实现 UserService接口:
public class UserServiceImpl implements UserService { @Override public UserDTO findUserById(long id) { UserDTO dto = new UserDTO(); dto.setPassword("pass"); dto.setUsername("user"); return dto; }}
- 配置文件(已启动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" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <dubbo:application name="hello-world-app" /> <dubbo:registry protocol="zookeeper" address="192.168.1.108:2181" /> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:service interface="com.terry.service.UserService" ref="userService" /> <bean id="userService" class="com.terry.service.impl.UserServiceImpl" /></beans>
三、web工程
- web工程也依赖interface
- 配置文件:
<?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" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <dubbo:application name="consumer-of-helloworld-app" /> <dubbo:registry protocol="zookeeper" address="192.168.1.108:2181" /> <dubbo:reference id="userService" interface="com.terry.service.UserService" /></beans>
- 测试一下:
@RestController@RequestMapping("/user")public class UserAction { @Autowired private UserService userService; @RequestMapping("/get") public UserDTO get() { UserDTO dto = userService.findUserById(1L); return dto; }}
- 然后就可以跑起来了。
0 0
- dobbu入门
- zookeper----------dobbu使用问题记录
- 在dobbu中对象传递属性不存在。
- dobbu框架下,启动service,无法启动。没有错误
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- 入门
- storm流程——flume和kafka的连接
- 很好的编程学习网站,尤其学习linux下编程
- SQL必知必会(五) 使用视图、使用储存过程、管理事务处理、使用游标、高级SQL特性
- spring注入@autowired
- Android基础学习之ArrayAdaptery以及SimpleAdapter的使用
- dobbu入门
- 【LINUX】教你如何构建支持lighttpd + cgi的环境
- OpenGL画点函数
- UVa10720
- iOS中UIWebView的使用详解
- 乐学成语之splash
- 【Get深一度】7种常用的排序算法
- Acdream 1210 Chinese Girls' Amusement(大数模板运算 + 找规律)
- 乐学成语——第三部分