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

2018-12-19 19:41:30 +08:00
 liuzhaowei55
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();
    }
1722 次点击
所在节点    Java
3 条回复
joooooker21
2018-12-19 20:12:01 +08:00
springboot 默认开启注解扫描的,所以使用注解就可以了~ @Component @Autowired
zizaiv2
2018-12-20 10:44:44 +08:00
tkmybatis
cyhulk
2018-12-25 18:12:11 +08:00
Interceptor 中引入一个 static 变量呗,等 context 起来之后 set 进去不就行了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/519098

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX