zoukankan      html  css  js  c++  java
  • springboot的@Configuration

    作用:替代以前的applicationContext.xml文件,完成spring容器的初始化。

     转入:https://www.cnblogs.com/dream-flying/articles/12933519.html

    例子1@Configuration+@ComponentScan

    作用:功能类似于在applicationContext.xml文件中配置组件扫描器。在定义各级bean时,使用@Controoler,@Service,@Component等注释,就可以自动完成spring容器对Bean的装载。

    复制代码
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    
    /*
    配置器
     */
    @Configuration
    @ComponentScan("com.yrc.test4")
    public class MyConfig {
    }
    复制代码

    例子2::@Configuration+@Bean

    作用::功能类似于在applicationContext.xml文件手动注册Bean。此时在各级Bean中需要添加setter方法,

    复制代码
    @Configuration
    public class MyConfig {
        @Bean
        public FunctionService functionService() {
            return new FunctionService();
        }
    
        @Bean
        public UseFunctionService useFunctionService(FunctionService functionService) {
            UseFunctionService useFunctionService = new UseFunctionService();
            useFunctionService.setFunctionService(functionService);
            return useFunctionService;
        }
    }
    复制代码

     例子3:@Configuration+@ComponentScan+@EnableAspectJAutoProxy

    作用:实现AOP配置,@EnableAspectJAutoProxy开启自动代理

    @Configuration
    @ComponentScan("com.yrc.test6")
    @EnableAspectJAutoProxy
    public class MyConfig {
    }
  • 相关阅读:
    lr http_get访问webservice
    lr http_post请求webservice
    快速幂(fast power)
    运算符重载
    1010 Radix 二分
    1054 The Dominant Color
    1042 Shuffling Machine
    1059 Prime Factors
    1061 Dating
    1078 Hashing
  • 原文地址:https://www.cnblogs.com/james641/p/14236811.html
Copyright © 2011-2022 走看看