首页 > 其他分享 >在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中

在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中

时间:2023-12-23 23:36:27浏览次数:41  
标签:文件 OpenFeign Spring upload eureka file spring public Cloud


跨服务上传文件,嘿嘿,来一篇实用性高的,本篇将主要完成在Feign中上传文件到另一个微服务中。步骤如下:

我们需要在服务提供者和服务消费者的项目中添加相应的依赖:

对于服务提供者的项目,你需要添加Spring Boot的Web依赖和Spring Cloud的Feign依赖。在pom.xml文件中添加以下依赖:

<dependencies>
    <!-- Spring Boot Web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- Spring Cloud Feign -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
</dependencies>

对于服务消费者的项目,除了上述的依赖外,还需要添加Feign的文件上传支持依赖。在pom.xml文件中添加以下依赖:

<dependencies>
    <!-- Spring Boot Web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- Spring Cloud Feign -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

        <!-- Feign 文件上传支持 -->
        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form</artifactId>
            <version>3.8.0</version>
        </dependency>
</dependencies>

注意,Feign的文件上传支持依赖是feign-form,需要指定相应的版本号。

正式开始

在服务提供者的微服务中,创建一个接收文件上传的接口。可以使用@RequestParam(“file”) MultipartFile file来接收文件参数。

@PostMapping("/upload")
void uploadFile(@RequestParam("file") MultipartFile file);

在服务消费者的微服务中,创建一个Feign接口,并使用@FeignClient注解标记它。在接口中定义上传文件的方法,使用@PostMapping注解,并指定上传文件的路径。

@FeignClient(name = "file-service")
public interface FileServiceClient {

    @PostMapping("/upload")
    void uploadFile(@RequestParam("file") MultipartFile file);
}

在服务消费者的微服务中,配置Feign的文件上传支持。在配置类中添加@Configuration注解,并创建一个FeignClientConfig类,使用@Bean注解配置Encoder和Decoder。

@Configuration
public class FeignClientConfig {

    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder();
    }

    @Bean
    public Decoder feignDecoder() {
        return new ResponseEntityDecoder(new SpringDecoder(feignHttpMessageConverter()));
    }

    private ObjectFactory<HttpMessageConverters> feignHttpMessageConverter() {
        final HttpMessageConverters httpMessageConverters = new HttpMessageConverters(new FormHttpMessageConverter());
        return () -> httpMessageConverters;
    }
}

在服务消费者的微服务中,使用@EnableFeignClients注解启用Feign客户端,并在需要上传文件的地方注入FileServiceClient接口,调用uploadFile方法即可完成文件上传。

@SpringBootApplication
@EnableFeignClients
public class ConsumerApplication {

    @Autowired
    private FileServiceClient fileServiceClient;

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }

    public void uploadFile(MultipartFile file) {
        fileServiceClient.uploadFile(file);
    }
}

这样,通过Feign客户端调用uploadFile方法时,会将文件作为参数上传到服务提供者的微服务中。注意,需要确保服务提供者和服务消费者的微服务都引入了相应的依赖,并且配置正确。

在以上代码中,我们已经定义了Feign客户端接口FileServiceClient,并在服务消费者的代码中注入了该接口。现在,我们只需要在服务消费者的代码中调用FileServiceClientuploadFile方法,即可完成文件上传。

假设我们要上传的文件是一个MultipartFile对象,可以按照以下方式完成文件上传:

@Autowired
private FileServiceClient fileServiceClient;

public void uploadFile(MultipartFile file) {
    fileServiceClient.uploadFile(file);
}

在调用uploadFile方法时,Feign会将MultipartFile对象转换为multipart/form-data格式,并将其作为请求体发送到服务提供者的微服务中。服务提供者的微服务会接收到文件,并进行相应的处理。

需要注意的是,Feign默认使用的是application/json格式进行请求和响应的序列化和反序列化。如果要使用multipart/form-data格式进行文件上传,需要在服务消费者的代码中配置Feign的文件上传支持。

前端界面:

在网页中实现文件上传,可以使用HTML的<form>元素和<input type="file">元素来创建一个文件上传表单。然后,通过JavaScriptAJAX将文件发送到服务端。

<!DOCTYPE html>
<html>
<head>
    <title>文件上传</title>
