spring boot整合dubbo使用多协议dubbo和rest
引入依赖
略…
定义接口
@Path("hello")
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public interface IHelloService {
@GET
@Path("sayHi")
public String sayHi(@QueryParam("to") String to);
}
服务提供者实现
@Service(interfaceClass = IHelloService.class, protocol = {"rest", "dubbo"})
@Component
public class HelloServiceImpl implements IHelloService {
@Override
public String sayHi(String to) {
return "Hi: " + to;
}
}
application.yml配置
spring:
application:
name: boot-dubbo-rest-provider
server:
port: 8080
dubbo:
application:
name: dubbo-rest-provider
registry:
address: zookeeper://localhost:2181
protocols:
dubbo:
name: dubbo
port: -1
server: netty
rest:
name: rest
port: 8888 [http访问端口]
server: netty
注意 dubbo.protocols
和只有一种协议的写法不同之处
启动类
@SpringBootApplication
@EnableDubbo(scanBasePackages = "com.**.bootdubboprovider.api.impl")
public class BootDubboProviderApplication {
public static void main(String[] args) {
SpringApplication.run(BootDubboProviderApplication.class, args);
}
}