使用maven构建dubbo服务的可执行jar包
Dubbo服务的运行方式
- 使用Servlet容器运行(Tomcat、Jetty等)----不可取
- 缺点:
- 增加复杂性(端口、管理)
- 浪费资源(内存)
- 自建Main方法类来运行(Spring容器) ----不建议(本地调试可用)
- 缺点:
- Dobbo本身提供的高级特性没用上
- 自已编写启动类可能会有缺陷
- 使用Dubbo框架提供的Main方法类来运行(Spring容器)----建议使用
- 缺点:
- 框架本身提供(com.alibaba.dubbo.container.Main)
- 可实现优雅关机(ShutdownHook)
自建Main方法类来运行
main方法类运行
public class DubboProvider {
private static final Log log =LogFactory.getLog(DubboProvider.class);
public static void main(String [] args) {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/spring-context.xml");
context.start();
} catch (Exception e) {
log.error("== DubboProvider context start error :",e);
}
synchronized (DubboProvider.class) {
while(true) {
try {
DubboProvider.class.wait();
} catch (Exception e) {
log.error("== synchronized error:",e);
}
}
}
}
}
使用maven构建dubbo服务的可执行jar包
xml配置
<!-- 构建项目 -->
<build>
<finalName>edu-service-user