关闭

dubbo服务启动方式对比

4986人阅读 评论(0) 收藏 举报
分类:

参考:http://blog.csdn.net/xiaomin1991222/article/details/50981354

 Dubbo服务的运行方式:

1、使用Servlet容器运行(Tomcat、Jetty等)----不可取 缺点:增加复杂性(端口、管理) 浪费资源(内存)
2、自建Main方法类来运行(Spring容器) ----不建议(本地调试可用) 缺点: Dobbo本身提供的高级特性没用上 自已编写启动类可能会有缺陷
3、使用Dubbo框架提供的Main方法类来运行(Spring容器)----建议使用 优点:框架本身提供(com.alibaba.dubbo.container.Main) 可实现优雅关机(ShutdownHook)
注意点: spring-context.xml <import resource="classpath:spring/spring-xxx.xml" />

以下是dubbo服务的打包及启动配置,打出jar包的服务:

<build>
		<finalName>edu-service-user</finalName>

		<resources>
			<resource>
				<targetPath>${project.build.directory}/classes</targetPath>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<includes>
					<include>**/*.xml</include>
					<include>**/*.properties</include>
				</includes>
			</resource>
			<!-- 结合com.alibaba.dubbo.container.Main -->
			<resource>
				<targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
				<directory>src/main/resources/spring</directory>
				<filtering>true</filtering>
				<includes>
					<include>spring-context.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包,定位到相应的目录下,执行  java -jar edu-service-user.jar &

修改spring-context.xml文件中对另外两个文件的引用路径:前面加上classpath:spring/spring-mybatis.xml

六、当然了,我们的服务是war包,直接部署在tomcat就ok了。配置如下:

<build>
	<finalName>****-service</finalName>
	<resources>
		<resource>
			<targetPath>${project.build.directory}/classes</targetPath>
			<directory>src/main/resources</directory>
			<filtering>true</filtering>
			<includes>
				<include>**/*</include>
			</includes>
		</resource>
		<!-- 结合com.alibaba.dubbo.container.Main -->
		<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>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.1</version>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
				<encoding>UTF-8</encoding>
				<compilerArgs>
					<arg>-extdirs</arg>
					<arg>${project.basedir}/src/main/webapp/WEB-INF/lib</arg>
				</compilerArgs>
			</configuration>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-war-plugin</artifactId>
			<version>2.6</version>
			<configuration>
				<warName>****</warName>
				<archive>
					<addMavenDescriptor>false</addMavenDescriptor>
				</archive>
			</configuration>
		</plugin>
	</plugins>
</build>


0
2

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:45799次
    • 积分:1447
    • 等级:
    • 排名:千里之外
    • 原创:106篇
    • 转载:35篇
    • 译文:0篇
    • 评论:3条