</head>
<body>
    <h1>文件上传</h1>
    <form id="uploadForm" enctype="multipart/form-data">
        <input type="file" name="file" id="fileInput">
        <button type="submit">上传</button>
    </form>

    <div id="message"></div>

    <script>
        document.getElementById("uploadForm").addEventListener("submit", function(event) {
            event.preventDefault(); // 阻止表单默认提交行为

            var fileInput = document.getElementById("fileInput");
            var file = fileInput.files[0]; // 获取选择的文件

            var formData = new FormData();
            formData.append("file", file); // 将文件添加到FormData对象中

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "/upload"); // 设置请求方法和URL
            xhr.onload = function() {
                if (xhr.status === 200) {
                    document.getElementById("message").textContent = "文件上传成功!";
                } else {
                    document.getElementById("message").textContent = "文件上传失败!";
                }
            };
            xhr.send(formData); // 发送请求
        });
    </script>
</body>
</html>

要通过localhost:端口号直接访问HTML页面,需要在Spring Boot应用程序中添加一个控制器,将HTML页面映射到一个URL路径上。

我的HTML页面名为upload.html,并且位于src/main/resources/static目录下。

@Controller
public class UploadController {
    @GetMapping("/")
    public String index() {
        return "upload.html";
    }
}

在上述代码中,我们创建了一个名为UploadController的控制器,并使用@GetMapping注解将/路径映射到upload.html页面。当用户访问localhost:端口号时,将自动跳转到upload.html页面。

需要注意的是,为了使Spring Boot能够正确地处理静态资源,你需要在application.properties文件中添加以下配置:

