网上大部分资料都是基于application.properties配置,或者是基于xml配置dubbo的相关参数。而实际上,在Spring Boot工程中,
shop-service-provider:application.yml配置文件说明
shop-service-consumer: application.yml说明
server: address: port: 8081 servlet: context-path: / tomcat: uri-encoding: UTF-8 spring: application: name: shop-service-consumer # log config logging: config: classpath:log4j2.xml level: root: info web: info file: logs/shop-service-provider.log # Dubbo Application nacos ## The default value of dubbo.application.name is ${spring.application.name} ## dubbo.application.name=${spring.application.name} nacos: service-address: 127.0.0.1 port: 8848 dubbo: registry: address: nacos://${nacos.service-address}:${nacos.port}dubbo相关参数:也可以在DubboConfigurationProperties类中查看
针对dubbo服务提供者,我没有单独把RpcShopService接口单独放到一个子模块提供,建议在引用到实际项目中,可以单独提供接口包,在消费端直接引用接口包,这样就可以脱离服务提供者。
ShopServiceProviderApplication.java启动主类
package cn.raysonblog.shopserviceprovider; import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import java.util.concurrent.CountDownLatch; /** * dubbo 服务提供方 * @author raysonfang * @公众号 Java技术干货(ID:raysonfang) */ @SpringBootApplication @EnableDubbo public class ShopServiceProviderApplication { //使用jar方式打包的启动方式 private static CountDownLatch countDownLatch = new CountDownLatch(1); public static void main(String[] args) throws InterruptedException{ SpringApplication.run(ShopServiceProviderApplication.class, args).registerShutdownHook(); countDownLatch.await(); } }需要注意@EnableDubbo这个注解,是开启Dubbo服务必要的。