MAC 用 Intellij Idea 创建 Spring Cloud Eureka Server 例子
来源:互联网 发布:和风天气json解析封装 编辑:程序博客网 时间:2024/06/06 07:44
1、在intellij idea的IDE里,File -> New -> Project -> Maven -> Next
设置组名:
GroupId : service-server-2
ArtifactId : service-server-2
Next
设置工程名称
Project Name:serviceserver2
Finish
总体结构:
2、创建入口类 EurekaServiceRegisterApplication.java
标上
@EnableEurekaServer
@SpringBootApplication
特性
package hello;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@EnableEurekaServer @SpringBootApplicationpublic class EurekaServiceRegisterApplication { public static void main(String[] args) { SpringApplication.run(EurekaServiceRegisterApplication.class, args); }}
3、修改 pom.xml
更新 spring-boot,spring-cloud的类库,需要点时间,别着急;
<?xml version="1.0" encoding="UTF-8"?><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> <groupId>service-server-2</groupId> <artifactId>service-server-2</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <!-- spring boot的maven打包插件 --> <build> <finalName>service-center-1</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- eureka-server --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <!-- spring boot test--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement></project>
4、增加 application.properties
默认端口:8761
#注册服务的端口号server.port=8761#是否需要注册到注册中心,因为该项目本身作为服务注册中心,所以为falseeureka.client.register-with-eureka=false#是否需要从注册中心获取服务列表,原因同上,为falseeureka.client.fetch-registry=false#注册服务器的地址:服务提供者和服务消费者都要依赖这个地址eureka.client.service-url.defaultZone=http://localhost:${server.port}/eurekalogging.level.com.netflix.eureka=OFFlogging.level.com.netflix.discovery=OFF
5、跑起来
菜单:Run -> EurekaServiceRegisterApplication
6、发布jar
1).点击菜单:File -> Project Stucture,进入工程配置界面;
2).在配置界面的左侧:
*选中“Artifacts” ,点 “+”,
*选择“JAR”,二级选择 “From Modules With Dependencies”,
*选择“Main Class” 入口对应的类;
*选择其它类库的导出方式:复制;
*最后 点击“OK”,配置完成;
上述默认生成的jar,会运行不成功,
1、相关依赖的jar签过名,采用嵌入模式生成的jar没签名执行时会提示签名有问题;
2、采用复制模式时,MANIFEST.MF文件始终不能打包进入jar,总提示找不到入口类;
经过一天的苦研,最终采用分离式(采用两个art),一个为了生成本工程的jar文件,另一个是为了复制出相关的依赖文件;
生成本工程的jar文件,采用手分增加文件,用默认的编辑果结死活不行。
过程如下:
*设置独立serviceserver.jar,并加入
/hello/EurekaServiceRegisterApplication.class
/META-INF/MANIFEST.MF
*相关依赖文件采用复制模式:
输出文件包括(serviceserver-2,type:other):
相关依赖的.jar(n个)
serviceserver.jar
application.properties
3).点击菜单:Build -> Make Project生成目标文件
4).查看jar文件:工程根目录/out/artifacts/serviceserver_2下;
5).运行:
cd 工程根目录/out/artifacts/serviceserver_2
java -jar serviceserver.jar;
源代码 :https://github.com/ronmy/EurekaAndDotnetCore2.0
- MAC 用 Intellij Idea 创建 Spring Cloud Eureka Server 例子
- Spring cloud eureka 简单例子
- Spring Cloud第二篇 创建一个Eureka Server
- spring cloud 之eureka-server
- spring cloud eureka server HA
- spring cloud eureka server 配置
- spring cloud eureka-server搭建
- spring cloud中启动Eureka Server
- Spring Cloud Eureka Server HA With Docker
- spring cloud之Eureka Server环境搭建
- spring cloud eureka server warning EUREKA MAY BE INCORRECTLY
- spring cloud-eureka
- Spring-cloud Eureka 集群
- spring cloud eureka
- Spring Cloud Eureka
- Spring Cloud Netflix Eureka
- Spring Cloud Eureka详解
- Spring Cloud Eureka
- Writing Science
- HDU1197 Specialized Four-Digit Numbers
- 有符号整、小数的原、反、补码表示范围,及补码比原、反码多表示一位的原因
- 实验一:线性表的基本操作实现及其应用
- 电动车改装系列
- MAC 用 Intellij Idea 创建 Spring Cloud Eureka Server 例子
- 寒假学习之STM32(5)----串口实验
- UVA 156 Ananagrams (map应用)
- Java中四个访问修饰符
- Android Err:no permissions (verify udev rules)
- 实验一线性表的基本操作实现及其应用
- 洛谷 1118 [USACO] 数字三角形(不是DP的那道) dfs+乱搞
- java继承中类的初始化过程
- 使用Pandas对数据进行处理