zoukankan      html  css  js  c++  java
  • Spring @Import注解Demo

    @Import可以把第三方定义的java类加载到spring ioc容器中

    配置文件

    import com.gxf.importdemo.ImportBean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Import;
    import org.springframework.scheduling.annotation.AsyncConfigurer;
    import org.springframework.scheduling.annotation.EnableAsync;
    import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
    
    import java.util.concurrent.Executor;
    
    
    @Configuration
    @ComponentScan("com.gxf.service")
    @EnableAsync
    @Import(ImportBean.class)
    public class AsyncConfig implements AsyncConfigurer {
        @Override
        public Executor getAsyncExecutor() {
            ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
            executor.setCorePoolSize(10);
            executor.setMaxPoolSize(100);
            executor.setQueueCapacity(10);
            executor.initialize();
            return executor;
        }
    }

    通过@Import注解把ImportBean 加入到spring ioc容器中,ImportBean没有任何spring ioc容器相关的注解

    public class ImportBean {
        public void test() {
            System.out.println("test");
        }
    }

    可以直接通过@AutoWired注解使用

        @Autowired
        private ImportBean importBean;
    Please call me JiangYouDang!
  • 相关阅读:
    C#:字符串(转载9)
    C# 数组(转载8)
    C#:可空类型(转载7)
    XD 05
    eclipse 快捷键 干货
    XD 04
    XD 03
    model, mapper, xml
    02 MyBatis & Druid
    注解 用到
  • 原文地址:https://www.cnblogs.com/luckygxf/p/15417719.html
Copyright © 2011-2022 走看看