First, I have enclosed a Gangster's blog: https: //blog.csdn.net/springcyb/article/details/89147639
But in another part of my big brother blog not take myself so I summed up, the proposal is still learning to see me (@ - @)
One: to build a framework springCloud
1. Create a new maven project
src delete files in the folder maven project
2. Create a multi-module maven project children
Right-click on the project - "new-" model
The need for automatic import during the first project established in a number of related packages and dependencies, time may need to be longer, be patient not to shut down half the time he should not be too much trouble
3. Modify the contents inside
3.1 modify application.yml, if the extension is not yml, then right-refactor- "rename course, if the following code can be converted to the format when I did prorpeties
server: port: 8000 eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka server: enable-self-preservation: false
Very simple and that is assigned a port number, and address some of the basic settings
3.2 modify the contents of the file java
package com.example.springcloud_eureka; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer @SpringBootApplication public class SpringcloudEurekaApplication { public static void main(String[] args) { SpringApplication.run(SpringcloudEurekaApplication.class, args); } }
4.运行后我们在地址栏输入http://127.0.0.1:8000/就会出现下面的界面
5.创建一个生产者springcloud-provider
这一块用上面链接的方法会报错,下面是我自己的操作过程
新建一个spring项目除了项目名改成springcloud-provider之外其他的都一样
6 .修改里面的内容
6.1修改application.yml
server: port: 8011 spring: application: name: springcloud-user-reg eureka: client: service-url: defaultZone: http://localhost:8000/eureka
6.2修改java文件的内容
package com.example.springcloudprovider; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /* @SpringBootApplication @EnableEurekaClient @RestController @ComponentScan("com.jk.*") */ @EnableEurekaClient @RestController @SpringBootApplication public class SpringcloudProviderApplication { public static void main(String[] args) { SpringApplication.run(SpringcloudProviderApplication.class, args); } /** * 测试方法 */ //动态取端口号,${server.port}和配置文件的值对应 @Value("${server.port}") String post; @GetMapping("provider1") public String test(){ //返回一句话 return "I post port is :" +post; } }
7.在运行一下这个java文件然后刷新下http://127.0.0.1:8000/的网页显示下面内容
可见生产者已经绑定上去了
打开http://127.0.0.1:8011/provider1可以看到下面内容
下一篇博客我们将开始记录消费者的创建和数据库的一些操作