dubbo分布式服务,使用maven打jar包

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>


  <artifactId>zbx-service</artifactId>
 
  <packaging>jar</packaging>

  <name>zbx-service</name>
  <url>http://maven.apache.org</url>
   <parent>
    <groupId>zbx</groupId>
    <artifactId>zbx-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <java.version>1.8</java.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
<!--================================================-->
<!--=====打jar包基本是通用配置=====-->
	<build>
        <!-- 生成的jar名 -->
		<finalName>zbx-service</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>
			<resource>
				<targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
				<includes>
					<include>spring.xml</include>
				</includes>
			</resource>
		</resources>
		<pluginManagement>
			<plugins>
				<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>
                            <!--dubbo服务的入口类-->
							<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>
							<outputDirectory>
								${project.build.directory}/lib
							</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
<!--=======================================================-->
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
    <dependency>
      <groupId>zbx</groupId>
      <artifactId>zbx-com</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>zbx</groupId>
      <artifactId>zbx-api</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Cloud Alibaba中使用Dubbo进行分布式服务需要进行以下步骤: 1. 添加Dubbo依赖:在pom.xml文件中添加Dubbo依赖,例如: ``` <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-dubbo</artifactId> <version>2.2.3.RELEASE</version> </dependency> ``` 2. 配置Dubbo:在application.properties或者application.yml文件中添加Dubbo配置,例如: ``` #Dubbo配置 spring: dubbo: application: name: dubbo-provider #服务提供者名称 registry: address: nacos://localhost:8848 #注册中心地址 protocol: name: dubbo #协议名称 port: 20880 #协议端口号 ``` 3. 编写Dubbo服务接口:在服务提供者中定义Dubbo服务接口,例如: ``` public interface UserService { User getUserById(Long id); } ``` 4. 实现Dubbo服务接口:在服务提供者中实现Dubbo服务接口,例如: ``` @Service(version = "1.0.0") public class UserServiceImpl implements UserService { @Override public User getUserById(Long id) { //实现方法 } } ``` 5. 注册Dubbo服务:在服务提供者中使用@DubboService注解注册Dubbo服务,例如: ``` @Service(version = "1.0.0") @DubboService(interfaceClass = UserService.class) public class UserServiceImpl implements UserService { @Override public User getUserById(Long id) { //实现方法 } } ``` 6. 调用Dubbo服务:在服务消费者中使用@DubboReference注解调用Dubbo服务,例如: ``` @Service public class UserServiceImpl implements UserService { @DubboReference(version = "1.0.0") private UserService userService; public User getUserById(Long id) { return userService.getUserById(id); } } ``` 以上就是在Spring Cloud Alibaba中使用Dubbo进行分布式服务的步骤。需要注意的是,Dubbo还支持其他的注册中心和负载均衡策略,可以根据实际情况进行配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值