浏览代码

init nacos project

zxy 2 年之前
父节点
当前提交
d45bb9f06b

+ 8 - 0
.gitignore

@@ -11,4 +11,12 @@
11 11
 
12 12
 # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
13 13
 hs_err_pid*
14
+# maven
15
+comsumer-service/.mvn*
16
+offer-service/.mvn*
14 17
 
18
+# mvnw
19
+comsumer-service/mvnw
20
+comsumer-service/mvnw.cmd
21
+offer-service/mvnw
22
+offer-service/mvnw.cmd

+ 34 - 0
comsumer-service/.gitignore

@@ -0,0 +1,34 @@
1
+HELP.md
2
+target/
3
+!.mvn/wrapper/maven-wrapper.jar
4
+!**/src/main/**/target/
5
+!**/src/test/**/target/
6
+
7
+### STS ###
8
+.apt_generated
9
+.classpath
10
+.factorypath
11
+.project
12
+.settings
13
+.springBeans
14
+.sts4-cache
15
+
16
+### IntelliJ IDEA ###
17
+.idea
18
+*.iws
19
+*.iml
20
+*.ipr
21
+
22
+### NetBeans ###
23
+/nbproject/private/
24
+/nbbuild/
25
+/dist/
26
+/nbdist/
27
+/.nb-gradle/
28
+build/
29
+!**/src/main/**/build/
30
+!**/src/test/**/build/
31
+
32
+### VS Code ###
33
+.vscode/
34
+.mvn/

+ 63 - 0
comsumer-service/pom.xml

@@ -0,0 +1,63 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+    <modelVersion>4.0.0</modelVersion>
5
+    <parent>
6
+        <artifactId>nacosParent</artifactId>
7
+        <groupId>org.example</groupId>
8
+        <version>1.0-SNAPSHOT</version>
9
+    </parent>
10
+    <groupId>com.example</groupId>
11
+    <artifactId>comsumer-service</artifactId>
12
+    <version>0.0.1-SNAPSHOT</version>
13
+    <name>comsumer-service</name>
14
+    <description>comsumer-service</description>
15
+    <properties>
16
+        <java.version>1.8</java.version>
17
+    </properties>
18
+    <dependencies>
19
+        <dependency>
20
+            <groupId>org.springframework.boot</groupId>
21
+            <artifactId>spring-boot-starter</artifactId>
22
+        </dependency>
23
+
24
+        <dependency>
25
+            <groupId>org.springframework.boot</groupId>
26
+            <artifactId>spring-boot-starter-test</artifactId>
27
+            <scope>test</scope>
28
+        </dependency>
29
+        <dependency>
30
+            <groupId>org.springframework.boot</groupId>
31
+            <artifactId>spring-boot-starter-web</artifactId>
32
+        </dependency>
33
+        <dependency>
34
+            <groupId>com.alibaba.cloud</groupId>
35
+            <artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
36
+            <version>2.2.0.RELEASE</version>
37
+            <exclusions>
38
+                <exclusion>
39
+                    <groupId>org.springframework.cloud</groupId>
40
+                    <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
41
+                </exclusion>
42
+            </exclusions>
43
+        </dependency>
44
+        <dependency>
45
+            <groupId>org.springframework.cloud</groupId>
46
+            <artifactId>spring-cloud-loadbalancer</artifactId>
47
+        </dependency>
48
+        <dependency>
49
+            <groupId>org.springframework.cloud</groupId>
50
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
51
+        </dependency>
52
+    </dependencies>
53
+
54
+    <build>
55
+        <plugins>
56
+            <plugin>
57
+                <groupId>org.springframework.boot</groupId>
58
+                <artifactId>spring-boot-maven-plugin</artifactId>
59
+            </plugin>
60
+        </plugins>
61
+    </build>
62
+
63
+</project>

+ 19 - 0
comsumer-service/src/main/java/com/example/comsumerservice/ComsumerServiceApplication.java

@@ -0,0 +1,19 @@
1
+package com.example.comsumerservice;
2
+
3
+import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6
+import org.springframework.cloud.openfeign.EnableFeignClients;
7
+import org.springframework.context.annotation.ComponentScan;
8
+
9
+@SpringBootApplication
10
+@EnableDiscoveryClient
11
+@EnableFeignClients
12
+//@ComponentScan({"com"})
13
+public class ComsumerServiceApplication {
14
+
15
+    public static void main(String[] args) {
16
+        SpringApplication.run(ComsumerServiceApplication.class, args);
17
+    }
18
+
19
+}

