Springboot集成Dubbo(以注解形式)

本文涉及的产品
注册配置 MSE Nacos/ZooKeeper,118元/月
云原生网关 MSE Higress,422元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: Springboot集成Dubbo(以注解形式)

Springboot 集成 Dubbo(以注解形式)

网址


Dubbo 官方文档:http://dubbo.apache.org/zh-cn/docs/user/quick-start.html

Zookeeper 安装

单机安装,见官网


案例一

使用专用接口定义


项目总体结构如下

springboot-dubbo
----dubbo-api
  ----pom
  ----src
  ----main
            ----java
                ----top.simba1949.service.DubboService.java
----dubbo-provider
  ----pom
  ----src
  ----main
    ----java
    ----top.simba1949
      ----Application.java
      ----service.impl.DubboServiceImpl.java
  ----resources
    ----application.yml
----dubbo-consumer
  ----pom
  ----src
  ----main
    ----java
    ----top.simba1949
      ----Application.java
      ----controller.DubboController
  ----resources
    ----application.yml


父项目


用于管理项目依赖和版本控制

Springboot 集成 Dubbo 的依赖

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>${dubbo.version}</version>
</dependency>
<dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>dubbo-spring-boot-starter</artifactId>
    <version>${dubbo-spring-boot-starter.version}</version>
</dependency>
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
</dependency>


pom.xml

<properties>
    <lombok.version>1.18.4</lombok.version>
    <dubbo.version>2.6.4 </dubbo.version>
    <dubbo-spring-boot-starter.version>0.2.0</dubbo-spring-boot-starter.version>
</properties>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.spring.platform</groupId>
            <artifactId>platform-bom</artifactId>
            <version>Cairo-SR6</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional> <!-- 表示依赖不会传递 -->
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>${dubbo.version}</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba.boot</groupId>
        <artifactId>dubbo-spring-boot-starter</artifactId>
        <version>${dubbo-spring-boot-starter.version}</version>
    </dependency>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <!--编译插件-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <!-- 配置使用的 jdk 版本 -->
                <target>1.8</target>
                <source>1.8</source>
            </configuration>
        </plugin>
        <!--springboot-maven打包插件-->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <!--资源拷贝插件-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <!--实现热部署插件-->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
            </configuration>
        </plugin>
    </plugins>
    <!--IDEA是不会编译src的java目录的xml文件,如果需要读取,则需要手动指定哪些配置文件需要读取-->
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>
</build>


接口定义 module

DubboService.java

package top.simba1949.service;
/**
 * @author SIMBA1949
 * @date 2019/1/21 22:34
 */
public interface DubboService {
    /**
     * HELLO
     * @param hello
     * @return
     */
    String str(String hello);
}


服务提供者 module

服务提供者依赖接口定义 module


pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>dubbo-01</artifactId>
        <groupId>top.simba1949</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>dubbo-01-producer</artifactId>
    <dependencies>
        <dependency>
            <groupId>top.simba1949</groupId>
            <artifactId>dubbo-01-service</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>


application.yml 配置文件

server:
  port: 8091
# dubbo 配置
dubbo:
  application:
    id: dubbo-producer
    name: dubbo-producer
  # dubbo 注册中心地址
  registry:
    address: zookeeper://192.168.239.147:2181
  # 服务提供者的协议名和端口
  protocol:
    server: true
    name: dubbo
    port: 20800


实现类 DubboServiceImpl.java 实现具体的业务逻辑

package top.simba1949.service.impl;
import com.alibaba.dubbo.config.annotation.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.simba1949.service.DubboService;
/**
 * com.alibaba.dubbo.config.annotation.Service 是 Alibaba 包下的注解,表明这是 dubbo 服务提供者
 * @author SIMBA1949
 * @date 2019/1/21 22:34
 */
@Slf4j
@Component
@Service
public class DubboServiceImpl implements DubboService {
    @Override
    public String str(String hello) {
        log.info("服务提供者:" + hello);
        return "服务提供者道:" + hello;
    }
}


启动类 Application.java

package top.simba1949;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * @EnableDubbo 用于开启 dubbo 注解的扫描和自动配置
 * @author SIMBA1949
 * @date 2019/1/21 22:32
 */
@EnableDubbo
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

服务消费者 module

服务消费者依赖接口定义 module


pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>dubbo-01</artifactId>
        <groupId>top.simba1949</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>dubbo-01-consumer</artifactId>
    <dependencies>
        <dependency>
            <groupId>top.simba1949</groupId>
            <artifactId>dubbo-01-service</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>


application.yml

server:
  port: 8081
dubbo:
  application:
    id: dubbo-consumer
    name: dubbo-consumer
  registry:
    address: zookeeper://192.168.239.147:2181
  protocol:
    name: dubbo
    port: 20800
  consumer:
    check: false


调用服务的具体的类 DubboController.java

