求解:GridFsTemplate是如何加载到IOC容器中的?

如下是SpringBoot项目中的测试类代码:测试GridFsTemplate存储文件到MongoDB数据库中 

package com.xuecheng.manage_cms;

import org.bson.types.ObjectId;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.gridfs.GridFsTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

@SpringBootTest
@RunWith(SpringRunner.class)
public class GridFSTemplateTest {
    /**
     * 这里的GridFsTemplate直接使用依赖注入
     * 没有明白这里的GridFsTemplate是如何加载到容器中的?
     * 在启动类和配置类中都没有找到相关的代码
     */
    @Autowired
    GridFsTemplate gridFsTemplate;

    /**
     * 存文件
     * @throws FileNotFoundException
     */
    @Test
    public void test1() throws FileNotFoundException {
        File file = new File("D:/index_banner.ftl");
        FileInputStream fis = new FileInputStream(file);
        ObjectId objectId = gridFsTemplate.store(fis, "index_banner.ftl", "");
        String fileId = objectId.toString();
        System.out.println(fileId);

    }

    //存文件(资料中复制的代码)
    @Test
    public void testStore() throws FileNotFoundException {
        //定义file
        File file =new File("d:/index_banner222.ftl");
        //定义fileInputStream
        FileInputStream fileInputStream = new FileInputStream(file);
        ObjectId objectId = gridFsTemplate.store(fileInputStream, "index_banner222.ftl");
        System.out.println(objectId);
    }
}

 疑问:疑问:GridFsTemplate是如何加载到IOC容器中的?

这里直接使用@Autowired就开始依赖注入,但是GridFsTemplate类是如何进入IOC容器中的呢?

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值