一、创建发布者项目
dubbo-boot-service-provider
参考上一篇
包引用 pom.xm
4.0.0 org.springframework.boot spring-boot-starter-parent2.6.2 com.hhm dubbo-boot-service-provider0.0.1-SNAPSHOT dubbo-boot-service-provider dubbo的发布者 jar 1.8 2.6.2 2.7.8 true org.springframework.boot spring-boot-dependencies${spring-boot.version} pom import org.apache.dubbo dubbo-dependencies-bom${dubbo.version} pom import org.apache.dubbo dubbo${dubbo.version} org.springframework springjavax.servlet servlet-apilog4j log4jorg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-testtest org.example dubbo-demo-service1.0-SNAPSHOT com.101tec zkclient0.10 com.alibaba.spring.boot dubbo-spring-boot-starter2.0.0 org.springframework.boot spring-boot-maven-plugin
配置文件 application.properties
dubbo.application.name=dubbo-boot-service-provider dubbo.registry.protocol=zookeeper dubbo.registry.address=127.0.0.1 dubbo.registry.port=2181 server.port=8081 # 开启指定dubbo服务 spring.dubbo.server=true
程序实现
@Component @Service(interfaceClass = UserService.class,version = "1.0.0",register = true) public class UserServiceImpl implements UserService {
引用的包是
import com.alibaba.dubbo.config.annotation.Service;
启动类
@SpringBootApplication @EnableDubbo
导入的包是
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
消费者项目可以不变
需要替换的话,实现类
@Reference(interfaceClass = UserService.class,version = "1.0.0",check = false)
引用的包
import com.alibaba.dubbo.config.annotation.Reference;
启动类
@EnableDubboConfiguration
这种方式不需要启动监控中心
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)