package top.simba1949.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.simba1949.service.DubboService;
/**
 * @Reference 会自动注入 dubbo 服务
 * @author SIMBA1949
 * @date 2019/1/21 22:45
 */
@RestController
@RequestMapping
@Slf4j
public class DubboController {
    @Reference
    private DubboService dubboService;
    @GetMapping("hello")
    public String str(String hello){
        log.info("消费者消费前:" + hello);
        String str = dubboService.str(hello);
        log.info("消费者消费后:" + str);
        return str;
    }
}


启动类

package top.simba1949;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * @author SIMBA1949
 * @date 2019/1/21 22:43
 */
@SpringBootApplication
@EnableDubbo
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}


案例二

服务提供者和服务消费者,使用相同的接口和实体类,但是属于不同的文件


服务提供者

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>top.simba1949</groupId>
    <artifactId>dubbo-02-provider</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <lombok.version>1.18.4</lombok.version>
        <dubbo.version>2.6.4 </dubbo.version>
        <dubbo-spring-boot-starter.version>0.2.0</dubbo-spring-boot-starter.version>
        <fastjson.version>1.2.55</fastjson.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>Cairo-SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 表示依赖不会传递 -->
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>${dubbo-spring-boot-starter.version}</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!--编译插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <!-- 配置使用的 jdk 版本 -->
                    <target>1.8</target>
                    <source>1.8</source>
                </configuration>
            </plugin>
            <!--springboot-maven打包插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!--资源拷贝插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!--实现热部署插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                </configuration>
            </plugin>
        </plugins>
        <!--IDEA是不会编译src的java目录的xml文件,如果需要读取,则需要手动指定哪些配置文件需要读取-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>
    </build>
</project>


application.yml

server:
  port: 8071
# DUBBO CONFIGURE
dubbo:
  application:
    id: springboot-dubbo-provider
    name: springboot-dubbo-provider
  registry:
    address: zookeeper://192.168.239.147:2181
  protocol:
    server: true
    name: dubbo
    port: 20801


实体类

package top.simba1949.common;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * @author SIMBA1949
 * @date 2019/1/21 23:45
 */
@Data
public class UserDto implements Serializable {
    private static final long serialVersionUID = 2223107801863147437L;
    private Long id;
    private String username;
    private Date birthday;
    private Boolean flag;
}


接口类

package top.simba1949.service;
import top.simba1949.common.UserDto;
/**
 * @author SIMBA1949
 * @date 2019/1/21 23:45
 */
public interface UserService {
    /**
     * USER
     * @param userStr
     * @return
     */
    UserDto user(String userStr);
}


接口实现类

package top.simba1949.service.impl;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.simba1949.common.UserDto;
import top.simba1949.service.UserService;
/**
 * @author SIMBA1949
 * @date 2019/1/21 23:45
 */
@Component
@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Override
    public UserDto user(String userStr) {
        log.info("服务提供者获取的数据为:" +  userStr);
        UserDto userDto = JSON.parseObject(userStr, UserDto.class);
        userDto.setUsername("服务提供者:" + userDto.getUsername());
        return userDto;
    }
}


启动类

server:
  port: 8071
# DUBBO CONFIGURE
dubbo:
  application:
    id: springboot-dubbo-provider
    name: springboot-dubbo-provider
  registry:
    address: zookeeper://192.168.239.147:2181
  protocol:
    server: true
    name: dubbo
    port: 20801


服务消费者

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>top.simba1949</groupId>
    <artifactId>dubbo-02-consumer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <lombok.version>1.18.4</lombok.version>
        <dubbo.version>2.6.4 </dubbo.version>
        <dubbo-spring-boot-starter.version>0.2.0</dubbo-spring-boot-starter.version>
        <fastjson.version>1.2.55</fastjson.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>Cairo-SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 表示依赖不会传递 -->
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>${dubbo-spring-boot-starter.version}</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!--编译插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <!-- 配置使用的 jdk 版本 -->
                    <target>1.8</target>
                    <source>1.8</source>
                </configuration>
            </plugin>
            <!--springboot-maven打包插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!--资源拷贝插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!--实现热部署插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                </configuration>
            </plugin>
        </plugins>
        <!--IDEA是不会编译src的java目录的xml文件,如果需要读取,则需要手动指定哪些配置文件需要读取-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
        </resources>
    </build>
</project>


配置文件

server:
  port: 8079
# DUBBO CONFIGURE
dubbo:
  application:
    id: springboot-dubbo-consumer
    name: springboot-dubbo-consumer
  registry:
    address: zookeeper://192.168.239.147:2181
  protocol:
    name: dubbo
    port: 20801
  consumer:
    check: false


实体类

package top.simba1949.common;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
 * @author SIMBA1949
 * @date 2019/1/21 23:45
 */
@Data
public class UserDto implements Serializable {
    private static final long serialVersionUID = 2223107801863147437L;
    private Long id;
    private String username;
    private Date birthday;
    private Boolean flag;
}


接口类

