搭建一个普通的maven工程,可以参考:platform-api的搭建http://www.jianshu.com/p/ff1e791d8679
pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.delsk</groupId>
<artifactId>platform-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>platform-consumer</name>
<description>consumer</description>
<parent>
<groupId>com.delsk</groupId>
<artifactId>platform-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.delsk</groupId>
<artifactId>platform-base</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.delsk</groupId>
<artifactId>platform-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
就是一个常规的maven项目,结构如图
image.png如果需要调用远程的服务,添加上@Reference(version="1.0.0")即可
示例如下:
package com.delsk.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.delsk.api.domain.Customer;
import com.delsk.api.service.CustomerInfoService;
import com.delsk.commons.JSONResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("user")
public class UserController {
@Reference(version="1.0.0")
CustomerInfoService customerInfoService;
@RequestMapping("/getCustomerInfo/{customerId}")
public JSONResult getCustomerInfo(@PathVariable("customerId") String customerId) {
JSONResult jsonResult = customerInfoService.getCustomerInfo(customerId);
Customer customer = (Customer) jsonResult.getValue();
System.out.println(customer.toString());
return jsonResult;
}
}
application.properties
server.port=8892
spring.profiles =dev
#DB (datasource)
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/crm?createDatabaseIfNotExist=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username =root
spring.datasource.password =
spring.http.encoding.force=true
spring.http.encoding.charset=utf-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=utf-8
dubbo.properties
dubbo.application.name=platform-consumer
dubbo.application.logger=slf4j
dubbo.annotation.package=com.delsk
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.protocol.accessLog=true
dubbo.provider.timeout=3000
dubbo.provider.retries=1
dubbo.provider.delay=-1
dubbo.registr.protocol=zookeeper
dubbo.registry.address=127.0.0.1:2181
dubbo.registry.register=true
dubbo.registry.subscribe=true
网友评论