dubbo框架中Main方法运行spring容器

转自:http://blog.csdn.net/u013168445/article/details/71194666

一:运行spring容器的方式有三种

1:使用tomcat、jetty等servlet容器运行

2:自己写一个Main方法运行

3:使用dubbo框架提供的Main方法运行

前面两种有一定的局限性,很多缺点,具体就不一一列举,有兴趣的同学可以研究一下,今天就给大家讲如何实现第三种方式

二:Main配置详讲

优点:由框架本身提供,可实现优雅关机

spring路径存放路径

  按照dubbo官网解说,要使得Main能正确的启用Spring容器,要求spring配置文件存放至

classpath*:META-INF/spring/*.xml路径底下

dubbo官方网址 http://dubbo.io/User+Guide-zh.htm

项目结构

项目是maven项目,框架是spring+mybatis+dubbo

dubbo框架中Main方法运行spring容器_第1张图片


maven配置

[java]  view plain  copy
  1. "font-size:18px;">  
  2.       
  3.     asset-server  
  4.       
  5.           
  6.           
  7.             ${project.build.directory}/classes  
  8.             src/main/resources  
  9.             true  
  10.               
  11.                 **/*.xml 
  12.                 **/*.properties  
  13.               
  14.           
  15.   
  16.           
  17.           
  18.             ${project.build.directory}/classes/META-INF/spring  
  19.             src/main/resources/spring  
  20.             true  
  21.               
  22.                 applicationContext.xml  
  23.               
  24.           
  25.       
  26.   
  27.       
  28.           
  29.               
  30.               
  31.                 org.eclipse.m2e  
  32.                 lifecycle-mapping  
  33.                 1.0.0  
  34.                   
  35.                       
  36.                           
  37.                               
  38.                                   
  39.                                     org.apache.maven.plugins  
  40.                                     maven-dependency-plugin  
  41.                                     [2.0,)  
  42.                                       
  43.                                         copy-dependencies  
  44.                                       
  45.                                   
  46.                                   
  47.                                       
  48.                                   
  49.                               
  50.                           
  51.                       
  52.                   
  53.               
  54.           
  55.       
  56.       
  57.           
  58.           
  59.             org.apache.maven.plugins  
  60.             maven-jar-plugin  
  61.               
  62.                 target/classes/  
  63.                   
  64.                       
  65.                         com.alibaba.dubbo.container.Main  
  66.                           
  67.                         false  
  68.                         true  
  69.                         lib/  
  70.                       
  71.                       
  72.                         .  
  73.                       
  74.                   
  75.               
  76.           
  77.           
  78.             org.apache.maven.plugins  
  79.             maven-dependency-plugin  
  80.               
  81.                   
  82.                     copy-dependencies  
  83.                     package  
  84.                       
  85.                         copy-dependencies  
  86.                       
  87.                       
  88.                         jar  
  89.                         jar  
  90.                         false  
  91.                           
  92.                             ${project.build.directory}/lib  
  93.                           
  94.                       
  95.                   
  96.               
  97.           
  98.       
  99.   


运行测试

1).在c盘新建文件夹asset-service,将lib文件夹,asset-service.jar放置文件夹(打包完成后可能还有其他文件,我们只需要这两个)

dubbo框架中Main方法运行spring容器_第2张图片

2)打开运行窗口,进入asset-service,执行命令 java -jar asset-server.jar &

dubbo框架中Main方法运行spring容器_第3张图片

可以看到dubbo监控中心监测到接口已经正常部署


dubbo框架中Main方法运行spring容器_第4张图片

你可能感兴趣的:(分布式框架学习)