配置
Dubbo 捐精给 Apache 以后,也就意味着之前 Dubbo 以及 spring-boot-starter 坐标也变了,当然之前的还可以用,但是要使用新版本的小伙伴建议看这里。
Zookeeper 注册中心版
pom.xml 引入坐标:
dubbo.application.id=mail
dubbo.application.name=mail
dubbo.registry.address=zookeeper://106.13.122.117:2181
dubbo.provider.threads=10
dubbo.provider.threadpool=fixed
dubbo.provider.loadbalance=roundrobin
dubbo.server=true
dubbo.protocol.name=dubbo
dubbo.protocol.port=-1
启动类:
@SpringBootApplication
//必须配置包扫描、否则Dubbo无法注册服务,实现类加扫描也不行,日狗不是
@DubboComponentScan(basePackages = “com.itstyle.mail.service.impl”)
public class Application {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
public static void main(String[] args){
SpringApplication.run(Application.class, args);
logger.info("邮件服务项目启动");
}
}
提供者接口实现:
引入 apache 包、之前的还可以用,不过已过时
import org.apache.dubbo.config.annotation.Service;
@Service(version = “1.0.0”)
public class MailServiceImpl implements IMailService {
}
消费引用:
import org.apache.dubbo.config.annotation.Reference;
@RestController
@RequestMapping("/mail")
public class mailController {
@Reference(version = "1.0.0")
private IMailService mailService;
}
Nacos 注册中心版
nacos.config.server-addr=47.104.197.9:8848
dubbo.application.name = spring-boot-mail
dubbo.registry.address = nacos://47.104.197.9:8848
dubbo.protocol.name=dubbo
dubbo.protocol.port=-1
启动类:
@SpringBootApplication
//必须配置包扫描、否则Dubbo无法注册服务
@EnableDubbo(scanBasePackages = “com.itstyle.mail.service.impl”)
public class Application {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
public static void main(String[] args){
SpringApplication.run(Application.class, args);
logger.info("邮件服务项目启动");
深圳网站建设www.sz886.com