Browse Source

config:后端项目,加入dubbo配置,并配置使用nacos作为注册中心

yang yi 9 months ago
parent
commit
78db9b828f

+ 3 - 0
open-api-gateway/src/main/java/space/anyi/openAPIGateway/Application.java

@@ -1,7 +1,9 @@
 package space.anyi.openAPIGateway;
 
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.context.ConfigurableApplicationContext;
 
 /**
@@ -12,6 +14,7 @@ import org.springframework.context.ConfigurableApplicationContext;
  * @Description:
  */
 @SpringBootApplication
+@EnableDubbo
 public class Application {
     public static void main(String[] args) {
         ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);

+ 19 - 2
pom.xml

@@ -13,7 +13,17 @@
         <maven.compiler.source>17</maven.compiler.source>
         <maven.compiler.target>17</maven.compiler.target>
     </properties>
-
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-bom</artifactId>
+                <version>3.3.0</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
     <parent>
         <artifactId>spring-boot-starter-parent</artifactId>
         <groupId>org.springframework.boot</groupId>
@@ -21,7 +31,14 @@
     </parent>
 
     <dependencies>
-
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-registry-nacos</artifactId>
+        </dependency>
         <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>

+ 12 - 0
src/main/resources/application.yaml

@@ -24,3 +24,15 @@ open-api:
   url: http://localhost:10002
   access-key: accessKey
   secret-key: secretKey
+dubbo:
+  application:
+    name: dubbo-springboot-provider
+    logger: slf4j
+  protocol:
+    name: tri
+    port: 50051
+  registry:
+    id: nacos-registry
+    address: nacos://127.0.0.1:8848
+    username: nacos
+    password: nacos