You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "mercyblitz (GitHub)" <gi...@apache.org> on 2018/12/18 03:00:54 UTC
[GitHub] [incubator-dubbo-spring-boot-project] mercyblitz commented on issue #263: 好几个朋友都在问多协议的配置,望能解答下,这个是很基本的功能。
First, add these properties into your `application.properties`:
```properties
## Enable multiple config bindings
dubbo.config.multiple =true
## ProtocolConfig Bean
dubbo.protocols.dubbo.name = dubbo
dubbo.protocols.dubbo.port = 12345
dubbo.protocols.dubbo.status = server
dubbo.protocols.rest.name = rest
dubbo.protocols.rest.port = 8888
```
Second, add the dependencies to your `pom.xml`:
```xml
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.19.Final</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
```
Third, specify multiple protocols:
```java
@Service(
version = "${demo.service.version}",
protocol = {"dubbo", "rest"},
registry = "${dubbo.registry.id}"
)
@Path("demo")
public class DefaultDemoService implements DemoService {
@GET
@Path("/say-hello")
public String sayHello(@QueryParam("name") String name) {
return "Hello, " + name + " (from Spring Boot)";
}
}
```
Last, curl this REST URL:
```
$ curl http://localhost:8888/demo/say-hello?name=%E5%B0%8F%E9%A9%AC%E5%93%A5
Hello, 小马哥 (from Spring Boot)
```
[ Full content available at: https://github.com/apache/incubator-dubbo-spring-boot-project/issues/263 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org