1.接口工程:存放实体bean(必须要进行序列化操作)和业务接口
实体bean
package com.bjpowernode.dubbo.pojo;
import java.io.Serializable;
import java.util.Objects;
public class User implements Serializable {
private Integer id;
private String username;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
业务接口
package com.bjpowernode.dubbo.service;
import com.bjpowernode.dubbo.pojo.User;
public interface UserService {
/**
* 根据用户id和用户名查找用户信息
* @param id
* @return
*/
User queryUserById(Integer id,String userName);
}
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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bjpowernode.dubbo</groupId>
<artifactId>zk-interface</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<!--JDK1.8编译插件-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
提供者
接口实现类
package com.bjpowernode.dubbo.service.impl;
import com.bjpowernode.dubbo.pojo.User;
import com.bjpowernode.dubbo.service.UserService;
public class UserServiceImpl implements UserService {
@Override
public User queryUserById(Integer id,String username) {
User user = new User();
user.setId(id);
user.setUsername(username);
return user;
}
}
dubbo-zk-userservice-provider.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://dubbo.apache.org/schema/dubbo&#