+ 17 - 0
comsumer-service/src/main/java/com/example/comsumerservice/controller/ComsumerController.java

@@ -0,0 +1,17 @@
1
+package com.example.comsumerservice.controller;
2
+
3
+import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.web.bind.annotation.GetMapping;
5
+import org.springframework.web.bind.annotation.RestController;
6
+
7
+@RestController
8
+public class ComsumerController {
9
+    @Autowired
10
+    ProvideClient provideClient;
11
+    @GetMapping("/offer")
12
+    public String offerService(){
13
+        System.out.println("comsumer service invoke");
14
+        //执行在注册中心注册的远程服务调用
15
+        return "comsumer service invoke"+"======" + provideClient.offerService();
16
+    }
17
+}

+ 10 - 0
comsumer-service/src/main/java/com/example/comsumerservice/controller/ProvideClient.java

@@ -0,0 +1,10 @@
1
+package com.example.comsumerservice.controller;
2
+
3
+import org.springframework.cloud.openfeign.FeignClient;
4
+import org.springframework.web.bind.annotation.GetMapping;
5
+
6
+@FeignClient(value = "offer-service")
7
+public interface ProvideClient {
8
+    @GetMapping("/offer")
9
+    String offerService();
10
+}

+ 1 - 0
comsumer-service/src/main/resources/application.properties

@@ -0,0 +1 @@
1
+

+ 9 - 0
comsumer-service/src/main/resources/application.yml

@@ -0,0 +1,9 @@
1
+server:
2
+  port: 8886
3
+spring:
4
+  application:
5
+    name: comsumer-service
6
+  cloud:
7
+    nacos:
8
+      discovery:
9
+        server-addr: 127.0.0.1:8848

+ 13 - 0
comsumer-service/src/test/java/com/example/comsumerservice/ComsumerServiceApplicationTests.java

@@ -0,0 +1,13 @@
1
+package com.example.comsumerservice;
2
+
3
+import org.junit.jupiter.api.Test;
4
+import org.springframework.boot.test.context.SpringBootTest;
5
+
6
+@SpringBootTest
7
+class ComsumerServiceApplicationTests {
8
+
9
+    @Test
10
+    void contextLoads() {
11
+    }
12
+
13
+}

+ 33 - 0
offer-service/.gitignore

@@ -0,0 +1,33 @@
1
+HELP.md
2
+target/
3
+!.mvn/wrapper/maven-wrapper.jar
4
+!**/src/main/**/target/
5
+!**/src/test/**/target/
6
+
7
+### STS ###
8
+.apt_generated
9
+.classpath
10
+.factorypath
11
+.project
12
+.settings
13
+.springBeans
14
+.sts4-cache
15
+
16
+### IntelliJ IDEA ###
17
+.idea
18
+*.iws
19
+*.iml
20
+*.ipr
21
+
22
+### NetBeans ###
23
+/nbproject/private/
24
+/nbbuild/
25
+/dist/
26
+/nbdist/
27
+/.nb-gradle/
28
+build/
29
+!**/src/main/**/build/
30
+!**/src/test/**/build/
31
+
32
+### VS Code ###
33
+.vscode/

+ 54 - 0
offer-service/pom.xml

@@ -0,0 +1,54 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+    <modelVersion>4.0.0</modelVersion>
5
+    <parent>
6
+        <artifactId>nacosParent</artifactId>
7
+        <groupId>org.example</groupId>
8
+        <version>1.0-SNAPSHOT</version>
9
+    </parent>
10
+    <groupId>com.example</groupId>
11
+    <artifactId>offer-service</artifactId>
12
+    <version>0.0.1-SNAPSHOT</version>
13
+    <name>offer-service</name>
14
+    <description>offer-service</description>
15
+    <properties>
16
+        <java.version>1.8</java.version>
17
+    </properties>
18
+    <dependencies>
19
+        <dependency>
20
+            <groupId>org.springframework.boot</groupId>
21
+            <artifactId>spring-boot-starter</artifactId>
22
+        </dependency>
23
+        <dependency>
24
+            <groupId>com.alibaba.cloud</groupId>
25
+            <artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
26
+            <version>2.2.0.RELEASE</version>
27
+        </dependency>
28
+        <dependency>
29
+            <groupId>org.springframework.boot</groupId>
30
+            <artifactId>spring-boot-starter-web</artifactId>
31
+        </dependency>
32
+        <dependency>
33
+            <groupId>org.springframework.cloud</groupId>
34
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
35
+            <version>3.1.1</version>
36
+        </dependency>
37
+
38
+        <dependency>
39
+            <groupId>org.springframework.boot</groupId>
40
+            <artifactId>spring-boot-starter-test</artifactId>
41
+            <scope>test</scope>
42
+        </dependency>
43
+    </dependencies>
44
+
45
+    <build>
46
+        <plugins>
47
+            <plugin>
48
+                <groupId>org.springframework.boot</groupId>
49
+                <artifactId>spring-boot-maven-plugin</artifactId>
50
+            </plugin>
51
+        </plugins>
52
+    </build>
53
+
54
+</project>

