使用eclipse一步一步创建SpringCloud项目(一)——创建项目父工程、Eureka

1、File—>New—Maven Project,选择Create a simple project,点击next

使用eclipse一步一步创建SpringCloud项目(一)——创建项目父工程、Eureka_第1张图片

 

2、输入Group Id,Artifact Id,Packaging选择pom,点击Finish

使用eclipse一步一步创建SpringCloud项目(一)——创建项目父工程、Eureka_第2张图片

 

3、父工程创建完成后,修改父pom文件,加入SpringCloud依赖

<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.0modelVersion>
    <groupId>com.landcodegroupId>
    <artifactId>landartifactId>
    <version>1.0.0-SNAPSHOTversion>
    <packaging>pompackaging>

    <properties>
        <spring-cloud.version>Greenwich.SR2spring-cloud.version>
        <spring-boot.version>2.1.6.RELEASEspring-boot.version>
        <gson.version>2.6gson.version>
    properties>

    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-dependenciesartifactId>
                <version>${spring-cloud.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>

            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-dependenciesartifactId>
                <version>${spring-boot.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
        dependencies>
    dependencyManagement>

    <dependencies>
        
        <dependency>
            <groupId>com.google.code.gsongroupId>
            <artifactId>gsonartifactId>
            <version>${gson.version}version>
        dependency>
    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <encoding>utf-8encoding>
                    <source>1.8source>
                    <target>1.8target>
                configuration>
            plugin>
        plugins>
    build>
project>

 

4、开始创建子项目eureka,右键工程 New—>Maven Module,选择Create a simple project,输入Module Name,点击Next

使用eclipse一步一步创建SpringCloud项目(一)——创建项目父工程、Eureka_第3张图片

 

5、输入Group Id,Packaging选择jar,点击Finish完成子项目创建

使用eclipse一步一步创建SpringCloud项目(一)——创建项目父工程、Eureka_第4张图片

 

6、eureka子项目创建完成后,修改pom文件,加入springboot依赖,加入springboot-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.0modelVersion>
    <parent>
        <groupId>com.landcodegroupId>
        <artifactId>landartifactId>
        <version>1.0.0-SNAPSHOTversion>
    parent>
    <artifactId>land-eurekaartifactId>

    
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
        dependency>
    dependencies>

    <build>
        <finalName>land-eurekafinalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <executions>
                    <execution>
                        <goals>
                        
                            <goal>repackagegoal>
                        goals>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <encoding>utf-8encoding>
                    <source>1.8source>
                    <target>1.8target>
                configuration>
            plugin>
        plugins>
    build>
project>

 

7、在eureka项目的src/main/java/包根目录下创建启动类如下

@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }
}

 

8、在eureka项目的src/main/resources根目录下创建application.yml配置文件

#本机端口
server:
  port: 8761

eureka:
  client:
#是否向注册中心注册自己
    register-with-eureka: false
#是否从注册中心查询服务
    fetch-registry: false
#注册中心地址
    service-url:
      defaultZone: http://localhost:8761/eureka/

 

9、eclipse创建springcloud项目并集成eureka完成

 浏览器打开 http://192.168.0.3:8761/ 访问eureka管理页面

转载于:https://www.cnblogs.com/alan6/p/11517970.html

你可能感兴趣的:(使用eclipse一步一步创建SpringCloud项目(一)——创建项目父工程、Eureka)