Dubbo Main启动方式配置
Dubbo Main启动方式配置
Dubbo Main启动服务容器是一个standalone的启动程序,因为后台服务不需要Tomcat或JBoss等Web容器的功能,如果硬要用Web容器去加载服务提供方,增加复杂性,也浪费资源。
服务容器只是一个简单的Main方法,并加载一个简单的Spring容器,用于暴露服务。
服务容器的加载内容可以扩展,内置了spring, jetty, log4j等加载,可通过Container扩展点进行扩展,参见:Container
Spring Container
如不配置dubbo.spring.config 会自动加载META-INF/spring目录下的所有Spring配置。
手动配置:(配在java命令-D参数或者dubbo.properties中)
dubbo.spring.config=classpath*:*.xml ----配置spring配置加载位置 如
- dubbo.container=log4j,spring
- dubbo.application.name=hello-core-service
- dubbo.application.owner=coret
- dubbo.registry.address=zookeeper://127.0.0.1:2181
- dubbo.protocol.name=dubbo
- dubbo.protocol.port=56432
- dubbo.service.loadbalance=roundrobin
- dubbo.spring.config=classpath:dubbo-provider.xml
- dubbo.log4j.level=DEBUG
- dubbo.log4j.level=INFO
Jetty Container
启动一个内嵌Jetty,用于汇报状态。
配置:(配在java命令-D参数或者dubbo.properties中)
dubbo.jetty.port=8080 ----配置jetty启动端口
dubbo.jetty.directory=/foo/bar ----配置可通过jetty直接访问的目录,用于存放静态文件
dubbo.jetty.page=log,status,system ----配置显示的页面,缺省加载所有页面
Log4j Container
自动配置log4j的配置,在多进程启动时,自动给日志文件按进程分目录。
配置:(配在java命令-D参数或者dubbo.properties中)
dubbo.log4j.file=/foo/bar.log ----配置日志文件路径
dubbo.log4j.level=WARN ----配置日志级别
dubbo.log4j.subdirectory=20880 ----配置日志子目录,用于多进程启动,避免冲突
服务启动
- public class CoreLauncher {
- private static Logger logger = LoggerFactory.getLogger(CoreLauncher.class);
- /**
- * @param args
- */
- public static void main(String[] args) {
- getLocalip();
- logger.info("开始启动asset");
- //第一种 通过其他容器启动如 tomcat ,jboss等 以web服务的形式启动
- // 第二种 通过自定义main函数
- /* ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
- "classpath:dubbo-provider.xml");
- context.start();
- synchronized (CoreLauncher.class) {
- while (true) {
- try {
- CoreLauncher.class.wait();
- } catch (Throwable e) {
- }
- }
- }
- */
- //第三种 通过dubbo.container.main 要在classpath目录下配置 dubbo.properties 相关配置
- com.alibaba.dubbo.container.Main.main(args);
- }
- private static void getLocalip() {
- try {
- System.out.println("服务暴露的ip: "
- + java.net.InetAddress.getLocalHost().getHostAddress());
- } catch (Exception e) {
- logger.error(e.getMessage(), e);
- }
- }
- }