1. 程式人生 > >dubbo之Main啟動(使用spring)

dubbo之Main啟動(使用spring)

final pom nta style container artifact arch classpath eclipse

直接調用dubbo的main函數啟動

一、配置spring.xml的位置

第一種方法(采用dubbo默認配置的位置)

將spring.xml放進src/main/resources下的META-INF/spring/目錄下

第二種方法(自定義spring.xml位置)

在src/main/resources目錄下新建文件dubbo.properties配置文件,內容為

dubbo.spring.config=classpath:spring.xml

=後面的就是spring.xml路徑

二、調用dubbo的main函數

package com.dubbo.start;

import com.alibaba.dubbo.container.Main; public class Main2 { public static void main(String[] args) { Main.main(args); } }

啟動即可。

如果將該服務打為jar包該如何啟動?

一、在pom.xml中添加以下內容

參考http://www.ccblog.cn/75.htm

<build>
    <!--jar包名稱-->
    <finalName>dubbo-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>spring.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>

二、打為jar包並進入jar包目錄

運行

java -jar XXX.jar &

啟動即可

dubbo之Main啟動(使用spring)