liuzhaowei55
V2EX  ›  Java

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

  •  
  •   liuzhaowei55 ·
    ysbjlzlx · Dec 19, 2018 · 2208 views
    This topic created in 2726 days ago, the information mentioned may be changed or developed.
    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 replies    2018-12-25 18:12:11 +08:00
    joooooker21
        1
    joooooker21  
       Dec 19, 2018
    springboot 默认开启注解扫描的,所以使用注解就可以了~ @Component @Autowired
    zizaiv2
        2
    zizaiv2  
       Dec 20, 2018
    tkmybatis
    cyhulk
        3
    cyhulk  
       Dec 25, 2018
    Interceptor 中引入一个 static 变量呗,等 context 起来之后 set 进去不就行了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1295 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:23 · PVG 01:23 · LAX 10:23 · JFK 13:23
    ♥ Do have faith in what you're doing.