Create a Spring Boot Project Module mechanism project through Eclipse's Maven, and implement eureka
1. Create a Maven Project
File -> New -> Maven -> Maven Project
勾选“Create a simple project(skip archetype selection)”
Packaging select pom, then click "Finish" to complete the creation of "ershuai-blog"
2. The pom.xml of ershuai-blog
Add configuration to pom.xml of "ershuai-blog"
Be sure to remember to add dependencyManagement. Otherwise, the subproject cannot add <parent>, because spring boot will occupy <parent>
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-boot.version>1.5.7.RELEASE</spring-boot.version> <spring-cloud.version>Dalston.SR3</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- spring boot supports the logback logging framework by default, and logging is an associated package --> <!-- Console output log level: TRACE < DEBUG < INFO < WARN < ERROR < FATAL. Default INFO --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!-- After adding this configuration, spring boot type sub-projects do not need to configure the <parent> tag of org.springframework.boot--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
3. Create sub-projects
Select the "ershuai-blog" project, right-click Maven -> New Maven Module Project, and create the "ershuai-eureka-server" project
勾选“Create a simple project(skip archetype selection)”
Packaging select jar, then click "Finish" to complete the creation of "ershuai-eureka-server"
Fourth, ershuai-eureka-server-like pom.xml
This sub-project is used as eureka, so the eureka package is introduced
To run the subproject as a jar package, you must add spring-boot-maven-plugin, otherwise the MANIFEST.MF information of the typed jar package is incorrect and cannot run normally. It may prompt a "no main manifest attribute" error or something
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <!-- spring boot jar package, this configuration is required for normal operation. Otherwise, it may prompt that there is no main manifest attribute in the jar, and other error messages --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Five, application.yml configuration
eureka-like application.yml placement
spring: application: name: ershuai-eureka-server server: port: 1001 eureka: client: register-with-eureka: false # Whether to register itself to the eureka server fetch-registry: false # Whether to get the registration information from eureka instance: hostname: localhost instance-id: ${spring.cloud.client.ipAddress}:${server.port} # Specify the ip of this instance prefer-ip-address: true # use ip instead of hostname when registering #server: #enable-self-preservation: false # Enable protection mechanism
6. Start
6.1, the main method runs
/** * * @author ershuai *@date April 23, 2018 at 6:33:29 PM * * jar run mode * java -jar ershuai-eureka-server-0.0.1-SNAPSHOT.jar * */ @EnableEurekaServer @SpringBootApplication public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } }
6.2, jar package operation
Select the "ershuai-eureka-server" project, right-click, Run As -> Maven Install. After success, in the target folder, a jar package will be generated
Under windows, cmd goes to this directory and executes the command: java -jar xxxx.jar. ready to run
7. Visit eureka
http://localhost:1001/