单纯测试2个相同Bean 导致报错!

    // Bean name 要与value保持一致 不然回报错哦
    @Bean(name = "redisson1",value = "redisson1")
    public Redisson redisson001() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:6379").setDatabase(0);
        return (Redisson) Redisson.create(config);
    }

    @Bean(name = "redisson2",value = "redisson2")
    public Redisson redisson002() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:6379").setDatabase(1);
        return (Redisson) Redisson.create(config);
    }

    @Autowired
    private Redisson redisson;

启动项目报错信息

***************************
APPLICATION FAILED TO START
***************************

Description:

Field redisson in com.XXX.XXX.controller.SameNameBeanTest required a single bean, but 2 were found:
	- redisson1: defined by method 'redisson001' 
	- redisson2: defined by method 'redisson002' 

正常代码

import cn.hutool.core.date.DateTime;
import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : zanglikun
 * @date : 2021/12/22 10:48
 * @Version: 1.0
 * @Desc : @Bean的同名处理
 */
@RestController
@RequestMapping("redis")
public class SameNameBeanTest {

    // Bean name 要与value保持一致 不然回报错哦
    @Bean(name = "redisson1", value = "redisson1")
    public Redisson redisson001() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:6379").setDatabase(0);
        return (Redisson) Redisson.create(config);
    }

    @Bean(name = "redisson2", value = "redisson2")
    public Redisson redisson002() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:6379").setDatabase(1);
        return (Redisson) Redisson.create(config);
    }


    /**
     * Redisson1
     */
    @Autowired()
    @Qualifier(value = "redisson1")
    private Redisson redisson1;

    @GetMapping("redis001")
    public void redis001() {
        redisson1.getBucket("Redis001").set(new DateTime());
    }


    /**
     * Redisson2
     */
    @Resource(name = "redisson2")
    private Redisson redisson2;

    @GetMapping("redis002")
    public void redis002() {
        redisson2.getBucket("Redis002").set(new DateTime());
    }

}

完结!