Creating springcloud eclipse project (a) - Creating a parent project engineering, Eureka

1, File-> New-Maven Project, select Create a simple project, click next

 

2. Enter Group Id, Artifact Id, Packaging choose pom, click Finish

 

3, after the parent project has been created, modify the parent pom file, add SpringCloud dependent, spring boot maven plugin

<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>com.lancode.iot</groupId>
    <artifactId>mqtt_alan</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <!-- spring-cloud所有项目依赖包 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>mqtt-alan-root</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>utf-8</encoding>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

 

4, start creating subprojects eureka, right-engineering New-> Maven Module, select Create a simple project, enter the Module Name, click Next

 

5. Enter Group Id, Packaging choose jar, click Finish to create subprojects

 

6, after eureka subproject is created, modified pom file

<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>
    <parent>
        <groupId>com.lancode.iot</groupId>
        <artifactId>mqtt_alan</artifactId>
        <version>0.0.1-SNAPSHOT</Version > 
    </ parent > 
    < the artifactId > LAN-Eureka </ the artifactId > 

    <-! add a package file registry dependent -> 
    < Dependencies > 
        < dependency > 
            < the groupId > org.springframework.cloud </ the groupId > 
            < the artifactId > the Spring-Cloud-Starter-Netflix-Eureka-Server </ artifactId > 
        </ dependency > 
        
        <-! must introduce gson version 2.6 replace version 2.2, is not compatible or will be error -> 
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6</version>
            <!--<scope>compile</scope>-->
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

 

7, create a startup class follows in the src eureka project / main / java / package root directory

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

 

8, create application.yml profile in src / main / resources root of the eureka project

# Local port 
Server: 
  Port: 8761 

Eureka: 
  Client: 
# whether to register itself with the registry 
    the Register-with-Eureka: false 
# whether from the registry query service 
    FETCH-Registry: false 
# Registration Center Address 
    Service-url: 
      defaultzone: HTTP : // localhost: 8761 / eureka /

 

9, eclipse springcloud create and integrate eureka project completed

 

Guess you like

Origin www.cnblogs.com/alan6/p/11517970.html