springcloud入门教程- server工程的搭建

springcloud server工程的搭建

新建一个简单的maven项目,编写pom.xml


4.0.0

com.lcg
spcdemo
0.0.1-SNAPSHOT
jar

spcdemo
http://maven.apache.org


<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>


org.springframework.boot
spring-boot-starter-parent
1.5.10.RELEASE




org.springframework.cloud
spring-cloud-dependencies
Dalston.SR5
pom
import






org.springframework.cloud
spring-cloud-starter-eureka-server


org.springframework.cloud
spring-cloud-starter-config


org.springframework.boot
spring-boot-starter-test
test


junit
junit
3.8.1
test




spring-snapshots
Spring Snapshots
https://repo.spring.io/libs-snapshot-local

true



spring-milestones
Spring Milestones
https://repo.spring.io/libs-milestone-local

false



spring-releases
Spring Releases
https://repo.spring.io/libs-release-local

false





spring-snapshots
Spring Snapshots
https://repo.spring.io/libs-snapshot-local

true



spring-milestones
Spring Milestones
https://repo.spring.io/libs-milestone-local

false



编写配置文件 /src/main/resources/application.yml

server:
port: 8761

eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0

编写Java代码 /src/main/java/com/lcg/spcdemo/Application.java

package com.lcg.spcdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

/**

  • SpringCloud Demo
    /
    @SpringBootApplication
    @EnableEurekaServer
    public class Application {
    public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
    
    }
    }

运行main方法,看到console控制台输出

然后访问 http://localhost:8761 看到如下图

至此,springcloud的server端搭建完成。

0%