V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
liuzhaowei55
V2EX  ›  Java

Spring Boot + Mybatis 开发中, Mybatis 插件如何导入 Bean?我列出几个网上没有解决问题的答案,求一个正确答案

  •  
  •   liuzhaowei55 ·
    ysbjlzlx · 2018-12-19 19:41:30 +08:00 · 1701 次点击
    这是一个创建于 1926 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ApplicationContext applicationContext = ContextLoader.getCurrentWebApplicationContext();
    applicationContext.getBean(Service.class);
    
       // 这个是在 WebMvcConfigrer 中
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(mybatisPlugin());
        }
    
        @Bean
        public MybatisPlugin mybatisPlugin() {
            return new MybatisPlugin();
        }
    
    3 条回复    2018-12-25 18:12:11 +08:00
    joooooker21
        1
    joooooker21  
       2018-12-19 20:12:01 +08:00
    springboot 默认开启注解扫描的,所以使用注解就可以了~ @Component @Autowired
    zizaiv2
        2
    zizaiv2  
       2018-12-20 10:44:44 +08:00
    tkmybatis
    cyhulk
        3
    cyhulk  
       2018-12-25 18:12:11 +08:00
    Interceptor 中引入一个 static 变量呗,等 context 起来之后 set 进去不就行了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5898 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 02:20 · PVG 10:20 · LAX 19:20 · JFK 22:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.