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!
  • 相关阅读:
    Mysql索引优化分析
    mysql学习
    linux安装mysql
    MVC实例应用模式
    模型-视图-控制器MVC模式
    设计模式理解
    XX系统质量属性战术
    XX系统可用性易用性
    属性常见属性场景
    架构漫谈读后感
  • 原文地址:https://www.cnblogs.com/luckygxf/p/15417719.html
Copyright © 2011-2022 走看看