package top.simba1949.service;
import top.simba1949.common.UserDto;
/**
 * @author SIMBA1949
 * @date 2019/1/21 23:45
 */
public interface UserService {
    /**
     * USER
     * @param userStr
     * @return
     */
    UserDto user(String userStr);
}


调用dubbo服务java类

package top.simba1949.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.simba1949.common.UserDto;
import top.simba1949.service.UserService;
/**
 * @author SIMBA1949
 * @date 2019/1/21 23:58
 */
@RestController
@RequestMapping
@Slf4j
public class UserController {
    @Reference
    private UserService userService;
    @PostMapping("user")
    public UserDto user(@RequestBody UserDto userDto){
        log.info("消费者消费之前的数据:" +  userDto);
        String userStr = JSON.toJSONString(userDto);
        UserDto user = userService.user(userStr);
        log.info("消费者消费之后的数据:" + user);
        return user;
    }
}


启动类

package top.simba1949;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * @author SIMBA1949
 * @date 2019/1/21 23:43
 */
@EnableDubbo
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}


Dubbo Admin 管理的安装

Dubbo Admin 安装


相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
目录
相关文章
|
1月前
|
XML Java 数据格式
SpringBoot入门(8) - 开发中还有哪些常用注解
SpringBoot入门(8) - 开发中还有哪些常用注解
50 0
|
2月前
|
Java Spring
在使用Spring的`@Value`注解注入属性值时,有一些特殊字符需要注意
【10月更文挑战第9天】在使用Spring的`@Value`注解注入属性值时,需注意一些特殊字符的正确处理方法,包括空格、引号、反斜杠、新行、制表符、逗号、大括号、$、百分号及其他特殊字符。通过适当包裹或转义,确保这些字符能被正确解析和注入。
129 3
|
21天前
|
前端开发 Java Spring
Spring MVC核心:深入理解@RequestMapping注解
在Spring MVC框架中,`@RequestMapping`注解是实现请求映射的核心,它将HTTP请求映射到控制器的处理方法上。本文将深入探讨`@RequestMapping`注解的各个方面,包括其注解的使用方法、如何与Spring MVC的其他组件协同工作,以及在实际开发中的应用案例。
36 4
|
1月前
|
XML JSON Java
SpringBoot必须掌握的常用注解!
SpringBoot必须掌握的常用注解!
60 4
SpringBoot必须掌握的常用注解!
|
21天前
|
前端开发 Java 开发者
Spring MVC中的请求映射:@RequestMapping注解深度解析
在Spring MVC框架中,`@RequestMapping`注解是实现请求映射的关键,它将HTTP请求映射到相应的处理器方法上。本文将深入探讨`@RequestMapping`注解的工作原理、使用方法以及最佳实践,为开发者提供一份详尽的技术干货。
64 2
|
21天前
|
前端开发 Java Spring
探索Spring MVC:@Controller注解的全面解析
在Spring MVC框架中,`@Controller`注解是构建Web应用程序的基石之一。它不仅简化了控制器的定义,还提供了一种优雅的方式来处理HTTP请求。本文将全面解析`@Controller`注解,包括其定义、用法、以及在Spring MVC中的作用。
40 2
|
25天前
|
消息中间件 Java 数据库
解密Spring Boot:深入理解条件装配与条件注解
Spring Boot中的条件装配与条件注解提供了强大的工具,使得应用程序可以根据不同的条件动态装配Bean,从而实现灵活的配置和管理。通过合理使用这些条件注解,开发者可以根据实际需求动态调整应用的行为,提升代码的可维护性和可扩展性。希望本文能够帮助你深入理解Spring Boot中的条件装配与条件注解,在实际开发中更好地应用这些功能。
31 2
|
25天前
|
JSON Java 数据格式
springboot常用注解
@RestController :修饰类,该控制器会返回Json数据 @RequestMapping(“/path”) :修饰类,该控制器的请求路径 @Autowired : 修饰属性,按照类型进行依赖注入 @PathVariable : 修饰参数,将路径值映射到参数上 @ResponseBody :修饰方法,该方法会返回Json数据 @RequestBody(需要使用Post提交方式) :修饰参数,将Json数据封装到对应参数中 @Controller@Service@Compont: 将类注册到ioc容器
|
26天前
|
XML Java 数据格式
SpringBoot入门(8) - 开发中还有哪些常用注解
SpringBoot入门(8) - 开发中还有哪些常用注解
38 2
|
1月前
|
Dubbo Java 应用服务中间件
深入探讨了“dubbo+nacos+springboot3的native打包成功后运行出现异常”的原因及解决方案
本文深入探讨了“dubbo+nacos+springboot3的native打包成功后运行出现异常”的原因及解决方案。通过检查GraalVM版本兼容性、配置反射列表、使用代理类、检查配置文件、禁用不支持的功能、查看日志文件、使用GraalVM诊断工具和调整GraalVM配置等步骤,帮助开发者快速定位并解决问题,确保服务的正常运行。
49 1
下一篇
DataWorks