├── .gitignore ├── springboot-dubbox-webapp ├── src │ ├── main │ │ ├── resources │ │ │ ├── dubbo.properties │ │ │ ├── application.properties │ │ │ ├── logback.xml │ │ │ └── META-INF │ │ │ │ └── dubbo │ │ │ │ └── application-dubbo-consumer.xml │ │ └── java │ │ │ ├── net │ │ │ └── aimeizi │ │ │ │ ├── config │ │ │ │ └── RestServiceConfig.java │ │ │ │ ├── starter │ │ │ │ ├── JavaConfigBootstrap.java │ │ │ │ ├── ApplicationBootstrap.java │ │ │ │ └── SpringBootStarter.java │ │ │ │ ├── controller │ │ │ │ └── StudentController.java │ │ │ │ ├── consumer │ │ │ │ └── JavaConfigConsumer.java │ │ │ │ └── ServiceConsumer.java │ │ │ └── dubbo │ │ │ └── spring │ │ │ └── javaconfig │ │ │ └── JavaConsumerConfig.java │ └── test │ │ ├── resources │ │ └── log4j.xml │ │ └── java │ │ └── net │ │ └── aimeizi │ │ └── RestClient.java └── pom.xml ├── springboot-dubbox-service ├── src │ └── main │ │ ├── resources │ │ ├── application.properties │ │ ├── logback.xml │ │ └── META-INF │ │ │ └── spring │ │ │ └── application-dubbo-provider.xml │ │ ├── java │ │ └── net │ │ │ └── aimeizi │ │ │ ├── config │ │ │ └── ServiceConfig.java │ │ │ ├── starter │ │ │ ├── SpringBootStarter.java │ │ │ └── ApplicationBootstrap.java │ │ │ ├── service │ │ │ ├── order │ │ │ │ └── OrderServiceImpl.java │ │ │ ├── student │ │ │ │ ├── StudentServiceImpl.java │ │ │ │ ├── AnotherStudentRestServiceImpl.java │ │ │ │ ├── StudentRestServiceImpl.java │ │ │ │ └── AnnotationDrivenStudentRestServiceImpl.java │ │ │ ├── person │ │ │ │ └── PersonServiceImpl.java │ │ │ └── user │ │ │ │ ├── UserServiceImpl.java │ │ │ │ └── UserRestServiceImpl.java │ │ │ ├── utils │ │ │ └── ParamValidateUtils.java │ │ │ └── filter │ │ │ └── ServiceFilter.java │ │ └── webapp │ │ └── WEB-INF │ │ └── web.xml └── pom.xml ├── README.md ├── springboot-dubbox-api ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── dubbo │ │ │ ├── com.alibaba.dubbo.rpc.Filter │ │ │ └── com.alibaba.dubbo.rpc.Protocol │ │ ├── thrift │ │ ├── Order.thrift │ │ └── OrderService.thrift │ │ ├── avro │ │ ├── PersonService.avdl │ │ ├── QueryParameter.avsc │ │ └── Person.avsc │ │ └── java │ │ ├── net │ │ └── aimeizi │ │ │ ├── student │ │ │ ├── StudentService.java │ │ │ ├── StudentRestService.java │ │ │ ├── AnotherStudentRestService.java │ │ │ └── Student.java │ │ │ ├── exception │ │ │ ├── ParamException.java │ │ │ ├── ServiceException.java │ │ │ └── ValidationExceptionMapper.java │ │ │ ├── user │ │ │ ├── UserService.java │ │ │ ├── UserRestService.java │ │ │ └── User.java │ │ │ ├── SerializationOptimizerImpl.java │ │ │ ├── consts │ │ │ └── ServiceConst.java │ │ │ ├── DataResult.java │ │ │ └── person │ │ │ ├── PersonService.java │ │ │ ├── QueryParameter.java │ │ │ └── Person.java │ │ └── com │ │ └── alibaba │ │ └── dubbo │ │ └── rpc │ │ └── protocol │ │ ├── avro │ │ └── AvroProtocol.java │ │ └── thrift2 │ │ └── Thrift2Protocol.java ├── thrift-0.9.3.exe └── pom.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | *.ipr 5 | *.iws 6 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/resources/dubbo.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-dubbox-simple 2 | Dubbox整合Spring Boot基于Avro、Thrift协议构建REST服务 3 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter: -------------------------------------------------------------------------------- 1 | serviceFilter=net.aimeizi.filter.ServiceFilter -------------------------------------------------------------------------------- /springboot-dubbox-api/thrift-0.9.3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/v5tech/springboot-dubbox-simple/HEAD/springboot-dubbox-api/thrift-0.9.3.exe -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/thrift/Order.thrift: -------------------------------------------------------------------------------- 1 | namespace java net.aimeizi.order 2 | 3 | struct Order{ 4 | 1:required i32 orderId, 5 | 2:optional string orderTitle 6 | } -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Protocol: -------------------------------------------------------------------------------- 1 | avro=com.alibaba.dubbo.rpc.protocol.avro.AvroProtocol 2 | thrift2=com.alibaba.dubbo.rpc.protocol.thrift2.Thrift2Protocol -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/thrift/OrderService.thrift: -------------------------------------------------------------------------------- 1 | namespace java net.aimeizi.order 2 | 3 | include "Order.thrift" 4 | 5 | service OrderService{ 6 | 7 | string ping(); 8 | 9 | Order.Order getOrder(1:i32 orderId); 10 | 11 | } -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/net/aimeizi/config/RestServiceConfig.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.config; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 配置服务url 7 | */ 8 | 9 | @Data 10 | public class RestServiceConfig { 11 | 12 | private String baseUrl; 13 | } 14 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/config/ServiceConfig.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.config; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class ServiceConfig { 7 | 8 | /** 9 | * service provider发生错误时,是否抛出异常 10 | */ 11 | private boolean throwException = false; 12 | } 13 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/avro/PersonService.avdl: -------------------------------------------------------------------------------- 1 | @namespace ("net.aimeizi.person") 2 | protocol PersonService 3 | { 4 | import schema "Person.avsc"; 5 | import schema "QueryParameter.avsc"; 6 | string ping(); 7 | array getPersonList(net.aimeizi.person.QueryParameter queryParameter); 8 | } -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/avro/QueryParameter.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "namespace": "net.aimeizi.person", 3 | "type": "record", 4 | "name": "QueryParameter", 5 | "fields": [ 6 | { 7 | "name": "ageStart", 8 | "type": "int" 9 | }, 10 | { 11 | "name": "ageEnd", 12 | "type": "int" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/student/StudentService.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.student; 2 | 3 | import javax.validation.constraints.Min; 4 | import javax.ws.rs.BeanParam; 5 | 6 | /** 7 | * Created by Administrator on 2016/5/6 0006. 8 | * 非rest接口 9 | */ 10 | public interface StudentService { 11 | 12 | Student getStudent(@Min(value=0L, message="学生id必须大于0") Long id/*, HttpServletRequest request*/); 13 | 14 | Student registerStudent(@BeanParam Student student); 15 | } 16 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/exception/ParamException.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.exception; 2 | 3 | 4 | import net.aimeizi.consts.ServiceConst; 5 | 6 | public class ParamException extends ServiceException { 7 | 8 | 9 | public ParamException(String errMsg) { 10 | super(errMsg); 11 | setErrCode(ServiceConst.ErrorCode.PARAM_ERROR); 12 | } 13 | 14 | public ParamException(String errCode, String errMsg) { 15 | super(errCode, errMsg); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/student/StudentRestService.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.student; 2 | 3 | import javax.validation.constraints.Min; 4 | import javax.ws.rs.BeanParam; 5 | 6 | /** 7 | * Created by Administrator on 2016/5/6 0006. 8 | * 发布rest接口服务,注解添加在实现上 9 | */ 10 | public interface StudentRestService { 11 | 12 | Student getStudent(@Min(value=1L, message="学生id必须大于0") Long id/*, HttpServletRequest request*/); 13 | 14 | Student registerStudent(@BeanParam Student student); 15 | } -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/net/aimeizi/starter/JavaConfigBootstrap.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.starter; 2 | 3 | /** 4 | * 使用java config方式 5 | */ 6 | public class JavaConfigBootstrap { 7 | public static void main(String[] args) { 8 | // 实现Spring的JavaConfig配置方式,使用 Main.main(args) (需传参javaconfig设置使用JavaConfigContainer) 启动时可直接扫描 dubbo.spring.javaconfig 包下的所有的Spring配置类 9 | String[] customArgs = new String[]{"javaconfig"}; 10 | com.alibaba.dubbo.container.Main.main(customArgs); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/avro/Person.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "namespace": "net.aimeizi.person", 3 | "type": "record", 4 | "name": "Person", 5 | "fields": [ 6 | { 7 | "name": "age", 8 | "type": "int" 9 | }, 10 | { 11 | "name": "name", 12 | "type": "string" 13 | }, 14 | { 15 | "name": "sex", 16 | "type": "boolean" 17 | }, 18 | { 19 | "name": "salary", 20 | "type": "double" 21 | }, 22 | { 23 | "name": "childrenCount", 24 | "type": "int" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | dubbo-consumer 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | dubbo-consumer 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/user/UserService.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.user; 2 | 3 | 4 | import net.aimeizi.DataResult; 5 | import net.aimeizi.user.User; 6 | 7 | public interface UserService { 8 | 9 | /** 10 | * 检测服务健康状态用 11 | * @return 12 | */ 13 | String ping(); 14 | 15 | DataResult registerUser(User u); 16 | 17 | DataResult getUserById(Long userId); 18 | 19 | DataResult deleteUserById(Long userId); 20 | 21 | DataResult updatePassword(Long userId, String oldPwd, String newPwd); 22 | } -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/test/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/starter/SpringBootStarter.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.starter; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | /** 8 | * 使用SpringBoot启动容器 9 | */ 10 | @SpringBootApplication 11 | @ImportResource(locations={"META-INF/spring/application-dubbo-provider.xml"}) 12 | public class SpringBootStarter { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringBootStarter.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/starter/ApplicationBootstrap.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.starter; 2 | 3 | /** 4 | * 使用dubbo启动容器服务 5 | * Created by Administrator on 2016/5/4 0004. 6 | */ 7 | public class ApplicationBootstrap { 8 | 9 | public static void main(String[] args) throws Exception { 10 | 11 | // ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"classpath:META-INF/spring/application-dubbo-provider.xml"}); 12 | // context.start(); 13 | // System.in.read(); 14 | 15 | com.alibaba.dubbo.container.Main.main(args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/net/aimeizi/starter/ApplicationBootstrap.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.starter; 2 | 3 | /** 4 | * 使用dubbo启动容器服务 5 | * Created by Administrator on 2016/5/4 0004. 6 | */ 7 | public class ApplicationBootstrap { 8 | 9 | public static void main(String[] args) throws Exception { 10 | 11 | // ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"classpath:META-INF/spring/application-dubbo-consumer.xml"}); 12 | // context.start(); 13 | // System.in.read(); 14 | 15 | com.alibaba.dubbo.container.Main.main(args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/net/aimeizi/starter/SpringBootStarter.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.starter; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | /** 8 | * 使用SpringBoot启动容器 9 | */ 10 | @SpringBootApplication 11 | @ImportResource(locations = {"META-INF/dubbo/application-dubbo-consumer.xml"}) 12 | public class SpringBootStarter { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(net.aimeizi.starter.SpringBootStarter.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/order/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.order; 2 | 3 | import net.aimeizi.order.Order; 4 | import net.aimeizi.order.OrderService; 5 | import org.apache.thrift.TException; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service("orderService") 9 | public class OrderServiceImpl implements OrderService.Iface { 10 | 11 | 12 | @Override 13 | public String ping() throws TException { 14 | return "pong"; 15 | } 16 | 17 | @Override 18 | public Order getOrder(int orderId) throws TException { 19 | return new Order(orderId).setOrderTitle("dubbo"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/exception/ServiceException.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.exception; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | 7 | @Setter 8 | @Getter 9 | @ToString 10 | public class ServiceException extends Exception { 11 | 12 | private String errCode; 13 | 14 | private String errMsg; 15 | 16 | public ServiceException(String errCode, String errMsg) { 17 | super(errMsg); 18 | this.errCode = errCode; 19 | this.errMsg = errMsg; 20 | } 21 | 22 | public ServiceException(String errMsg) { 23 | super(errMsg); 24 | this.errMsg = errMsg; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/student/StudentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.student; 2 | 3 | import net.aimeizi.student.Student; 4 | import net.aimeizi.student.StudentService; 5 | 6 | import javax.validation.constraints.Min; 7 | 8 | /** 9 | * Created by Administrator on 2016/5/6 0006. 10 | * 普通的service实现类,非rest服务 11 | */ 12 | public class StudentServiceImpl implements StudentService { 13 | 14 | @Override 15 | public Student getStudent(@Min(value = 0L, message = "学生id必须大于0") Long id) { 16 | Student student = new Student(); 17 | student.setId(id); 18 | return student; 19 | } 20 | 21 | @Override 22 | public Student registerStudent(Student student) { 23 | return student; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/student/AnotherStudentRestService.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.student; 2 | 3 | import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; 4 | 5 | import javax.validation.constraints.Min; 6 | import javax.ws.rs.*; 7 | import javax.ws.rs.core.MediaType; 8 | 9 | /** 10 | * Created by Administrator on 2016/5/6 0006. 11 | * 发布rest接口服务,注解添加在接口上 12 | */ 13 | @Path("s") 14 | @Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML}) 15 | @Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8}) 16 | public interface AnotherStudentRestService { 17 | 18 | @GET 19 | @Path("{id : \\d+}") 20 | Student getStudent(@PathParam("id") @Min(value=1L, message="学生id必须大于0") Long id/*, HttpServletRequest request*/); 21 | 22 | @POST 23 | @Path("register") 24 | Student registerStudent(@BeanParam Student student); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/net/aimeizi/controller/StudentController.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.controller; 2 | 3 | import com.alibaba.dubbo.config.annotation.Reference; 4 | import lombok.Setter; 5 | import net.aimeizi.student.Student; 6 | import net.aimeizi.student.StudentService; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * Created by Administrator on 2016/5/6 0006. 13 | */ 14 | @RestController 15 | @RequestMapping("/students") 16 | public class StudentController { 17 | 18 | @Reference(group = "xmlConfig") 19 | @Setter 20 | private StudentService studentService; 21 | 22 | @RequestMapping("/get/{id}") 23 | public Student student(@PathVariable("id") Long id){ 24 | return studentService.getStudent(id); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/student/AnotherStudentRestServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.student; 2 | 3 | import lombok.Setter; 4 | import net.aimeizi.student.AnotherStudentRestService; 5 | import net.aimeizi.student.Student; 6 | import net.aimeizi.student.StudentService; 7 | 8 | import javax.validation.constraints.Min; 9 | import javax.ws.rs.BeanParam; 10 | 11 | /** 12 | * Created by Administrator on 2016/5/6 0006. 13 | * 发布rest接口服务,注解添加在接口上 14 | */ 15 | public class AnotherStudentRestServiceImpl implements AnotherStudentRestService { 16 | 17 | @Setter 18 | private StudentService studentService; 19 | 20 | @Override 21 | public Student getStudent(@Min(value = 1L, message = "学生id必须大于0") Long id) { 22 | return studentService.getStudent(id); 23 | } 24 | 25 | @Override 26 | public Student registerStudent(@BeanParam Student student) { 27 | return studentService.registerStudent(student); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/net/aimeizi/consumer/JavaConfigConsumer.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.consumer; 2 | 3 | import com.alibaba.dubbo.config.annotation.Reference; 4 | import net.aimeizi.student.AnotherStudentRestService; 5 | import net.aimeizi.student.Student; 6 | import org.springframework.stereotype.Component; 7 | 8 | import javax.annotation.PostConstruct; 9 | 10 | /** 11 | * Created by Administrator on 2016/5/6 0006. 12 | * java config consumer示例 13 | */ 14 | @Component 15 | public class JavaConfigConsumer { 16 | 17 | @Reference 18 | private AnotherStudentRestService anotherStudentRestService; 19 | 20 | @PostConstruct 21 | public void start() throws Exception { 22 | Student student = new Student(1L, "dubbo"); 23 | System.out.println("SUCESS: registered user with id " + anotherStudentRestService.registerStudent(student).getId()); 24 | System.out.println("SUCESS: got user " + anotherStudentRestService.getStudent(1L)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/person/PersonServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.person; 2 | 3 | import net.aimeizi.person.Person; 4 | import net.aimeizi.person.PersonService; 5 | import net.aimeizi.person.QueryParameter; 6 | import org.apache.avro.AvroRemoteException; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | @Service("personService") 13 | public class PersonServiceImpl implements PersonService { 14 | 15 | @Override 16 | public String ping() throws AvroRemoteException { 17 | return "pong"; 18 | } 19 | 20 | @Override 21 | public List getPersonList(QueryParameter queryParameter) throws AvroRemoteException { 22 | Person person = new Person(); 23 | person.setAge(queryParameter.getAgeStart()); 24 | person.setName("dubbo"); 25 | List persons = new ArrayList(); 26 | persons.add(person); 27 | return persons; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/SerializationOptimizerImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi; 2 | 3 | import com.alibaba.dubbo.common.serialize.support.SerializationOptimizer; 4 | import net.aimeizi.student.Student; 5 | import net.aimeizi.user.User; 6 | 7 | 8 | import java.util.Collection; 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | 12 | /** 13 | * 启用Kryo和FST序列化 14 | * 15 | * 16 | * 在生产环境建议使用Kryo 17 | * 要让Kryo和FST完全发挥出高性能,最好将那些需要被序列化的类注册到dubbo系统中实现该回调接口,注册需要被序列化的类 18 | * 19 | */ 20 | public class SerializationOptimizerImpl implements SerializationOptimizer { 21 | 22 | @Override 23 | public Collection getSerializableClasses() { 24 | List classes = new LinkedList(); 25 | classes.add(User.class); 26 | classes.add(DataResult.class); 27 | classes.add(Student.class); 28 | return classes; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/consts/ServiceConst.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.consts; 2 | 3 | 4 | public class ServiceConst { 5 | 6 | public static class ErrorCode { 7 | 8 | /** 9 | * 约定0开头的,代表各种未知错误 10 | */ 11 | public final static String UNKNOWN = "000"; 12 | 13 | /** 14 | * 约定1开头的,代表各种参数错误 15 | */ 16 | public final static String PARAM_ERROR = "100"; //参数错误 17 | public final static String PARAM_VALID_ERROR = "101"; //参数校验失败 18 | public final static String PARAM_EMPTY = "102"; //参数为空 19 | 20 | /** 21 | * 约定2开头的,代表各种DB层面的错误 22 | */ 23 | public final static String DB_ERROR = "200"; //数据库层面的错误 24 | } 25 | 26 | 27 | public static class HttpCode { 28 | public final static String Continue = "100"; 29 | public final static String SwitchingProtocols = "101"; 30 | public final static String Processing = "102"; 31 | public final static String OK = "200"; 32 | public final static String Created = "201"; 33 | public final static String Accepted = "202"; 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/student/Student.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.student; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.codehaus.jackson.annotate.JsonProperty; 7 | import org.hibernate.validator.constraints.Length; 8 | import org.hibernate.validator.constraints.Range; 9 | 10 | import javax.validation.constraints.NotNull; 11 | import javax.xml.bind.annotation.XmlAccessType; 12 | import javax.xml.bind.annotation.XmlAccessorType; 13 | import javax.xml.bind.annotation.XmlRootElement; 14 | import java.io.Serializable; 15 | 16 | /** 17 | * Created by Administrator on 2016/5/6 0006. 18 | */ 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | @Data 22 | @XmlRootElement 23 | @XmlAccessorType(XmlAccessType.FIELD) 24 | public class Student implements Serializable { 25 | 26 | /** 27 | * 学生ID 28 | */ 29 | @Range(min = 1, max = Long.MAX_VALUE, message = "Id必须大于0") 30 | private Long id; 31 | 32 | /** 33 | * 用户名 34 | */ 35 | @JsonProperty("username") 36 | @NotNull(message = "名称不能为空") 37 | @Length(min = 2, max = 20, message = "名称长度范围为2-20位字符") 38 | private String name; 39 | } 40 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | contextConfigLocation 9 | classpath:META-INF/spring/application-dubbo-provider.xml 10 | 11 | 12 | 13 | 14 | com.alibaba.dubbo.remoting.http.servlet.BootstrapListener 15 | 16 | 17 | 18 | org.springframework.web.context.ContextLoaderListener 19 | 20 | 21 | 22 | dispatcher 23 | com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet 24 | 1 25 | 26 | 27 | 28 | dispatcher 29 | /services/* 30 | 31 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/user/UserRestService.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.user; 2 | 3 | import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; 4 | import net.aimeizi.DataResult; 5 | 6 | import javax.validation.constraints.Min; 7 | import javax.ws.rs.*; 8 | import javax.ws.rs.core.MediaType; 9 | 10 | 11 | @Path("user") 12 | @Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML}) 13 | @Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8}) 14 | public interface UserRestService { 15 | 16 | @GET 17 | @Path("ping") 18 | String ping(); 19 | 20 | @POST 21 | @Path("register") 22 | DataResult registerUser(User u); 23 | 24 | @GET 25 | @Path("{id : \\d+}") 26 | DataResult getUserById(@PathParam("id") @Min(value = 1, message = "userId必须>0") Long userId); 27 | 28 | @POST 29 | @Path("delete") 30 | DataResult deleteUserById(Long userId); 31 | 32 | @POST 33 | @Path("update/pwd") 34 | DataResult updatePassword(Long userId, String oldPwd, String newPwd); 35 | 36 | @GET 37 | @Path("get") 38 | DataResult get(); 39 | 40 | @POST 41 | @Path("post") 42 | DataResult post(); 43 | } 44 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/user/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.user; 2 | 3 | import net.aimeizi.DataResult; 4 | import net.aimeizi.user.User; 5 | import net.aimeizi.user.UserService; 6 | import org.springframework.stereotype.Service; 7 | import java.util.Random; 8 | 9 | 10 | @Service("userService") 11 | public class UserServiceImpl implements UserService { 12 | @Override 13 | public String ping() { 14 | return "pong"; 15 | } 16 | 17 | @Override 18 | public DataResult registerUser(User u) { 19 | Random rnd = new Random(); 20 | u.setUserId(rnd.nextLong()); 21 | return new DataResult(u); 22 | } 23 | 24 | @Override 25 | public DataResult getUserById(Long userId) { 26 | User u = new User(); 27 | u.setUserId(userId); 28 | return new DataResult(u); 29 | } 30 | 31 | @Override 32 | public DataResult deleteUserById(Long userId) { 33 | return new DataResult(false); 34 | } 35 | 36 | @Override 37 | public DataResult updatePassword(Long userId, String oldPwd, String newPwd) { 38 | return new DataResult(true); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/student/StudentRestServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.student; 2 | 3 | import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; 4 | import lombok.Setter; 5 | import net.aimeizi.student.Student; 6 | import net.aimeizi.student.StudentRestService; 7 | import net.aimeizi.student.StudentService; 8 | 9 | import javax.validation.constraints.Min; 10 | import javax.ws.rs.*; 11 | import javax.ws.rs.core.MediaType; 12 | 13 | /** 14 | * Created by Administrator on 2016/5/6 0006. 15 | * 发布rest接口服务,注解添加在实现上 16 | */ 17 | @Path("students") 18 | @Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML}) 19 | @Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8}) 20 | public class StudentRestServiceImpl implements StudentRestService { 21 | 22 | @Setter 23 | private StudentService studentService; 24 | 25 | @GET 26 | @Path("{id : \\d+}") 27 | @Override 28 | public Student getStudent(@PathParam("id") @Min(value = 1L, message = "学生id必须大于0") Long id) { 29 | return studentService.getStudent(id); 30 | } 31 | 32 | @POST 33 | @Path("register") 34 | @Override 35 | public Student registerStudent(@BeanParam Student student) { 36 | return studentService.registerStudent(student); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/user/User.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.user; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.codehaus.jackson.annotate.JsonProperty; 7 | import org.hibernate.validator.constraints.Length; 8 | import org.hibernate.validator.constraints.Range; 9 | 10 | import javax.validation.constraints.NotNull; 11 | import javax.xml.bind.annotation.XmlAccessType; 12 | import javax.xml.bind.annotation.XmlAccessorType; 13 | import javax.xml.bind.annotation.XmlRootElement; 14 | import java.io.Serializable; 15 | 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | @Data 19 | @XmlRootElement 20 | @XmlAccessorType(XmlAccessType.FIELD) 21 | public class User implements Serializable { 22 | 23 | /** 24 | * 用户ID 25 | */ 26 | @Range(min = 1, max = Long.MAX_VALUE, message = "userId必须大于0") 27 | private Long userId; 28 | 29 | /** 30 | * 用户名 31 | */ 32 | @JsonProperty("username") 33 | @NotNull(message = "名称不能为空") 34 | @Length(min = 2, max = 20, message = "名称长度范围为2-20位字符") 35 | private String name; 36 | 37 | /** 38 | * 密码 39 | */ 40 | @Length(min = 8, message = "密码长度不能低于8位") 41 | private String password; 42 | 43 | /** 44 | * 年龄 45 | */ 46 | @Range(min = 0, max = 150, message = "年龄只能在0-150岁之间") 47 | private Integer age; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/exception/ValidationExceptionMapper.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.exception; 2 | 3 | 4 | import com.alibaba.dubbo.rpc.protocol.rest.RpcExceptionMapper; 5 | import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; 6 | import net.aimeizi.DataResult; 7 | import net.aimeizi.consts.ServiceConst; 8 | 9 | import javax.validation.ConstraintViolation; 10 | import javax.validation.ConstraintViolationException; 11 | import javax.ws.rs.core.Response; 12 | 13 | /** 14 | * 异常校验 15 | */ 16 | public class ValidationExceptionMapper extends RpcExceptionMapper { 17 | 18 | protected Response handleConstraintViolationException(ConstraintViolationException cve) { 19 | StringBuilder sb = new StringBuilder(); 20 | for (ConstraintViolation cv : cve.getConstraintViolations()) { 21 | sb.append(String.format("arg:%s,value:%s,message:%s", cv.getPropertyPath().toString(), 22 | (cv.getInvalidValue() == null ? "null" : cv.getInvalidValue().toString()), 23 | cv.getMessage())); 24 | } 25 | 26 | DataResult dataResult = new DataResult(ServiceConst.ErrorCode.PARAM_VALID_ERROR, sb.toString()); 27 | //class cls = Request.class. 28 | // Request 29 | return Response.status(Response.Status.OK).entity(dataResult). 30 | type(ContentType.APPLICATION_JSON_UTF_8).build(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/DataResult.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi; 2 | 3 | import lombok.Getter; 4 | import lombok.NoArgsConstructor; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | 8 | import javax.xml.bind.annotation.XmlRootElement; 9 | import java.io.Serializable; 10 | 11 | @Setter 12 | @Getter 13 | @ToString 14 | @NoArgsConstructor 15 | @XmlRootElement 16 | public class DataResult implements Serializable { 17 | 18 | 19 | private static final long serialVersionUID = 6847146041806712878L; 20 | 21 | public DataResult(T data) { 22 | this.data = data; 23 | this.isSuccess = true; 24 | } 25 | 26 | public DataResult(String errorCode, String errorDesc) { 27 | this.errorCode = errorCode; 28 | this.errorDesc = errorDesc; 29 | this.isSuccess = false; 30 | } 31 | 32 | public DataResult(String errorCode, String errorDesc, long elapsedMilliseconds) { 33 | this.errorCode = errorCode; 34 | this.errorDesc = errorDesc; 35 | this.isSuccess = false; 36 | this.elapsedMilliseconds = elapsedMilliseconds; 37 | } 38 | 39 | /** 40 | * 是否处理成功 41 | */ 42 | private boolean isSuccess; 43 | 44 | /** 45 | * 返回的数据 46 | */ 47 | private T data; 48 | 49 | /** 50 | * 错误代码 51 | */ 52 | private String errorCode; 53 | 54 | /** 55 | * 错误描述 56 | */ 57 | private String errorDesc; 58 | 59 | /** 60 | * 处理耗时(毫秒) 61 | */ 62 | private long elapsedMilliseconds; 63 | 64 | } 65 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/resources/META-INF/dubbo/application-dubbo-consumer.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/utils/ParamValidateUtils.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.utils; 2 | 3 | import javax.validation.*; 4 | import java.util.*; 5 | 6 | public class ParamValidateUtils { 7 | 8 | final static ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); 9 | final static Validator validator = factory.getValidator(); 10 | 11 | public static Map> validator(T t, HashSet skipFields) { 12 | Set> constraintViolations = validator.validate(t); 13 | if (constraintViolations != null && constraintViolations.size() > 0) { 14 | Map> mapErr = new HashMap>(); 15 | for (ConstraintViolation constraintViolation : constraintViolations) { 16 | for (Path.Node node : constraintViolation.getPropertyPath()) { 17 | String fieldName = node.getName(); 18 | if (skipFields == null || !skipFields.contains(fieldName)) { 19 | ArrayList lst = mapErr.get(fieldName); 20 | if (lst == null) { 21 | lst = new ArrayList(); 22 | } 23 | lst.add(constraintViolation.getMessage()); 24 | mapErr.put(node.getName(), lst); 25 | } 26 | } 27 | } 28 | return mapErr; 29 | } 30 | return null; 31 | } 32 | 33 | public static Map> validator(T t) { 34 | return validator(t, null); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/user/UserRestServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.user; 2 | 3 | import net.aimeizi.DataResult; 4 | import net.aimeizi.user.User; 5 | import net.aimeizi.user.UserRestService; 6 | import net.aimeizi.user.UserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.annotation.Resource; 10 | import javax.validation.constraints.Min; 11 | import javax.validation.constraints.NotNull; 12 | 13 | @Service("userRestService") 14 | public class UserRestServiceImpl implements UserRestService { 15 | 16 | @Resource(name = "userService") 17 | UserService userService; 18 | 19 | @Override 20 | public String ping() { 21 | return userService.ping(); 22 | } 23 | 24 | @Override 25 | public DataResult registerUser(User u) { 26 | return userService.registerUser(u); 27 | } 28 | 29 | @Override 30 | public DataResult getUserById(@Min(1L) Long userId) { 31 | return userService.getUserById(userId); 32 | } 33 | 34 | @Override 35 | public DataResult deleteUserById(Long userId) { 36 | return userService.deleteUserById(userId); 37 | } 38 | 39 | @Override 40 | public DataResult updatePassword(@Min(1L) Long userId, @NotNull String oldPwd, @NotNull String newPwd) { 41 | return userService.updatePassword(userId, oldPwd, newPwd); 42 | } 43 | 44 | @Override 45 | public DataResult get() { 46 | return new DataResult(true); 47 | } 48 | 49 | @Override 50 | public DataResult post() { 51 | return new DataResult(true); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/service/student/AnnotationDrivenStudentRestServiceImpl.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.service.student; 2 | 3 | import com.alibaba.dubbo.config.annotation.Service; 4 | import com.alibaba.dubbo.rpc.RpcContext; 5 | import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType; 6 | import lombok.Setter; 7 | import net.aimeizi.student.Student; 8 | import net.aimeizi.student.StudentRestService; 9 | import net.aimeizi.student.StudentService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.validation.constraints.Min; 14 | import javax.ws.rs.*; 15 | import javax.ws.rs.core.Context; 16 | import javax.ws.rs.core.MediaType; 17 | 18 | /** 19 | * Created by Administrator on 2016/5/6 0006. 20 | * 基于注解驱动的rest服务 21 | */ 22 | 23 | @Service(protocol = {"rest", "dubbo"}, group = "annotationConfig", validation = "true") 24 | @Path("customers") 25 | @Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML}) 26 | @Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8}) 27 | public class AnnotationDrivenStudentRestServiceImpl implements StudentRestService { 28 | 29 | @Autowired 30 | @Setter 31 | private StudentService studentService; 32 | 33 | @Override 34 | @GET 35 | @Path("{id : \\d+}") 36 | public Student getStudent(@PathParam("id") @Min(value = 1L, message = "学生id必须大于0") Long id /*, @Context HttpServletRequest request, @Context HttpServletRequest request*/) { 37 | // System.out.println("Client address from @Context injection: " + (request != null ? request.getRemoteAddr() : "")); 38 | // System.out.println("Client address from RpcContext: " + RpcContext.getContext().getRemoteAddressString()); 39 | return studentService.getStudent(id); 40 | } 41 | 42 | @Override 43 | @POST 44 | @Path("register") 45 | public Student registerStudent(@BeanParam Student student) { 46 | return studentService.registerStudent(student); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/person/PersonService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Avro 3 | * 4 | * DO NOT EDIT DIRECTLY 5 | */ 6 | package net.aimeizi.person; 7 | 8 | @SuppressWarnings("all") 9 | @org.apache.avro.specific.AvroGenerated 10 | public interface PersonService { 11 | public static final org.apache.avro.Protocol PROTOCOL = org.apache.avro.Protocol.parse("{\"protocol\":\"PersonService\",\"namespace\":\"net.aimeizi.person\",\"types\":[{\"type\":\"record\",\"name\":\"Person\",\"fields\":[{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"sex\",\"type\":\"boolean\"},{\"name\":\"salary\",\"type\":\"double\"},{\"name\":\"childrenCount\",\"type\":\"int\"}]},{\"type\":\"record\",\"name\":\"QueryParameter\",\"fields\":[{\"name\":\"ageStart\",\"type\":\"int\"},{\"name\":\"ageEnd\",\"type\":\"int\"}]}],\"messages\":{\"ping\":{\"request\":[],\"response\":\"string\"},\"getPersonList\":{\"request\":[{\"name\":\"queryParameter\",\"type\":\"QueryParameter\"}],\"response\":{\"type\":\"array\",\"items\":\"Person\"}}}}"); 12 | /** 13 | */ 14 | java.lang.CharSequence ping() throws org.apache.avro.AvroRemoteException; 15 | /** 16 | */ 17 | java.util.List getPersonList(net.aimeizi.person.QueryParameter queryParameter) throws org.apache.avro.AvroRemoteException; 18 | 19 | @SuppressWarnings("all") 20 | public interface Callback extends PersonService { 21 | public static final org.apache.avro.Protocol PROTOCOL = net.aimeizi.person.PersonService.PROTOCOL; 22 | /** 23 | * @throws java.io.IOException The async call could not be completed. 24 | */ 25 | void ping(org.apache.avro.ipc.Callback callback) throws java.io.IOException; 26 | /** 27 | * @throws java.io.IOException The async call could not be completed. 28 | */ 29 | void getPersonList(net.aimeizi.person.QueryParameter queryParameter, org.apache.avro.ipc.Callback> callback) throws java.io.IOException; 30 | } 31 | } -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/dubbo/spring/javaconfig/JavaConsumerConfig.java: -------------------------------------------------------------------------------- 1 | package dubbo.spring.javaconfig; 2 | 3 | import com.alibaba.dubbo.config.ApplicationConfig; 4 | import com.alibaba.dubbo.config.RegistryConfig; 5 | import com.alibaba.dubbo.config.spring.AnnotationBean; 6 | import net.aimeizi.consumer.JavaConfigConsumer; 7 | import net.aimeizi.exception.ValidationExceptionMapper; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | /** 12 | * Created by Administrator on 2016/5/6 0006. 13 | * 将XML配置方式转换为JavaConfig配置 14 | * 实现Spring的JavaConfig配置方式,使用 Main.main(args) (需传参javaconfig设置使用JavaConfigContainer) 启动时可直接扫描 dubbo.spring.javaconfig 包下的所有的Spring配置类 15 | */ 16 | @Configuration 17 | public class JavaConsumerConfig { 18 | 19 | public static final String APPLICATION_NAME = "dubbo-consumer"; 20 | 21 | public static final String REGISTRY_ADDRESS = "zookeeper://127.0.0.1:2181"; 22 | 23 | public static final String ANNOTATION_PACKAGE = "net.aimeizi.consumer"; 24 | 25 | /** 26 | * 自动装配消费者 27 | * @return 28 | */ 29 | @Bean 30 | public JavaConfigConsumer javaConfigConsumer(){ 31 | // 会调用@PostConstruct注解标注的方法 32 | return new JavaConfigConsumer(); 33 | } 34 | 35 | @Bean 36 | public ValidationExceptionMapper validationExceptionMapper(){ 37 | return new ValidationExceptionMapper(); 38 | } 39 | 40 | @Bean 41 | public ApplicationConfig applicationConfig() { 42 | ApplicationConfig applicationConfig = new ApplicationConfig(); 43 | applicationConfig.setName(APPLICATION_NAME); 44 | return applicationConfig; 45 | } 46 | 47 | @Bean 48 | public RegistryConfig registryConfig() { 49 | RegistryConfig registryConfig = new RegistryConfig(); 50 | registryConfig.setAddress(REGISTRY_ADDRESS); 51 | return registryConfig; 52 | } 53 | 54 | @Bean 55 | public AnnotationBean annotationBean() { 56 | AnnotationBean annotationBean = new AnnotationBean(); 57 | annotationBean.setPackage(ANNOTATION_PACKAGE); 58 | return annotationBean; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/com/alibaba/dubbo/rpc/protocol/avro/AvroProtocol.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.dubbo.rpc.protocol.avro; 2 | 3 | import com.alibaba.dubbo.common.URL; 4 | import com.alibaba.dubbo.common.logger.Logger; 5 | import com.alibaba.dubbo.common.logger.LoggerFactory; 6 | import com.alibaba.dubbo.rpc.RpcException; 7 | import com.alibaba.dubbo.rpc.protocol.AbstractProxyProtocol; 8 | import org.apache.avro.ipc.NettyServer; 9 | import org.apache.avro.ipc.NettyTransceiver; 10 | import org.apache.avro.ipc.Server; 11 | import org.apache.avro.ipc.reflect.ReflectRequestor; 12 | import org.apache.avro.ipc.reflect.ReflectResponder; 13 | 14 | import java.net.InetSocketAddress; 15 | 16 | /** 17 | * 为dubbo-rpc添加avro支持 18 | * Created by Administrator on 2016/5/5 0005. 19 | */ 20 | public class AvroProtocol extends AbstractProxyProtocol { 21 | public static final int DEFAULT_PORT = 40881; 22 | private static final Logger logger = LoggerFactory.getLogger(AvroProtocol.class); 23 | 24 | public int getDefaultPort() { 25 | return DEFAULT_PORT; 26 | } 27 | 28 | @Override 29 | protected Runnable doExport(T impl, Class type, URL url) 30 | throws RpcException { 31 | 32 | logger.info("impl => " + impl.getClass()); 33 | logger.info("type => " + type.getName()); 34 | logger.info("url => " + url); 35 | 36 | final Server server = new NettyServer(new ReflectResponder(type, impl), 37 | new InetSocketAddress(url.getHost(), url.getPort())); 38 | server.start(); 39 | 40 | return new Runnable() { 41 | public void run() { 42 | try { 43 | logger.info("Close Avro Server"); 44 | server.close(); 45 | } catch (Throwable e) { 46 | logger.warn(e.getMessage(), e); 47 | } 48 | } 49 | }; 50 | } 51 | 52 | @Override 53 | protected T doRefer(Class type, URL url) throws RpcException { 54 | 55 | logger.info("type => " + type.getName()); 56 | logger.info("url => " + url); 57 | 58 | try { 59 | NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(url.getHost(), url.getPort())); 60 | T ref = ReflectRequestor.getClient(type, client); 61 | logger.info("Create Avro Client"); 62 | return ref; 63 | } catch (Exception e) { 64 | logger.error(e.getMessage(), e); 65 | throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e); 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/test/java/net/aimeizi/RestClient.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi; 2 | 3 | import net.aimeizi.student.Student; 4 | 5 | import javax.ws.rs.client.Client; 6 | import javax.ws.rs.client.ClientBuilder; 7 | import javax.ws.rs.client.Entity; 8 | import javax.ws.rs.client.WebTarget; 9 | import javax.ws.rs.core.MediaType; 10 | import javax.ws.rs.core.Response; 11 | 12 | /** 13 | * 测试rest服务 14 | */ 15 | public class RestClient { 16 | 17 | public static void main(String[] args) { 18 | 19 | final String port = "8000"; 20 | 21 | registerStudent("http://localhost:" + port + "/services/students/register.json", MediaType.APPLICATION_JSON_TYPE); 22 | 23 | registerStudent("http://localhost:" + port + "/services/students/register.xml", MediaType.TEXT_XML_TYPE); 24 | 25 | getStudent("http://localhost:" + port + "/services/students/1.json"); 26 | 27 | getStudent("http://localhost:" + port + "/services/students/2.xml"); 28 | 29 | registerStudent("http://localhost:" + port + "/services/s/register.json", MediaType.APPLICATION_JSON_TYPE); 30 | 31 | registerStudent("http://localhost:" + port + "/services/s/register.xml", MediaType.TEXT_XML_TYPE); 32 | 33 | getStudent("http://localhost:" + port + "/services/s/1.json"); 34 | 35 | getStudent("http://localhost:" + port + "/services/s/2.xml"); 36 | 37 | registerStudent("http://localhost:" + port + "/services/customers/register.json", MediaType.APPLICATION_JSON_TYPE); 38 | 39 | registerStudent("http://localhost:" + port + "/services/customers/register.xml", MediaType.TEXT_XML_TYPE); 40 | 41 | getStudent("http://localhost:" + port + "/services/customers/1.json"); 42 | 43 | getStudent("http://localhost:" + port + "/services/customers/2.xml"); 44 | 45 | } 46 | 47 | private static void registerStudent(String url, MediaType mediaType) { 48 | System.out.println("Registering student via " + url); 49 | Student student = new Student(1L, "dubbo"); 50 | Client client = ClientBuilder.newClient(); 51 | WebTarget target = client.target(url); 52 | Response response = target.request().post(Entity.entity(student, mediaType)); 53 | 54 | try { 55 | if (response.getStatus() != 200) { 56 | throw new RuntimeException("Failed with HTTP error code : " + response.getStatus()); 57 | } 58 | System.out.println("Successfully got result: " + response.readEntity(String.class)); 59 | } finally { 60 | response.close(); 61 | client.close(); 62 | } 63 | } 64 | 65 | private static void getStudent(String url) { 66 | System.out.println("Getting student via " + url); 67 | Client client = ClientBuilder.newClient(); 68 | WebTarget target = client.target(url); 69 | Response response = target.request().get(); 70 | try { 71 | if (response.getStatus() != 200) { 72 | throw new RuntimeException("Failed with HTTP error code : " + response.getStatus()); 73 | } 74 | System.out.println("Successfully got result: " + response.readEntity(String.class)); 75 | } finally { 76 | response.close(); 77 | client.close(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/java/net/aimeizi/filter/ServiceFilter.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi.filter; 2 | 3 | import com.alibaba.dubbo.rpc.*; 4 | import lombok.Setter; 5 | import net.aimeizi.DataResult; 6 | import net.aimeizi.config.ServiceConfig; 7 | import net.aimeizi.consts.ServiceConst; 8 | import net.aimeizi.exception.ParamException; 9 | import net.aimeizi.exception.ServiceException; 10 | import net.aimeizi.utils.ParamValidateUtils; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.stereotype.Component; 14 | 15 | import java.util.ArrayList; 16 | import java.util.Map; 17 | 18 | @Component("serviceFilter") 19 | public class ServiceFilter implements Filter { 20 | 21 | final static Logger logger = LoggerFactory.getLogger(ServiceFilter.class); 22 | 23 | //坑1:不要用@Autowired注入,拿不到对象,改用setter 24 | @Setter 25 | ServiceConfig serviceConfig; 26 | 27 | @Override 28 | public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { 29 | 30 | long start = System.currentTimeMillis(); 31 | 32 | StringBuilder sb = new StringBuilder(); 33 | 34 | try { 35 | 36 | //1. log params info 37 | sb.append(invocation.toString()); 38 | 39 | //2. param validate 40 | for (Object arg : invocation.getArguments()) { 41 | Map> validateResult = ParamValidateUtils.validator(arg); 42 | if (validateResult != null) { 43 | for (Map.Entry> entry : validateResult.entrySet()) { 44 | sb.append(" , 参数:" + arg + " , " + entry.getKey() + " 校验失败 , 原因: " + entry.getValue()); 45 | long end = System.currentTimeMillis(); 46 | long elapsedMilliseconds = end - start; 47 | sb.append(" , 执行耗时: " + elapsedMilliseconds + " 毫秒"); 48 | DataResult dataResult = new DataResult(ServiceConst.ErrorCode.PARAM_VALID_ERROR, entry. 49 | getKey() + ":" 50 | + entry.getValue(), elapsedMilliseconds); 51 | RpcResult result = new RpcResult(dataResult); 52 | result.setAttachments(invocation.getAttachments()); 53 | if (serviceConfig.isThrowException()) { 54 | result.setException(new ParamException(ServiceConst.ErrorCode.PARAM_VALID_ERROR)); 55 | } 56 | 57 | logger.error(sb.toString()); 58 | return result; 59 | } 60 | } 61 | } 62 | 63 | //3. invoke 64 | Result result = invoker.invoke(invocation); 65 | 66 | //4. log result 67 | sb.append(" , 调用结果: " + result.toString()); 68 | long end = System.currentTimeMillis(); 69 | long elapsedMilliseconds = end - start; 70 | sb.append(" , 执行耗时: " + elapsedMilliseconds + " 毫秒"); 71 | 72 | if (result.getValue() != null && result.getValue() instanceof DataResult) { 73 | ((DataResult) result.getValue()).setElapsedMilliseconds(elapsedMilliseconds); 74 | } 75 | 76 | logger.info(sb.toString()); 77 | 78 | return result; 79 | 80 | } catch (Exception e) { 81 | DataResult dataResult = new DataResult(ServiceConst.ErrorCode.UNKNOWN, e.getMessage()); 82 | RpcResult result = new RpcResult(dataResult); 83 | result.setAttachments(invocation.getAttachments()); 84 | if (serviceConfig.isThrowException()) { 85 | result.setException(new ServiceException(ServiceConst.ErrorCode.UNKNOWN, e.getMessage())); 86 | } 87 | sb.append(" , 调用结果: " + result.toString()); 88 | 89 | long end = System.currentTimeMillis(); 90 | long elapsedMilliseconds = end - start; 91 | 92 | sb.append(" , 执行耗时: " + elapsedMilliseconds + " 毫秒"); 93 | dataResult.setElapsedMilliseconds(elapsedMilliseconds); 94 | logger.error(sb.toString()); 95 | 96 | return result; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/com/alibaba/dubbo/rpc/protocol/thrift2/Thrift2Protocol.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.dubbo.rpc.protocol.thrift2; 2 | 3 | import com.alibaba.dubbo.common.URL; 4 | import com.alibaba.dubbo.common.logger.Logger; 5 | import com.alibaba.dubbo.common.logger.LoggerFactory; 6 | import com.alibaba.dubbo.rpc.RpcException; 7 | import com.alibaba.dubbo.rpc.protocol.AbstractProxyProtocol; 8 | import org.apache.thrift.TProcessor; 9 | import org.apache.thrift.protocol.TCompactProtocol; 10 | import org.apache.thrift.protocol.TProtocol; 11 | import org.apache.thrift.server.TNonblockingServer; 12 | import org.apache.thrift.server.TServer; 13 | import org.apache.thrift.transport.TFramedTransport; 14 | import org.apache.thrift.transport.TNonblockingServerSocket; 15 | import org.apache.thrift.transport.TSocket; 16 | import org.apache.thrift.transport.TTransport; 17 | 18 | import java.lang.reflect.Constructor; 19 | 20 | /** 21 | * 为dubbo-rpc添加thrift2支持 22 | * Created by Administrator on 2016/5/5 0005. 23 | */ 24 | public class Thrift2Protocol extends AbstractProxyProtocol { 25 | public static final int DEFAULT_PORT = 33208; 26 | private static final Logger logger = LoggerFactory.getLogger(Thrift2Protocol.class); 27 | 28 | public int getDefaultPort() { 29 | return DEFAULT_PORT; 30 | } 31 | 32 | @Override 33 | protected Runnable doExport(T impl, Class type, URL url) 34 | throws RpcException { 35 | 36 | logger.info("impl => " + impl.getClass()); 37 | logger.info("type => " + type.getName()); 38 | logger.info("url => " + url); 39 | 40 | TProcessor tprocessor; 41 | TNonblockingServer.Args tArgs = null; 42 | String iFace = "$Iface"; 43 | String processor = "$Processor"; 44 | String typeName = type.getName(); 45 | TNonblockingServerSocket transport; 46 | if (typeName.endsWith(iFace)) { 47 | String processorClsName = typeName.substring(0, typeName.indexOf(iFace)) + processor; 48 | try { 49 | Class clazz = Class.forName(processorClsName); 50 | Constructor constructor = clazz.getConstructor(type); 51 | try { 52 | tprocessor = (TProcessor) constructor.newInstance(impl); 53 | transport = new TNonblockingServerSocket(url.getPort()); 54 | tArgs = new TNonblockingServer.Args(transport); 55 | tArgs.processor(tprocessor); 56 | tArgs.transportFactory(new TFramedTransport.Factory()); 57 | tArgs.protocolFactory(new TCompactProtocol.Factory()); 58 | } catch (Exception e) { 59 | logger.error(e.getMessage(), e); 60 | throw new RpcException("Fail to create thrift server(" + url + ") : " + e.getMessage(), e); 61 | } 62 | } catch (Exception e) { 63 | logger.error(e.getMessage(), e); 64 | throw new RpcException("Fail to create thrift server(" + url + ") : " + e.getMessage(), e); 65 | } 66 | } 67 | 68 | if (tArgs == null) { 69 | logger.error("Fail to create thrift server(" + url + ") due to null args"); 70 | throw new RpcException("Fail to create thrift server(" + url + ") due to null args"); 71 | } 72 | final TServer thriftServer = new TNonblockingServer(tArgs); 73 | 74 | new Thread(new Runnable() { 75 | public void run() { 76 | logger.info("Start Thrift Server"); 77 | thriftServer.serve(); 78 | logger.info("Thrift server started."); 79 | } 80 | }).start(); 81 | 82 | return new Runnable() { 83 | public void run() { 84 | try { 85 | logger.info("Close Thrift Server"); 86 | thriftServer.stop(); 87 | } catch (Throwable e) { 88 | logger.warn(e.getMessage(), e); 89 | } 90 | } 91 | }; 92 | } 93 | 94 | @Override 95 | protected T doRefer(Class type, URL url) throws RpcException { 96 | 97 | logger.info("type => " + type.getName()); 98 | logger.info("url => " + url); 99 | 100 | try { 101 | TSocket tSocket; 102 | TTransport transport; 103 | TProtocol protocol; 104 | T thriftClient = null; 105 | String iFace = "$Iface"; 106 | String client = "$Client"; 107 | 108 | String typeName = type.getName(); 109 | if (typeName.endsWith(iFace)) { 110 | String clientClsName = typeName.substring(0, typeName.indexOf(iFace)) + client; 111 | Class clazz = Class.forName(clientClsName); 112 | Constructor constructor = clazz.getConstructor(TProtocol.class); 113 | try { 114 | tSocket = new TSocket(url.getHost(), url.getPort()); 115 | transport = new TFramedTransport(tSocket); 116 | protocol = new TCompactProtocol(transport); 117 | thriftClient = (T) constructor.newInstance(protocol); 118 | transport.open(); 119 | logger.info("thrift client opened for service(" + url + ")"); 120 | } catch (Exception e) { 121 | logger.error(e.getMessage(), e); 122 | throw new RpcException("Fail to create remoting client:" + e.getMessage(), e); 123 | } 124 | } 125 | return thriftClient; 126 | } catch (Exception e) { 127 | logger.error(e.getMessage(), e); 128 | throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e); 129 | } 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /springboot-dubbox-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | net.aimeizi 8 | springboot-dubbox-simple 9 | 1.0 10 | 11 | 12 | springboot-dubbox-api 13 | jar 14 | springboot-dubbox-api 15 | Simple Project for Spring Boot Dubbox Api 16 | 17 | 18 | 19 | org.projectlombok 20 | lombok 21 | 22 | 23 | com.alibaba 24 | dubbo 25 | 26 | 27 | javax.servlet 28 | javax.servlet-api 29 | 30 | 31 | javax.validation 32 | validation-api 33 | 34 | 35 | org.hibernate 36 | hibernate-validator 37 | 38 | 39 | javax.ws.rs 40 | javax.ws.rs-api 41 | 42 | 43 | javax.annotation 44 | javax.annotation-api 45 | 46 | 47 | org.codehaus.jackson 48 | jackson-mapper-asl 49 | 50 | 51 | 52 | org.jboss.resteasy 53 | resteasy-client 54 | 55 | 56 | 57 | org.jboss.resteasy 58 | resteasy-jaxrs 59 | 60 | 61 | 62 | org.jboss.resteasy 63 | resteasy-netty 64 | 65 | 66 | 67 | org.jboss.resteasy 68 | resteasy-jackson-provider 69 | 70 | 71 | org.jboss.resteasy 72 | resteasy-jaxb-provider 73 | 74 | 75 | 76 | com.esotericsoftware.kryo 77 | kryo 78 | 79 | 80 | 81 | de.javakaffee 82 | kryo-serializers 83 | 84 | 85 | 86 | org.apache.avro 87 | avro 88 | 89 | 90 | 91 | org.apache.avro 92 | avro-ipc 93 | 94 | 95 | 96 | org.apache.thrift 97 | libthrift 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | org.apache.avro 107 | avro-maven-plugin 108 | 1.8.0 109 | 110 | 111 | schemas 112 | generate-sources 113 | 114 | schema 115 | protocol 116 | idl-protocol 117 | 118 | 119 | ${project.basedir}/src/main/avro/ 120 | ${project.basedir}/src/main/java/ 121 | 122 | 123 | 124 | 125 | 126 | org.apache.thrift.tools 127 | maven-thrift-plugin 128 | 0.1.11 129 | 130 | ${project.basedir}/thrift-0.9.3.exe 131 | 132 | 133 | 134 | thrift-sources 135 | generate-sources 136 | 137 | compile 138 | 139 | 140 | 141 | thrift-test-sources 142 | generate-test-sources 143 | 144 | testCompile 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /springboot-dubbox-webapp/src/main/java/net/aimeizi/ServiceConsumer.java: -------------------------------------------------------------------------------- 1 | package net.aimeizi; 2 | 3 | import net.aimeizi.config.RestServiceConfig; 4 | import net.aimeizi.order.OrderService; 5 | import net.aimeizi.person.PersonService; 6 | import net.aimeizi.user.User; 7 | import net.aimeizi.user.UserService; 8 | import org.apache.avro.AvroRemoteException; 9 | import org.apache.thrift.TException; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.context.ApplicationContext; 13 | import org.springframework.context.support.ClassPathXmlApplicationContext; 14 | 15 | import javax.ws.rs.client.Client; 16 | import javax.ws.rs.client.ClientBuilder; 17 | import javax.ws.rs.client.Entity; 18 | import javax.ws.rs.client.WebTarget; 19 | import javax.ws.rs.core.MediaType; 20 | import javax.ws.rs.core.Response; 21 | import java.io.IOException; 22 | 23 | public class ServiceConsumer { 24 | 25 | private static Logger logger = null; 26 | 27 | private static String baseUrl = ""; 28 | 29 | private final static Client client = ClientBuilder.newClient(); 30 | 31 | public static void main(String[] args) throws IOException, TException { 32 | 33 | ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/dubbo/application-dubbo-consumer.xml"); 34 | 35 | logger = LoggerFactory.getLogger(ServiceConsumer.class); 36 | 37 | baseUrl = context.getBean(RestServiceConfig.class).getBaseUrl(); 38 | 39 | UserService dubboService = context.getBean(UserService.class, "userService"); 40 | System.out.println("dubboService ping:" + dubboService.ping()); 41 | 42 | PersonService avroService = context.getBean("personService", PersonService.class); 43 | System.out.println("avroService ping:" + avroService.ping()); 44 | 45 | OrderService.Iface thriftService = context.getBean("orderService", OrderService.Iface.class); 46 | System.out.println("thriftService ping:" + thriftService.ping()); 47 | 48 | rpcTest(dubboService); 49 | 50 | restTest(); 51 | 52 | performanceTest(dubboService, avroService, thriftService); 53 | 54 | restErrorTest(); 55 | 56 | } 57 | 58 | private static void restErrorTest() { 59 | post(baseUrl + "register", getUser(0L), MediaType.APPLICATION_JSON_TYPE); 60 | } 61 | 62 | private static void restTest() { 63 | logger.info("\nREST test begin ..."); 64 | get(baseUrl + "0"); 65 | get(baseUrl + "2"); 66 | post(baseUrl + "delete", 2L, MediaType.APPLICATION_JSON_TYPE); 67 | post(baseUrl + "post", "", MediaType.APPLICATION_JSON_TYPE); 68 | post(baseUrl + "register", getUser(3L), MediaType.APPLICATION_JSON_TYPE); 69 | } 70 | 71 | 72 | private static void rpcTest(UserService userService) { 73 | logger.info("rpc test begin ..."); 74 | logger.info("getUserById test => "); 75 | logger.info(userService.getUserById(1L).toString()); 76 | logger.info(userService.ping()); 77 | logger.info(userService.deleteUserById(2L).toString()); 78 | logger.info(userService.updatePassword(1L, "12345678", "abcdefgh").toString()); 79 | logger.info(userService.registerUser(getUser(5L)).toString()); 80 | } 81 | 82 | 83 | private static void performanceTest(UserService dubboService, PersonService avroService, OrderService.Iface thriftService) throws AvroRemoteException, TException { 84 | 85 | System.out.println(dubboService.ping()); 86 | get(baseUrl + "ping"); 87 | System.out.println(avroService.ping()); 88 | 89 | logger.warn("dubbo RPC testing => "); 90 | 91 | int max = 50000; 92 | long start = System.currentTimeMillis(); 93 | 94 | for (int i = 0; i < max; i++) { 95 | dubboService.ping(); 96 | } 97 | 98 | long end = System.currentTimeMillis(); 99 | long elapsedMilliseconds = end - start; 100 | 101 | logger.warn(String.format("%d次RPC调用(dubbo协议),共耗时%d毫秒,平均%f/秒", max, elapsedMilliseconds, max / (elapsedMilliseconds / 1000.0F))); 102 | 103 | logger.warn("avro RPC testing => "); 104 | 105 | start = System.currentTimeMillis(); 106 | for (int i = 0; i < max; i++) { 107 | avroService.ping(); 108 | } 109 | end = System.currentTimeMillis(); 110 | elapsedMilliseconds = end - start; 111 | 112 | logger.warn(String.format("%d次RPC调用(avro协议),共耗时%d毫秒,平均%f/秒", max, elapsedMilliseconds, max / (elapsedMilliseconds / 1000.0F))); 113 | 114 | 115 | logger.warn("thrift RPC testing => "); 116 | 117 | start = System.currentTimeMillis(); 118 | for (int i = 0; i < max; i++) { 119 | thriftService.ping(); 120 | } 121 | end = System.currentTimeMillis(); 122 | elapsedMilliseconds = end - start; 123 | 124 | logger.warn(String.format("%d次RPC调用(thrift协议),共耗时%d毫秒,平均%f/秒", max, elapsedMilliseconds, max / (elapsedMilliseconds / 1000.0F))); 125 | 126 | 127 | logger.warn("REST testing => "); 128 | 129 | start = System.currentTimeMillis(); 130 | for (int i = 0; i < max; i++) { 131 | get(baseUrl + "ping"); 132 | } 133 | end = System.currentTimeMillis(); 134 | elapsedMilliseconds = end - start; 135 | 136 | logger.warn(String.format("%d次REST调用,共耗时%d毫秒,平均%f/秒", max, elapsedMilliseconds, max / (elapsedMilliseconds / 1000.0F))); 137 | } 138 | 139 | private static void get(String url) { 140 | logger.info(url); 141 | WebTarget target = client.target(url); 142 | Response response = target.request().get(); 143 | output(response, client); 144 | } 145 | 146 | private static void post(String url, T t, MediaType mediaType) { 147 | WebTarget target = client.target(url); 148 | Response response = target.request().buildPost(Entity.entity(t, mediaType)).invoke(); 149 | output(response, client); 150 | } 151 | 152 | private static void output(Response response, Client client) { 153 | try { 154 | if (response.getStatus() != 200) { 155 | throw new RuntimeException("Failed with HTTP error code : " + response.getStatus()); 156 | } 157 | logger.debug(response.readEntity(String.class)); 158 | } finally { 159 | response.close(); 160 | //client.close(); 161 | } 162 | } 163 | 164 | private static User getUser(Long i) { 165 | return new User(i, "jimmy", "123456ab", 20); 166 | } 167 | } -------------------------------------------------------------------------------- /springboot-dubbox-webapp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | net.aimeizi 8 | springboot-dubbox-simple 9 | 1.0 10 | 11 | 12 | springboot-dubbox-webapp 13 | war 14 | springboot-dubbox-webapp 15 | Simple Project for Spring Boot Dubbox WebApp 16 | 17 | 18 | 19 | 20 | org.projectlombok 21 | lombok 22 | 23 | 24 | 25 | net.aimeizi 26 | springboot-dubbox-api 27 | 1.0 28 | 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | org.springframework 39 | spring-context 40 | 41 | 42 | 43 | 44 | com.alibaba 45 | dubbo 46 | 47 | 48 | 49 | org.apache.mina 50 | mina-core 51 | 52 | 53 | 54 | javax.servlet 55 | javax.servlet-api 56 | 57 | 58 | 59 | javax.el 60 | javax.el-api 61 | 62 | 63 | org.glassfish.web 64 | javax.el 65 | 66 | 67 | org.glassfish.grizzly 68 | grizzly-core 69 | 70 | 71 | com.alibaba 72 | fastjson 73 | 74 | 75 | com.thoughtworks.xstream 76 | xstream 77 | 78 | 79 | org.apache.bsf 80 | bsf-api 81 | 82 | 83 | org.apache.zookeeper 84 | zookeeper 85 | 86 | 87 | com.github.sgroschupf 88 | zkclient 89 | 90 | 91 | 92 | com.googlecode.xmemcached 93 | xmemcached 94 | 95 | 96 | org.apache.cxf 97 | cxf-rt-frontend-simple 98 | 99 | 100 | org.apache.cxf 101 | cxf-rt-transports-http 102 | 103 | 104 | org.apache.thrift 105 | libthrift 106 | 107 | 108 | com.caucho 109 | hessian 110 | 111 | 112 | org.mortbay.jetty 113 | jetty 114 | 115 | 116 | redis.clients 117 | jedis 118 | 119 | 120 | javax.validation 121 | validation-api 122 | 123 | 124 | org.hibernate 125 | hibernate-validator 126 | 127 | 128 | javax.cache 129 | cache-api 130 | 131 | 132 | 133 | org.jboss.resteasy 134 | resteasy-jaxrs 135 | 136 | 137 | 138 | org.jboss.resteasy 139 | resteasy-client 140 | 141 | 142 | 143 | org.jboss.resteasy 144 | resteasy-netty 145 | 146 | 147 | 148 | org.jboss.resteasy 149 | resteasy-jdk-http 150 | 151 | 152 | 153 | org.jboss.resteasy 154 | resteasy-jackson-provider 155 | 156 | 157 | 158 | org.jboss.resteasy 159 | resteasy-jaxb-provider 160 | 161 | 162 | 163 | org.codehaus.jackson 164 | jackson-mapper-asl 165 | 166 | 167 | 168 | javax.xml.bind 169 | jaxb-api 170 | 171 | 172 | 173 | org.apache.tomcat.embed 174 | tomcat-embed-core 175 | 176 | 177 | org.apache.tomcat.embed 178 | tomcat-embed-logging-juli 179 | 180 | 181 | 182 | com.esotericsoftware.kryo 183 | kryo 184 | 185 | 186 | de.javakaffee 187 | kryo-serializers 188 | 189 | 190 | de.ruedigermoeller 191 | fst 192 | 193 | 194 | 195 | org.apache.avro 196 | avro 197 | 198 | 199 | 200 | org.apache.avro 201 | avro-ipc 202 | 203 | 204 | 205 | org.apache.thrift 206 | libthrift 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | org.springframework.boot 215 | spring-boot-maven-plugin 216 | 217 | 218 | 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /springboot-dubbox-service/src/main/resources/META-INF/spring/application-dubbo-provider.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 100 | 101 | 103 | 104 | 106 | 107 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /springboot-dubbox-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | net.aimeizi 8 | springboot-dubbox-simple 9 | 1.0 10 | 11 | 12 | springboot-dubbox-service 13 | jar 14 | springboot-dubbox-service 15 | Simple Project for Spring Boot Dubbox Service 16 | 17 | 18 | 19 | 20 | org.projectlombok 21 | lombok 22 | 23 | 24 | 25 | 26 | net.aimeizi 27 | springboot-dubbox-api 28 | 1.0 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-security 41 | 42 | 43 | 44 | org.springframework.data 45 | spring-data-commons 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework 53 | spring-core 54 | 55 | 56 | 57 | org.springframework 58 | spring-context 59 | 60 | 61 | 62 | org.springframework 63 | spring-context-support 64 | 65 | 66 | 67 | org.springframework 68 | spring-beans 69 | 70 | 71 | 72 | 73 | 74 | 75 | com.alibaba 76 | dubbo 77 | 78 | 79 | 80 | org.apache.mina 81 | mina-core 82 | 83 | 84 | 85 | javax.servlet 86 | javax.servlet-api 87 | 88 | 89 | 90 | javax.el 91 | javax.el-api 92 | 93 | 94 | org.glassfish.web 95 | javax.el 96 | 97 | 98 | org.glassfish.grizzly 99 | grizzly-core 100 | 101 | 102 | com.alibaba 103 | fastjson 104 | 105 | 106 | com.thoughtworks.xstream 107 | xstream 108 | 109 | 110 | org.apache.bsf 111 | bsf-api 112 | 113 | 114 | org.apache.zookeeper 115 | zookeeper 116 | 117 | 118 | com.github.sgroschupf 119 | zkclient 120 | 121 | 122 | com.googlecode.xmemcached 123 | xmemcached 124 | 125 | 126 | org.apache.cxf 127 | cxf-rt-frontend-simple 128 | 129 | 130 | org.apache.cxf 131 | cxf-rt-transports-http 132 | 133 | 134 | org.apache.thrift 135 | libthrift 136 | 137 | 138 | com.caucho 139 | hessian 140 | 141 | 142 | org.mortbay.jetty 143 | jetty 144 | 145 | 146 | org.mortbay.jetty 147 | servlet-api 148 | 149 | 150 | 151 | 152 | 153 | redis.clients 154 | jedis 155 | 156 | 157 | 158 | javax.annotation 159 | javax.annotation-api 160 | 161 | 162 | javax.validation 163 | validation-api 164 | 165 | 166 | org.hibernate 167 | hibernate-validator 168 | 169 | 170 | javax.ws.rs 171 | javax.ws.rs-api 172 | 173 | 174 | 175 | javax.cache 176 | cache-api 177 | 178 | 179 | 180 | org.jboss.resteasy 181 | resteasy-jaxrs 182 | 183 | 184 | 185 | org.jboss.resteasy 186 | resteasy-client 187 | 188 | 189 | 190 | org.jboss.resteasy 191 | resteasy-netty 192 | 193 | 194 | 195 | org.jboss.resteasy 196 | resteasy-jdk-http 197 | 198 | 199 | 200 | org.jboss.resteasy 201 | resteasy-jackson-provider 202 | 203 | 204 | 205 | org.jboss.resteasy 206 | resteasy-jaxb-provider 207 | 208 | 209 | 210 | org.codehaus.jackson 211 | jackson-mapper-asl 212 | 213 | 214 | javax.xml.bind 215 | jaxb-api 216 | 217 | 218 | 219 | org.apache.tomcat.embed 220 | tomcat-embed-core 221 | 222 | 223 | org.apache.tomcat.embed 224 | tomcat-embed-logging-juli 225 | 226 | 227 | com.esotericsoftware.kryo 228 | kryo 229 | 230 | 231 | de.javakaffee 232 | kryo-serializers 233 | 234 | 235 | de.ruedigermoeller 236 | fst 237 | 238 | 239 | 240 | org.apache.avro 241 | avro 242 | 243 | 244 | 245 | org.apache.avro 246 | avro-ipc 247 | 248 | 249 | 250 | org.apache.thrift 251 | libthrift 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | org.springframework.boot 260 | spring-boot-maven-plugin 261 | 262 | 263 | 264 | 265 | 266 | 267 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/person/QueryParameter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Avro 3 | * 4 | * DO NOT EDIT DIRECTLY 5 | */ 6 | package net.aimeizi.person; 7 | @SuppressWarnings("all") 8 | @org.apache.avro.specific.AvroGenerated 9 | public class QueryParameter extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { 10 | private static final long serialVersionUID = 9063777101000629314L; 11 | public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"QueryParameter\",\"namespace\":\"net.aimeizi.person\",\"fields\":[{\"name\":\"ageStart\",\"type\":\"int\"},{\"name\":\"ageEnd\",\"type\":\"int\"}]}"); 12 | public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } 13 | @Deprecated public int ageStart; 14 | @Deprecated public int ageEnd; 15 | 16 | /** 17 | * Default constructor. Note that this does not initialize fields 18 | * to their default values from the schema. If that is desired then 19 | * one should use newBuilder(). 20 | */ 21 | public QueryParameter() {} 22 | 23 | /** 24 | * All-args constructor. 25 | */ 26 | public QueryParameter(java.lang.Integer ageStart, java.lang.Integer ageEnd) { 27 | this.ageStart = ageStart; 28 | this.ageEnd = ageEnd; 29 | } 30 | 31 | public org.apache.avro.Schema getSchema() { return SCHEMA$; } 32 | // Used by DatumWriter. Applications should not call. 33 | public java.lang.Object get(int field$) { 34 | switch (field$) { 35 | case 0: return ageStart; 36 | case 1: return ageEnd; 37 | default: throw new org.apache.avro.AvroRuntimeException("Bad index"); 38 | } 39 | } 40 | // Used by DatumReader. Applications should not call. 41 | @SuppressWarnings(value="unchecked") 42 | public void put(int field$, java.lang.Object value$) { 43 | switch (field$) { 44 | case 0: ageStart = (java.lang.Integer)value$; break; 45 | case 1: ageEnd = (java.lang.Integer)value$; break; 46 | default: throw new org.apache.avro.AvroRuntimeException("Bad index"); 47 | } 48 | } 49 | 50 | /** 51 | * Gets the value of the 'ageStart' field. 52 | */ 53 | public java.lang.Integer getAgeStart() { 54 | return ageStart; 55 | } 56 | 57 | /** 58 | * Sets the value of the 'ageStart' field. 59 | * @param value the value to set. 60 | */ 61 | public void setAgeStart(java.lang.Integer value) { 62 | this.ageStart = value; 63 | } 64 | 65 | /** 66 | * Gets the value of the 'ageEnd' field. 67 | */ 68 | public java.lang.Integer getAgeEnd() { 69 | return ageEnd; 70 | } 71 | 72 | /** 73 | * Sets the value of the 'ageEnd' field. 74 | * @param value the value to set. 75 | */ 76 | public void setAgeEnd(java.lang.Integer value) { 77 | this.ageEnd = value; 78 | } 79 | 80 | /** 81 | * Creates a new QueryParameter RecordBuilder. 82 | * @return A new QueryParameter RecordBuilder 83 | */ 84 | public static net.aimeizi.person.QueryParameter.Builder newBuilder() { 85 | return new net.aimeizi.person.QueryParameter.Builder(); 86 | } 87 | 88 | /** 89 | * Creates a new QueryParameter RecordBuilder by copying an existing Builder. 90 | * @param other The existing builder to copy. 91 | * @return A new QueryParameter RecordBuilder 92 | */ 93 | public static net.aimeizi.person.QueryParameter.Builder newBuilder(net.aimeizi.person.QueryParameter.Builder other) { 94 | return new net.aimeizi.person.QueryParameter.Builder(other); 95 | } 96 | 97 | /** 98 | * Creates a new QueryParameter RecordBuilder by copying an existing QueryParameter instance. 99 | * @param other The existing instance to copy. 100 | * @return A new QueryParameter RecordBuilder 101 | */ 102 | public static net.aimeizi.person.QueryParameter.Builder newBuilder(net.aimeizi.person.QueryParameter other) { 103 | return new net.aimeizi.person.QueryParameter.Builder(other); 104 | } 105 | 106 | /** 107 | * RecordBuilder for QueryParameter instances. 108 | */ 109 | public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase 110 | implements org.apache.avro.data.RecordBuilder { 111 | 112 | private int ageStart; 113 | private int ageEnd; 114 | 115 | /** Creates a new Builder */ 116 | private Builder() { 117 | super(net.aimeizi.person.QueryParameter.SCHEMA$); 118 | } 119 | 120 | /** 121 | * Creates a Builder by copying an existing Builder. 122 | * @param other The existing Builder to copy. 123 | */ 124 | private Builder(net.aimeizi.person.QueryParameter.Builder other) { 125 | super(other); 126 | if (isValidValue(fields()[0], other.ageStart)) { 127 | this.ageStart = data().deepCopy(fields()[0].schema(), other.ageStart); 128 | fieldSetFlags()[0] = true; 129 | } 130 | if (isValidValue(fields()[1], other.ageEnd)) { 131 | this.ageEnd = data().deepCopy(fields()[1].schema(), other.ageEnd); 132 | fieldSetFlags()[1] = true; 133 | } 134 | } 135 | 136 | /** 137 | * Creates a Builder by copying an existing QueryParameter instance 138 | * @param other The existing instance to copy. 139 | */ 140 | private Builder(net.aimeizi.person.QueryParameter other) { 141 | super(net.aimeizi.person.QueryParameter.SCHEMA$); 142 | if (isValidValue(fields()[0], other.ageStart)) { 143 | this.ageStart = data().deepCopy(fields()[0].schema(), other.ageStart); 144 | fieldSetFlags()[0] = true; 145 | } 146 | if (isValidValue(fields()[1], other.ageEnd)) { 147 | this.ageEnd = data().deepCopy(fields()[1].schema(), other.ageEnd); 148 | fieldSetFlags()[1] = true; 149 | } 150 | } 151 | 152 | /** 153 | * Gets the value of the 'ageStart' field. 154 | * @return The value. 155 | */ 156 | public java.lang.Integer getAgeStart() { 157 | return ageStart; 158 | } 159 | 160 | /** 161 | * Sets the value of the 'ageStart' field. 162 | * @param value The value of 'ageStart'. 163 | * @return This builder. 164 | */ 165 | public net.aimeizi.person.QueryParameter.Builder setAgeStart(int value) { 166 | validate(fields()[0], value); 167 | this.ageStart = value; 168 | fieldSetFlags()[0] = true; 169 | return this; 170 | } 171 | 172 | /** 173 | * Checks whether the 'ageStart' field has been set. 174 | * @return True if the 'ageStart' field has been set, false otherwise. 175 | */ 176 | public boolean hasAgeStart() { 177 | return fieldSetFlags()[0]; 178 | } 179 | 180 | 181 | /** 182 | * Clears the value of the 'ageStart' field. 183 | * @return This builder. 184 | */ 185 | public net.aimeizi.person.QueryParameter.Builder clearAgeStart() { 186 | fieldSetFlags()[0] = false; 187 | return this; 188 | } 189 | 190 | /** 191 | * Gets the value of the 'ageEnd' field. 192 | * @return The value. 193 | */ 194 | public java.lang.Integer getAgeEnd() { 195 | return ageEnd; 196 | } 197 | 198 | /** 199 | * Sets the value of the 'ageEnd' field. 200 | * @param value The value of 'ageEnd'. 201 | * @return This builder. 202 | */ 203 | public net.aimeizi.person.QueryParameter.Builder setAgeEnd(int value) { 204 | validate(fields()[1], value); 205 | this.ageEnd = value; 206 | fieldSetFlags()[1] = true; 207 | return this; 208 | } 209 | 210 | /** 211 | * Checks whether the 'ageEnd' field has been set. 212 | * @return True if the 'ageEnd' field has been set, false otherwise. 213 | */ 214 | public boolean hasAgeEnd() { 215 | return fieldSetFlags()[1]; 216 | } 217 | 218 | 219 | /** 220 | * Clears the value of the 'ageEnd' field. 221 | * @return This builder. 222 | */ 223 | public net.aimeizi.person.QueryParameter.Builder clearAgeEnd() { 224 | fieldSetFlags()[1] = false; 225 | return this; 226 | } 227 | 228 | @Override 229 | public QueryParameter build() { 230 | try { 231 | QueryParameter record = new QueryParameter(); 232 | record.ageStart = fieldSetFlags()[0] ? this.ageStart : (java.lang.Integer) defaultValue(fields()[0]); 233 | record.ageEnd = fieldSetFlags()[1] ? this.ageEnd : (java.lang.Integer) defaultValue(fields()[1]); 234 | return record; 235 | } catch (Exception e) { 236 | throw new org.apache.avro.AvroRuntimeException(e); 237 | } 238 | } 239 | } 240 | 241 | private static final org.apache.avro.io.DatumWriter 242 | WRITER$ = new org.apache.avro.specific.SpecificDatumWriter(SCHEMA$); 243 | 244 | @Override public void writeExternal(java.io.ObjectOutput out) 245 | throws java.io.IOException { 246 | WRITER$.write(this, org.apache.avro.specific.SpecificData.getEncoder(out)); 247 | } 248 | 249 | private static final org.apache.avro.io.DatumReader 250 | READER$ = new org.apache.avro.specific.SpecificDatumReader(SCHEMA$); 251 | 252 | @Override public void readExternal(java.io.ObjectInput in) 253 | throws java.io.IOException { 254 | READER$.read(this, org.apache.avro.specific.SpecificData.getDecoder(in)); 255 | } 256 | 257 | } 258 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | net.aimeizi 7 | springboot-dubbox-simple 8 | 1.0 9 | pom 10 | 11 | springboot-dubbox-simple 12 | Simple Project for Spring Boot Dubbox 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.3.RELEASE 18 | 19 | 20 | 21 | 22 | springboot-dubbox-api 23 | springboot-dubbox-service 24 | springboot-dubbox-webapp 25 | 26 | 27 | 28 | UTF-8 29 | 1.7 30 | 31 | 32 | 33 | 34 | 35 | org.projectlombok 36 | lombok 37 | 1.16.8 38 | 39 | 40 | com.alibaba 41 | dubbo 42 | 2.8.4 43 | 44 | 45 | spring-web 46 | org.springframework 47 | 48 | 49 | spring-beans 50 | org.springframework 51 | 52 | 53 | spring-core 54 | org.springframework 55 | 56 | 57 | spring-context 58 | org.springframework 59 | 60 | 61 | spring-aop 62 | org.springframework 63 | 64 | 65 | spring-expression 66 | org.springframework 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.springframework 74 | spring-core 75 | 4.2.4.RELEASE 76 | 77 | 78 | 79 | org.springframework 80 | spring-context 81 | 4.2.4.RELEASE 82 | 83 | 84 | 85 | org.springframework 86 | spring-context-support 87 | 4.2.4.RELEASE 88 | 89 | 90 | 91 | org.springframework 92 | spring-beans 93 | 4.2.4.RELEASE 94 | 95 | 96 | 97 | 98 | 99 | org.springframework.data 100 | spring-data-commons 101 | 1.12.1.RELEASE 102 | 103 | 104 | 105 | org.springframework.boot 106 | spring-boot-starter-security 107 | 1.3.3.RELEASE 108 | 109 | 110 | 111 | org.apache.mina 112 | mina-core 113 | 1.1.7 114 | 115 | 116 | 117 | javax.servlet 118 | javax.servlet-api 119 | 3.1.0 120 | 121 | 122 | 123 | javax.el 124 | javax.el-api 125 | 3.0.0 126 | 127 | 128 | org.glassfish.web 129 | javax.el 130 | 2.2.6 131 | 132 | 133 | org.glassfish.grizzly 134 | grizzly-core 135 | 2.1.4 136 | 137 | 138 | com.alibaba 139 | hessian-lite 140 | 3.2.1-fixed-2 141 | 142 | 143 | com.alibaba 144 | fastjson 145 | 1.1.39 146 | 147 | 148 | com.thoughtworks.xstream 149 | xstream 150 | 1.4.1 151 | 152 | 153 | org.apache.bsf 154 | bsf-api 155 | 3.1 156 | 157 | 158 | org.jvnet.sorcerer 159 | sorcerer-javac 160 | 0.8 161 | 162 | 163 | org.apache.zookeeper 164 | zookeeper 165 | 3.4.6 166 | 167 | 168 | com.github.sgroschupf 169 | zkclient 170 | 0.1 171 | 172 | 173 | redis.clients 174 | jedis 175 | 2.1.0 176 | 177 | 178 | com.googlecode.xmemcached 179 | xmemcached 180 | 1.3.6 181 | 182 | 183 | org.apache.cxf 184 | cxf-rt-frontend-simple 185 | 2.6.1 186 | 187 | 188 | org.apache.cxf 189 | cxf-rt-transports-http 190 | 2.6.1 191 | 192 | 193 | jfree 194 | jfreechart 195 | 1.0.13 196 | 197 | 198 | com.caucho 199 | hessian 200 | 4.0.7 201 | 202 | 203 | org.mortbay.jetty 204 | jetty 205 | 6.1.26 206 | 207 | 208 | javax.annotation 209 | javax.annotation-api 210 | 1.2 211 | 212 | 213 | javax.validation 214 | validation-api 215 | 1.1.0.Final 216 | 217 | 218 | org.hibernate 219 | hibernate-validator 220 | 5.2.2.Final 221 | 222 | 223 | javax.cache 224 | cache-api 225 | 0.4 226 | 227 | 228 | org.apache.tuscany.sca 229 | tuscany-sca-api 230 | 2.0 231 | 232 | 233 | com.google.inject 234 | guice 235 | 3.0 236 | 237 | 238 | com.alibaba.citrus 239 | citrus-webx-all 240 | 3.0.8 241 | 242 | 243 | com.fasterxml.jackson.core 244 | jackson-core 245 | 2.3.3 246 | 247 | 248 | com.fasterxml.jackson.core 249 | jackson-databind 250 | 2.3.3 251 | 252 | 253 | org.codehaus.jackson 254 | jackson-mapper-asl 255 | 1.9.12 256 | 257 | 258 | javax.xml.bind 259 | jaxb-api 260 | 2.2.7 261 | 262 | 263 | cglib 264 | cglib-nodep 265 | 2.2 266 | 267 | 268 | commons-pool 269 | commons-pool 270 | 1.6 271 | 272 | 273 | org.apache.tomcat.embed 274 | tomcat-embed-core 275 | 8.0.11 276 | 277 | 278 | org.apache.tomcat.embed 279 | tomcat-embed-logging-juli 280 | 8.0.11 281 | 282 | 283 | javax.ws.rs 284 | javax.ws.rs-api 285 | 2.0 286 | 287 | 288 | 289 | 290 | org.jboss.resteasy 291 | resteasy-jaxrs 292 | 3.0.7.Final 293 | 294 | 295 | httpclient 296 | org.apache.httpcomponents 297 | 298 | 299 | 300 | 301 | org.jboss.resteasy 302 | resteasy-client 303 | 3.0.7.Final 304 | 305 | 306 | org.jboss.resteasy 307 | resteasy-netty 308 | 3.0.7.Final 309 | 310 | 311 | org.jboss.resteasy 312 | resteasy-jdk-http 313 | 3.0.7.Final 314 | 315 | 316 | org.jboss.resteasy 317 | resteasy-jackson-provider 318 | 3.0.14.Final 319 | 320 | 321 | org.jboss.resteasy 322 | resteasy-jaxb-provider 323 | 3.0.16.Final 324 | 325 | 326 | 327 | 328 | com.esotericsoftware.kryo 329 | kryo 330 | 2.24.0 331 | 332 | 333 | de.javakaffee 334 | kryo-serializers 335 | 0.37 336 | 337 | 338 | de.ruedigermoeller 339 | fst 340 | 1.55 341 | 342 | 343 | 344 | org.apache.avro 345 | avro 346 | 1.8.0 347 | 348 | 349 | 350 | org.apache.avro 351 | avro-ipc 352 | 1.8.0 353 | 354 | 355 | 356 | org.apache.thrift 357 | libthrift 358 | 0.9.3 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | -------------------------------------------------------------------------------- /springboot-dubbox-api/src/main/java/net/aimeizi/person/Person.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Autogenerated by Avro 3 | * 4 | * DO NOT EDIT DIRECTLY 5 | */ 6 | package net.aimeizi.person; 7 | @SuppressWarnings("all") 8 | @org.apache.avro.specific.AvroGenerated 9 | public class Person extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { 10 | private static final long serialVersionUID = 7881799290734605096L; 11 | public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"net.aimeizi.person\",\"fields\":[{\"name\":\"age\",\"type\":\"int\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"sex\",\"type\":\"boolean\"},{\"name\":\"salary\",\"type\":\"double\"},{\"name\":\"childrenCount\",\"type\":\"int\"}]}"); 12 | public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } 13 | @Deprecated public int age; 14 | @Deprecated public java.lang.CharSequence name; 15 | @Deprecated public boolean sex; 16 | @Deprecated public double salary; 17 | @Deprecated public int childrenCount; 18 | 19 | /** 20 | * Default constructor. Note that this does not initialize fields 21 | * to their default values from the schema. If that is desired then 22 | * one should use newBuilder(). 23 | */ 24 | public Person() {} 25 | 26 | /** 27 | * All-args constructor. 28 | */ 29 | public Person(java.lang.Integer age, java.lang.CharSequence name, java.lang.Boolean sex, java.lang.Double salary, java.lang.Integer childrenCount) { 30 | this.age = age; 31 | this.name = name; 32 | this.sex = sex; 33 | this.salary = salary; 34 | this.childrenCount = childrenCount; 35 | } 36 | 37 | public org.apache.avro.Schema getSchema() { return SCHEMA$; } 38 | // Used by DatumWriter. Applications should not call. 39 | public java.lang.Object get(int field$) { 40 | switch (field$) { 41 | case 0: return age; 42 | case 1: return name; 43 | case 2: return sex; 44 | case 3: return salary; 45 | case 4: return childrenCount; 46 | default: throw new org.apache.avro.AvroRuntimeException("Bad index"); 47 | } 48 | } 49 | // Used by DatumReader. Applications should not call. 50 | @SuppressWarnings(value="unchecked") 51 | public void put(int field$, java.lang.Object value$) { 52 | switch (field$) { 53 | case 0: age = (java.lang.Integer)value$; break; 54 | case 1: name = (java.lang.CharSequence)value$; break; 55 | case 2: sex = (java.lang.Boolean)value$; break; 56 | case 3: salary = (java.lang.Double)value$; break; 57 | case 4: childrenCount = (java.lang.Integer)value$; break; 58 | default: throw new org.apache.avro.AvroRuntimeException("Bad index"); 59 | } 60 | } 61 | 62 | /** 63 | * Gets the value of the 'age' field. 64 | */ 65 | public java.lang.Integer getAge() { 66 | return age; 67 | } 68 | 69 | /** 70 | * Sets the value of the 'age' field. 71 | * @param value the value to set. 72 | */ 73 | public void setAge(java.lang.Integer value) { 74 | this.age = value; 75 | } 76 | 77 | /** 78 | * Gets the value of the 'name' field. 79 | */ 80 | public java.lang.CharSequence getName() { 81 | return name; 82 | } 83 | 84 | /** 85 | * Sets the value of the 'name' field. 86 | * @param value the value to set. 87 | */ 88 | public void setName(java.lang.CharSequence value) { 89 | this.name = value; 90 | } 91 | 92 | /** 93 | * Gets the value of the 'sex' field. 94 | */ 95 | public java.lang.Boolean getSex() { 96 | return sex; 97 | } 98 | 99 | /** 100 | * Sets the value of the 'sex' field. 101 | * @param value the value to set. 102 | */ 103 | public void setSex(java.lang.Boolean value) { 104 | this.sex = value; 105 | } 106 | 107 | /** 108 | * Gets the value of the 'salary' field. 109 | */ 110 | public java.lang.Double getSalary() { 111 | return salary; 112 | } 113 | 114 | /** 115 | * Sets the value of the 'salary' field. 116 | * @param value the value to set. 117 | */ 118 | public void setSalary(java.lang.Double value) { 119 | this.salary = value; 120 | } 121 | 122 | /** 123 | * Gets the value of the 'childrenCount' field. 124 | */ 125 | public java.lang.Integer getChildrenCount() { 126 | return childrenCount; 127 | } 128 | 129 | /** 130 | * Sets the value of the 'childrenCount' field. 131 | * @param value the value to set. 132 | */ 133 | public void setChildrenCount(java.lang.Integer value) { 134 | this.childrenCount = value; 135 | } 136 | 137 | /** 138 | * Creates a new Person RecordBuilder. 139 | * @return A new Person RecordBuilder 140 | */ 141 | public static net.aimeizi.person.Person.Builder newBuilder() { 142 | return new net.aimeizi.person.Person.Builder(); 143 | } 144 | 145 | /** 146 | * Creates a new Person RecordBuilder by copying an existing Builder. 147 | * @param other The existing builder to copy. 148 | * @return A new Person RecordBuilder 149 | */ 150 | public static net.aimeizi.person.Person.Builder newBuilder(net.aimeizi.person.Person.Builder other) { 151 | return new net.aimeizi.person.Person.Builder(other); 152 | } 153 | 154 | /** 155 | * Creates a new Person RecordBuilder by copying an existing Person instance. 156 | * @param other The existing instance to copy. 157 | * @return A new Person RecordBuilder 158 | */ 159 | public static net.aimeizi.person.Person.Builder newBuilder(net.aimeizi.person.Person other) { 160 | return new net.aimeizi.person.Person.Builder(other); 161 | } 162 | 163 | /** 164 | * RecordBuilder for Person instances. 165 | */ 166 | public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase 167 | implements org.apache.avro.data.RecordBuilder { 168 | 169 | private int age; 170 | private java.lang.CharSequence name; 171 | private boolean sex; 172 | private double salary; 173 | private int childrenCount; 174 | 175 | /** Creates a new Builder */ 176 | private Builder() { 177 | super(net.aimeizi.person.Person.SCHEMA$); 178 | } 179 | 180 | /** 181 | * Creates a Builder by copying an existing Builder. 182 | * @param other The existing Builder to copy. 183 | */ 184 | private Builder(net.aimeizi.person.Person.Builder other) { 185 | super(other); 186 | if (isValidValue(fields()[0], other.age)) { 187 | this.age = data().deepCopy(fields()[0].schema(), other.age); 188 | fieldSetFlags()[0] = true; 189 | } 190 | if (isValidValue(fields()[1], other.name)) { 191 | this.name = data().deepCopy(fields()[1].schema(), other.name); 192 | fieldSetFlags()[1] = true; 193 | } 194 | if (isValidValue(fields()[2], other.sex)) { 195 | this.sex = data().deepCopy(fields()[2].schema(), other.sex); 196 | fieldSetFlags()[2] = true; 197 | } 198 | if (isValidValue(fields()[3], other.salary)) { 199 | this.salary = data().deepCopy(fields()[3].schema(), other.salary); 200 | fieldSetFlags()[3] = true; 201 | } 202 | if (isValidValue(fields()[4], other.childrenCount)) { 203 | this.childrenCount = data().deepCopy(fields()[4].schema(), other.childrenCount); 204 | fieldSetFlags()[4] = true; 205 | } 206 | } 207 | 208 | /** 209 | * Creates a Builder by copying an existing Person instance 210 | * @param other The existing instance to copy. 211 | */ 212 | private Builder(net.aimeizi.person.Person other) { 213 | super(net.aimeizi.person.Person.SCHEMA$); 214 | if (isValidValue(fields()[0], other.age)) { 215 | this.age = data().deepCopy(fields()[0].schema(), other.age); 216 | fieldSetFlags()[0] = true; 217 | } 218 | if (isValidValue(fields()[1], other.name)) { 219 | this.name = data().deepCopy(fields()[1].schema(), other.name); 220 | fieldSetFlags()[1] = true; 221 | } 222 | if (isValidValue(fields()[2], other.sex)) { 223 | this.sex = data().deepCopy(fields()[2].schema(), other.sex); 224 | fieldSetFlags()[2] = true; 225 | } 226 | if (isValidValue(fields()[3], other.salary)) { 227 | this.salary = data().deepCopy(fields()[3].schema(), other.salary); 228 | fieldSetFlags()[3] = true; 229 | } 230 | if (isValidValue(fields()[4], other.childrenCount)) { 231 | this.childrenCount = data().deepCopy(fields()[4].schema(), other.childrenCount); 232 | fieldSetFlags()[4] = true; 233 | } 234 | } 235 | 236 | /** 237 | * Gets the value of the 'age' field. 238 | * @return The value. 239 | */ 240 | public java.lang.Integer getAge() { 241 | return age; 242 | } 243 | 244 | /** 245 | * Sets the value of the 'age' field. 246 | * @param value The value of 'age'. 247 | * @return This builder. 248 | */ 249 | public net.aimeizi.person.Person.Builder setAge(int value) { 250 | validate(fields()[0], value); 251 | this.age = value; 252 | fieldSetFlags()[0] = true; 253 | return this; 254 | } 255 | 256 | /** 257 | * Checks whether the 'age' field has been set. 258 | * @return True if the 'age' field has been set, false otherwise. 259 | */ 260 | public boolean hasAge() { 261 | return fieldSetFlags()[0]; 262 | } 263 | 264 | 265 | /** 266 | * Clears the value of the 'age' field. 267 | * @return This builder. 268 | */ 269 | public net.aimeizi.person.Person.Builder clearAge() { 270 | fieldSetFlags()[0] = false; 271 | return this; 272 | } 273 | 274 | /** 275 | * Gets the value of the 'name' field. 276 | * @return The value. 277 | */ 278 | public java.lang.CharSequence getName() { 279 | return name; 280 | } 281 | 282 | /** 283 | * Sets the value of the 'name' field. 284 | * @param value The value of 'name'. 285 | * @return This builder. 286 | */ 287 | public net.aimeizi.person.Person.Builder setName(java.lang.CharSequence value) { 288 | validate(fields()[1], value); 289 | this.name = value; 290 | fieldSetFlags()[1] = true; 291 | return this; 292 | } 293 | 294 | /** 295 | * Checks whether the 'name' field has been set. 296 | * @return True if the 'name' field has been set, false otherwise. 297 | */ 298 | public boolean hasName() { 299 | return fieldSetFlags()[1]; 300 | } 301 | 302 | 303 | /** 304 | * Clears the value of the 'name' field. 305 | * @return This builder. 306 | */ 307 | public net.aimeizi.person.Person.Builder clearName() { 308 | name = null; 309 | fieldSetFlags()[1] = false; 310 | return this; 311 | } 312 | 313 | /** 314 | * Gets the value of the 'sex' field. 315 | * @return The value. 316 | */ 317 | public java.lang.Boolean getSex() { 318 | return sex; 319 | } 320 | 321 | /** 322 | * Sets the value of the 'sex' field. 323 | * @param value The value of 'sex'. 324 | * @return This builder. 325 | */ 326 | public net.aimeizi.person.Person.Builder setSex(boolean value) { 327 | validate(fields()[2], value); 328 | this.sex = value; 329 | fieldSetFlags()[2] = true; 330 | return this; 331 | } 332 | 333 | /** 334 | * Checks whether the 'sex' field has been set. 335 | * @return True if the 'sex' field has been set, false otherwise. 336 | */ 337 | public boolean hasSex() { 338 | return fieldSetFlags()[2]; 339 | } 340 | 341 | 342 | /** 343 | * Clears the value of the 'sex' field. 344 | * @return This builder. 345 | */ 346 | public net.aimeizi.person.Person.Builder clearSex() { 347 | fieldSetFlags()[2] = false; 348 | return this; 349 | } 350 | 351 | /** 352 | * Gets the value of the 'salary' field. 353 | * @return The value. 354 | */ 355 | public java.lang.Double getSalary() { 356 | return salary; 357 | } 358 | 359 | /** 360 | * Sets the value of the 'salary' field. 361 | * @param value The value of 'salary'. 362 | * @return This builder. 363 | */ 364 | public net.aimeizi.person.Person.Builder setSalary(double value) { 365 | validate(fields()[3], value); 366 | this.salary = value; 367 | fieldSetFlags()[3] = true; 368 | return this; 369 | } 370 | 371 | /** 372 | * Checks whether the 'salary' field has been set. 373 | * @return True if the 'salary' field has been set, false otherwise. 374 | */ 375 | public boolean hasSalary() { 376 | return fieldSetFlags()[3]; 377 | } 378 | 379 | 380 | /** 381 | * Clears the value of the 'salary' field. 382 | * @return This builder. 383 | */ 384 | public net.aimeizi.person.Person.Builder clearSalary() { 385 | fieldSetFlags()[3] = false; 386 | return this; 387 | } 388 | 389 | /** 390 | * Gets the value of the 'childrenCount' field. 391 | * @return The value. 392 | */ 393 | public java.lang.Integer getChildrenCount() { 394 | return childrenCount; 395 | } 396 | 397 | /** 398 | * Sets the value of the 'childrenCount' field. 399 | * @param value The value of 'childrenCount'. 400 | * @return This builder. 401 | */ 402 | public net.aimeizi.person.Person.Builder setChildrenCount(int value) { 403 | validate(fields()[4], value); 404 | this.childrenCount = value; 405 | fieldSetFlags()[4] = true; 406 | return this; 407 | } 408 | 409 | /** 410 | * Checks whether the 'childrenCount' field has been set. 411 | * @return True if the 'childrenCount' field has been set, false otherwise. 412 | */ 413 | public boolean hasChildrenCount() { 414 | return fieldSetFlags()[4]; 415 | } 416 | 417 | 418 | /** 419 | * Clears the value of the 'childrenCount' field. 420 | * @return This builder. 421 | */ 422 | public net.aimeizi.person.Person.Builder clearChildrenCount() { 423 | fieldSetFlags()[4] = false; 424 | return this; 425 | } 426 | 427 | @Override 428 | public Person build() { 429 | try { 430 | Person record = new Person(); 431 | record.age = fieldSetFlags()[0] ? this.age : (java.lang.Integer) defaultValue(fields()[0]); 432 | record.name = fieldSetFlags()[1] ? this.name : (java.lang.CharSequence) defaultValue(fields()[1]); 433 | record.sex = fieldSetFlags()[2] ? this.sex : (java.lang.Boolean) defaultValue(fields()[2]); 434 | record.salary = fieldSetFlags()[3] ? this.salary : (java.lang.Double) defaultValue(fields()[3]); 435 | record.childrenCount = fieldSetFlags()[4] ? this.childrenCount : (java.lang.Integer) defaultValue(fields()[4]); 436 | return record; 437 | } catch (Exception e) { 438 | throw new org.apache.avro.AvroRuntimeException(e); 439 | } 440 | } 441 | } 442 | 443 | private static final org.apache.avro.io.DatumWriter 444 | WRITER$ = new org.apache.avro.specific.SpecificDatumWriter(SCHEMA$); 445 | 446 | @Override public void writeExternal(java.io.ObjectOutput out) 447 | throws java.io.IOException { 448 | WRITER$.write(this, org.apache.avro.specific.SpecificData.getEncoder(out)); 449 | } 450 | 451 | private static final org.apache.avro.io.DatumReader 452 | READER$ = new org.apache.avro.specific.SpecificDatumReader(SCHEMA$); 453 | 454 | @Override public void readExternal(java.io.ObjectInput in) 455 | throws java.io.IOException { 456 | READER$.read(this, org.apache.avro.specific.SpecificData.getDecoder(in)); 457 | } 458 | 459 | } 460 | --------------------------------------------------------------------------------