spring.mvc.static-path-pattern=/static/**

这将告诉Spring Boot将所有以/static/开头的URL路径映射到src/main/resources/static目录下的静态资源。因此,你需要将upload.html文件放置在src/main/resources/static目录下。

至此,文件上传的大概框架就搭建好了,可以去练练手了。

案例

本案例是博主在以上代码上进行的,并添加了一个单元测试上传txt文件,干货满满,请细细品鉴,光是利用上边的代码,然后汇总,期间碰到了许多错误,才成功搭建成功本案例。

首先来看看博主的项目案例目录结构:

在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_文件上传


在feign模块中搭建两个字模块,一个作为服务模块一个作为消费者模块

eureka-feign-upload-server

来瞅瞅我的pom文件吧

<?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>feign</artifactId>
        <groupId>com.miaow</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eureka-feign-upload-server</artifactId>

    <name>eureka-feign-upload-server</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!--spring-cloud-starter-netflix-eureka-client:这是Eureka客户端的另一个依赖库,用于将应用程序注册到Eureka服务器并从服务器中发现其他服务。它与spring-cloud-starter-eureka功能相似,但是它是基于Netflix Ribbon的,可以提供更多的负载均衡策略和配置选项。通过添加该依赖库,你可以在应用程序中实现Eureka客户端功能,并使用Netflix Ribbon进行负载均衡。-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!--spring-cloud-starter-eureka是Eureka客户端的依赖库,用于将服务注册到Eureka服务器并从Eureka服务器发现其他服务。它包含了Eureka客户端的核心功能,如服务注册、服务发现、负载均衡等。-->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

配置好pom文件,引入相关依赖之后,我们在Application.yml文件中配置我们的相关属性:

server:
  port: 3401

spring:
  application:
    name: eureka-feign-upload-server

# eureka客户端注册到Eureka注册中心,切记需要启动eureka服务
eureka:
  client:
    service-url:
      defaultZone: http://localhost:1000/eureka

#ribbon:
#  eureka:
#    enabled: true

在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_spring boot_02


之后创建一个FileController类

@RestController
public class FileController {

    @PostMapping("/upload")
    public String uploadFile(@RequestParam("file") MultipartFile file) {
        return "文件上传成功";
    }
}

启动类:

@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
public class EurekaUploadServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaUploadServerApplication.class);
    }
}

PS:实际上这里没啥好讲的,按照我的配置方式进行,把它当做服务器就行了。

eureka-feign-upload-client

声明:这个模块看起来简单,但是配置稍有问题就会出现错误,或者服务器找不到,以下是博主使用的,并成功实现的,可以参照一下,但还是推荐你自己玩,碰到不会的可以与我对一下,我在写本篇博文最先时候的时候就是,对照demo来的,一个一个调试,最后成功(鬼知道我踩了多少坑)。

在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_spring boot_03


目录结构如上:

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>feign</artifactId>
        <groupId>com.miaow</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eureka-feign-upload-client</artifactId>

    <name>eureka-feign-upload-client</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <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.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <version>1.4.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form</artifactId>
            <version>3.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form-spring</artifactId>
            <version>3.8.0</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>test</scope>
        </dependency>


    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
application.yml文件配置
server:
  port: 3402

spring:
  application:
    name: eureka-feign-upload-client

  mvc:
    static-path-pattern: /static/**

  # 文件上传限制大小
  servlet:
    multipart:
      enabled: true
      max-file-size: 10MB
      max-request-size: 10MB

# eureka客户端注册到Eureka注册中心,切记需要启动eureka服务
eureka:
  client:
    service-url:
      defaultZone: http://localhost:1000/eureka

只要upload.html文件,在本文的上边,我只改了一个请求位置:

在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_spring_04


在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_微服务_05

FileServiceClient
//@FeignClient注解来指定服务提供者的名称  configuration属性指定了一个内部静态类MultipartSupportConfig,用于配置Feign的编码器。
@FeignClient(value = "eureka-feign-upload-server",configuration = FileServiceClient.MultipartSupportConfig.class)
public interface FileServiceClient {

    //SpringFormEncoder是Feign提供的一个编码器,用于处理multipart/form-data类型的请求。
    @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA)
    String uploadFile(@RequestPart( value = "file") MultipartFile file);


    @Configuration  //代表这个是一个配置类,告诉Spring
    class MultipartSupportConfig{
        @Bean
        public Encoder feignFromEncoder(){
            //返回一个Feign的编码器
            return new SpringFormEncoder();
        }
    }
}
FeignClientConfig配置类
@Configuration
public class FeignClientConfig {

    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder();
    }

    @Bean
    public Decoder feignDecoder() {
        return new ResponseEntityDecoder(new SpringDecoder(feignHttpMessageConverter()));
    }

    private ObjectFactory<HttpMessageConverters> feignHttpMessageConverter() {
        final HttpMessageConverters httpMessageConverters = new HttpMessageConverters(new FormHttpMessageConverter());
        return () -> httpMessageConverters;
    }
}
UploadController 控制类
@RestController
@RequestMapping("/api")
public class UploadController {

    @Autowired
    private FileServiceClient fileServiceClient;

    @GetMapping("/")
    public String index() {
        return "upload.html";
    }

    @RequestMapping("/upload")
    public void uploadFile(@RequestPart( value = "file") MultipartFile file) {
        fileServiceClient.uploadFile(file);
    }
}
启动类
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class EurekaUploadClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaUploadClientApplication.class);
    }
}
单元测试类:

注意单元测试的时候,需要一个upload.txt文件,你自己创建

在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_spring_06

@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class UploadTest {

    @Autowired
    FileServiceClient fileServiceClient;

    @Test
    public void testUpload(){
        File file = new File("upload.txt");
        DiskFileItem fileItem = (DiskFileItem) new DiskFileItemFactory().createItem("file",
                MediaType.TEXT_PLAIN_VALUE,true,file.getName());

        try (InputStream input = new FileInputStream(file); OutputStream os = fileItem.getOutputStream()) {
            IOUtils.copy(input, os);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid file: " + e, e);
        }
        MultipartFile multipartFile = new CommonsMultipartFile(fileItem);

        log.info(fileServiceClient.uploadFile(multipartFile));
    }
}

单元测试日志:

2023-12-15 15:03:24.077  INFO 12148 --- [           main] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client eureka-feign-upload-server initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=eureka-feign-upload-server,current list of Servers=[localhost:3401],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;	Instance count:1;	Active connections count: 0;	Circuit breaker tripped count: 0;	Active connections per server: 0.0;]
},Server stats: [[Server:localhost:3401;	Zone:defaultZone;	Total Requests:0;	Successive connection failure:0;	Total blackout seconds:0;	Last connection made:Thu Jan 01 08:00:00 CST 1970;	First connection made: Thu Jan 01 08:00:00 CST 1970;	Active Connections:0;	total failure count in last (1000) msecs:0;	average resp time:0.0;	90 percentile resp time:0.0;	95 percentile resp time:0.0;	min resp time:0.0;	max resp time:0.0;	stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@4374c051
2023-12-15 15:03:24.168  INFO 12148 --- [           main] com.miaow.UploadTest                     : 文件上传成功
2023-12-15 15:03:24.180  INFO 12148 --- [       Thread-8] c.n.l.PollingServerListUpdater           : Shutting down the Executor Pool for PollingServerListUpdater
2023-12-15 15:03:24.181  INFO 12148 --- [extShutdownHook] o.s.c.n.e.s.EurekaServiceRegistry        : Unregistering application EUREKA-FEIGN-UPLOAD-CLIENT with eureka with status DOWN
2023-12-15 15:03:24.182  WARN 12148 --- [extShutdownHook] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1702623804182, current=DOWN, previous=UP]
2023-12-15 15:03:24.182  INFO 12148 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_EUREKA-FEIGN-UPLOAD-CLIENT/localhost:eureka-feign-upload-client:3402: registering service...
2023-12-15 15:03:24.185  INFO 12148 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2023-12-15 15:03:24.188  INFO 12148 --- [extShutdownHook] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook removed for: NFLoadBalancer-PingTimer-eureka-feign-upload-server
2023-12-15 15:03:24.194  INFO 12148 --- [extShutdownHook] c.n.u.concurrent.ShutdownEnabledTimer    : Exception caught (might be ok if at shutdown)

单元测试成功了,那么我们去网页上看看吧:http://localhost:3402/static/upload.html

在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_spring cloud_07


在Spring Cloud中使用OpenFeign完成从一个微服务上传到另一个微服务中_spring cloud_08


ok至此,我们完成这个功能了。算是把坑填完了。


标签:文件,OpenFeign,Spring,upload,eureka,file,spring,public,Cloud
From: https://blog.51cto.com/miaow/8947869

相关文章

  • 在Spring Cloud中实现Feign声明式服务调用客户端
    如果你学过SpringCloud,你应该知道我们可以通过OpenFeign从一个服务中调用另一个服务,我们一般采用的方式就是定义一个Feign接口并使用@FeignClient注解来进行标注,feign会默认为我们创建的接口生成一个代理对象。当我们在代码中调用Feign接口的方法的时候,实际上就是在调用我们Feign......
  • Swagger(一) Swagger/Springfox 入门简介
    转载自:https://blog.csdn.net/donglinjob/article/details/108550636 Swagger/Springfox入门简介一、Swagger 简介1前言接口文档对于前后端开发人员都十分重要。尤其近几年流行前后端分离后接口文档又变成重中之重。接口文档固然重要,但是由于项目周期等原因后端人员经......
  • 将 Spring Boot WAR 部署到 Tomcat 服务器
    Servlet容器期望应用程序满足要部署的某些协定。对于Tomcat,合约是 ServletAPI3.0。为了让我们的应用程序满足这个契约,我们必须对源代码进行一些小的修改。 首先,我们需要打包一个WAR应用程序而不是JAR。为此,我们将使用以下内容更改 pom.xml:<packaging>war</packaging......
  • org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis
    Requestprocessingfailed;nestedexceptionisorg.mybatis.spring.MyBatisSystemException:nestedexceptionisorg.apache.ibatis.binding.BindingException:Parameter'keyWord'notfound.Availableparametersare[keyword,param1] 错误原因:我在mapper里加......
  • Spring Boot框架必知,满满干货!
    1、初识SpringBoot框架1.1SpringBoot框架定义SpringBoot并不是替代Spring框架的解决方案,而是和Spring框架紧密结合用于提升Spring开发者体验的工具,同时SpringBoot还集成了大量常用的第三方库配置,本质上是基于Spring的Web应用程序开发框架。1.2SpringBoot框架的优点可快速构......
  • cloudflare,vercel and netlify的作用和区别
    Cloudflare,Vercel和Netlify都是为开发者提供的云计算服务,但它们的功能和特性有所不同。Cloudflare的主要使命是帮助构建更好的互联网。它是世界上最大的网络之一,为企业、非营利组织、博客作者和任何有互联网存在的人提供更快、更安全的网站和应用。Cloudflare的网络上有数百万......
  • SpringSecurity:自定义身份认证异常处理器不生效
    由于我配置了全局异常处理器,再配置身份认证异常处理器后,发现异常直接被全局异常处理器捕获了@RestControllerAdvice("com.gsy.wy")@Slf4jpublicclassGlobalException{@ExceptionHandler(Exception.class)publicResulthandlerException(Exceptione){l......
  • Java Spring Boot 集成 elasticsearch6.8.x
    在全文搜索领域,毫无疑问,当下elasticsearch应用广泛,其优势自不必说,凭借全文快速搜索,可以在短时内实现大数据量的查询。今天学习下在SpringBoot中集成elasticsearch开发,这里主要展示可以怎么用,至于开发人员向通过ElasticsearchORM封装,也可以参考下面的示例。环境:Sprin......
  • Spring MVC 源码分析 - HandlerMapping 组件(三)之 AbstractHandlerMethodMapping
    HandlerMapping组件HandlerMapping组件,请求的处理器匹配器,负责为请求找到合适的 HandlerExecutionChain 处理器执行链,包含处理器(handler)和拦截器们(interceptors)handler 处理器是Object类型,可以将其理解成HandlerMethod对象(例如我们使用最多的 @RequestMapping 注解所标......
  • spring-jcl 模块源码分析
    目录简介源码分析总结简介spring-jcl是spring用于处理日志打印的模块,被spring-core所依赖:jcl全称是JakartaCommonsLogging,是apache提供的日志门面(功能同slf4j),日志门面利用设计模式中的门面模式提供统一的日志接口,实际的日志实现可以任意更换。不过jcl支持的日志实现有限,已......