+ 17 - 0
offer-service/src/main/java/com/example/offerservice/OfferServiceApplication.java

@@ -0,0 +1,17 @@
1
+package com.example.offerservice;
2
+
3
+import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6
+import org.springframework.cloud.openfeign.EnableFeignClients;
7
+
8
+@SpringBootApplication
9
+@EnableDiscoveryClient
10
+@EnableFeignClients
11
+public class OfferServiceApplication {
12
+
13
+    public static void main(String[] args) {
14
+        SpringApplication.run(OfferServiceApplication.class, args);
15
+    }
16
+
17
+}

+ 12 - 0
offer-service/src/main/java/com/example/offerservice/controller/OfferController.java

@@ -0,0 +1,12 @@
1
+package com.example.offerservice.controller;
2
+
3
+import org.springframework.web.bind.annotation.GetMapping;
4
+import org.springframework.web.bind.annotation.RestController;
5
+
6
+@RestController
7
+public class OfferController {
8
+    @GetMapping("/offer")
9
+    public String offerService() {
10
+        return "offer service invoke";
11
+    }
12
+}

+ 1 - 0
offer-service/src/main/resources/application.properties

@@ -0,0 +1 @@
1
+

+ 9 - 0
offer-service/src/main/resources/application.yml

@@ -0,0 +1,9 @@
1
+server:
2
+  port: 8520
3
+spring:
4
+  application:
5
+    name: offer-service
6
+  cloud:
7
+    nacos:
8
+      discovery:
9
+        server-addr: 127.0.0.1:8848

+ 13 - 0
offer-service/src/test/java/com/example/offerservice/OfferServiceApplicationTests.java

@@ -0,0 +1,13 @@
1
+package com.example.offerservice;
2
+
3
+import org.junit.jupiter.api.Test;
4
+import org.springframework.boot.test.context.SpringBootTest;
5
+
6
+@SpringBootTest
7
+class OfferServiceApplicationTests {
8
+
9
+    @Test
10
+    void contextLoads() {
11
+    }
12
+
13
+}

+ 47 - 0
pom.xml

@@ -0,0 +1,47 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+    <groupId>org.example</groupId>
7
+    <artifactId>nacosParent</artifactId>
8
+    <packaging>pom</packaging>
9
+    <version>1.0-SNAPSHOT</version>
10
+    <modules>
11
+        <module>offer-service</module>
12
+        <module>comsumer-service</module>
13
+    </modules>
14
+    <dependencyManagement>
15
+        <dependencies>
16
+            <dependency>
17
+                <groupId>com.alibaba.cloud</groupId>
18
+                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
19
+                <version>2021.0.1.0</version>
20
+                <type>pom</type>
21
+                <scope>import</scope>
22
+            </dependency>
23
+            <!--springCloud的包管理器-->
24
+            <dependency>
25
+                <groupId>org.springframework.cloud</groupId>
26
+                <artifactId>spring-cloud-dependencies</artifactId>
27
+                <version>2021.0.1</version>
28
+                <type>pom</type>
29
+                <scope>import</scope>
30
+            </dependency>
31
+            <!--springBoot的启动器的包管理器-->
32
+            <dependency>
33
+                <groupId>org.springframework.boot</groupId>
34
+                <artifactId>spring-boot-dependencies</artifactId>
35
+                <version>2.6.5</version>
36
+                <type>pom</type>
37
+                <scope>import</scope>
38
+            </dependency>
39
+        </dependencies>
40
+    </dependencyManagement>
41
+
42
+    <properties>
43
+        <maven.compiler.source>8</maven.compiler.source>
44
+        <maven.compiler.target>8</maven.compiler.target>
45
+    </properties>
46
+
47
+</project>