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 { }
spring_JavaConfig的更多相关文章
随机推荐
- 判断一个对象是否有new
C++语言中,对象没有空和不空的概念,只有对象指针才有空和不空的概念 判断对象指针是否为空只需要和NULL常量进行比较即可 如果相等,则为空,否则不为空 另外对象虽然没有空和不空的概念,但是有有效和无 ...
- Linux上超酷的命令行扩展工具Oh My Zsh
Oh My Zsh 是一款社区驱动的命令行工具,正如它的主页上说的,Oh My Zsh 是一种生活方式.它基于 zsh 命令行,提供了主题配置,插件机制,已经内置的便捷操作.给我们一种全新的方式使用命 ...
- 并发-AQS源码分析
AQS源码分析 参考: http://www.cnblogs.com/waterystone/p/4920797.html https://blog.csdn.net/fjse51/article/d ...
- Effective C++ 条款05:了解C++编写并调用哪些函数
规则一 编译器默认操作 // 你认为 class Empty { }; // 实际上 class Empty { public: Empty() { ... } // default 构造函数 Emp ...
- jQuery的序列化元素 serialize()方法 serializeArray()方法 param()方法
当提交的表单元素较多时用serialize()方法,serialize()方法也是作用于一个jQuery的对象,它能够将DOM元素内容序列化为字符串,用于Ajax请求. serialize() 方法通 ...
- spark学习7(spark2.0集群搭建)
第一步:安装spark 将官网下载好的spark-2.0.0-bin-hadoop2.6.tgz上传到/usr/spark目录下.这里需注意的是spark和hadoop有对应版本关系 [root@sp ...
- NumPy字节交换
NumPy - 字节交换 我们已经知道,存储在计算机内存中的数据取决于 CPU 使用的架构. 它可以是小端(最小有效位存储在最小地址中)或大端(最小有效字节存储在最大地址中). numpy.ndarr ...
- Git GUI 的使用
下面,我们开始使用Git Gui 如果你想init一个本地的git仓库,到你的代码根目录下,右键选择Git Init Here 这时,你会发现在代码根目录下,生成了一个.git的隐藏属性目录. 再选择 ...
- POI使用总结
一. POI简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能.二. HSSF概况 HSSF 是H ...
- hdu 5980 Find Small A(水,模拟)
Find Small A Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...