dubbo的main方法啟動
阿新 • • 發佈:2019-02-04
想到一個問題:公司專案是dubbo實現服務治理的,啟動dubbo是通過自帶的main方法,這個方式
要求spring配置檔案存放至
classpath*:META-INF/spring/*.xml路徑底下。那麼我們公司的是如何實現的,好像並沒有將spring配置檔案放在META-INF中呀。。。
怎麼回事???
原來是在pom.xml裡面配置的,可以將配置檔案拷貝到META-INF/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
maven配置
- <span style="font-size:18px;"><build>
- <!--jar包名稱-->
- <finalName>asset-server</finalName>
- <resources>
- <!--recources資料夾下的所有檔案都打進jar包-->
- <resource>
-
<targetPath>${project.build.directory}/classes</targetPath>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/*.xml</include>
- <include>**/*.properties</include>
- </includes>
- </resource>
- <!-- 上文有說過,由於我的applicationContext.xml檔案不是在META-INF下,這一段程式碼的作用就是將 applicationContext.xml檔案拷貝到META-INF目錄下-->
- <resource>
- <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
- <directory>src/main/resources/spring</directory>
- <filtering>true</filtering>
- <includes>
- <include>applicationContext.xml</include>
- </includes>
- </resource>
- </resources>
- <pluginManagement>
- <plugins>
- <!-- 解決Maven外掛在Eclipse內執行了一系列的生命週期引起衝突 -->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <versionRange>[2.0,)</versionRange>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore />
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <!-- 打包jar檔案時,配置manifest檔案,加入lib包的jar依賴 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <classesDirectory>target/classes/</classesDirectory>
- <archive>
- <manifest>
- <mainClass>com.alibaba.dubbo.container.Main</mainClass>
- <!-- 打包時 MANIFEST.MF檔案不記錄的時間戳版本 -->
- <useUniqueVersions>false</useUniqueVersions>
- <addClasspath>true</addClasspath>
- <classpathPrefix>lib/</classpathPrefix>
- </manifest>
- <manifestEntries>
- <Class-Path>.</Class-Path>
- </manifestEntries>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <type>jar</type>
- <includeTypes>jar</includeTypes>
- <useUniqueVersions>false</useUniqueVersions>
- <outputDirectory>
- ${project.build.directory}/lib
- </outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build></span>