zoukankan      html  css  js  c++  java
  • spring_JavaConfig

    从Spring 3起,JavaConfig功能已经包含在Spring核心模块,它允许开发者将bean定义和在Spring配置XML文件到Java类中。

    interface:

    package spring_config;
    
    /**
     * Created by luozhitao on 2017/8/10.
     */
    public interface hello0810 {
    
        public void printMsg(String msg);
    }

    imp:

    package spring_config;
    
    /**
     * Created by luozhitao on 2017/8/10.
     */
    public class hello0810imp implements hello0810{
        public void printMsg(String msg) {
    
            System.out.println("0810"+msg);
    
        }
    }

    使用 @Configuration 注释告诉 Spring,这是核心的 Spring 配置文件,并通过 @Bean 定义 bean。

    package spring_config;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    /**
     * Created by luozhitao on 2017/8/10.
     */
    @Configuration
    public class APPconfig {
    
        @Bean(name = "hellobean")
        public hello0810 hello(){
    
            return new hello0810imp();
        }
    }

    main:

    package spring_config;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.annotation.AnnotationConfigApplicationContext;
    
    /**
     * Created by luozhitao on 2017/8/10.
     */
    public class APP_main {
    
    
        public static void main(String [] args){
    
    
            ApplicationContext context=new AnnotationConfigApplicationContext(APPconfig.class);
    
            hello0810 ho=(hello0810)context.getBean("hellobean");
    
            ho.printMsg("spring_config");
    
    
    
    
    
        }
    
    }

     -----------------------

    使用@Import加载多个配置文件。

    package com.yiibai.config;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Import;
    
    @Configuration
    @Import({ CustomerConfig.class, SchedulerConfig.class })
    public class AppConfig {
    
    }
  • 相关阅读:
    How to load custom styles at runtime (不会翻译,只有抄了 )
    更多FMK 的还是看万一的吧
    Custom Grid Columns
    样式和说明文档
    LiveBindings --- 把对象之间的属性绑定起来
    LiveBindings如何绑定一个对象(转)
    Delphi LiveBinds组件
    记录一偏,因为我不会翻译,
    Delphi XE4 For IOS之部署问题
    Delphi XE5 android 捕获几个事件
  • 原文地址:https://www.cnblogs.com/luo-mao/p/7338009.html
Copyright © 2011-2022 走看看