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的更多相关文章
随机推荐
- discuz对PHP7不支持mysql的兼容性处理
PHP7 废除了 ”mysql.dll” ,推荐使用 mysqli 或者 pdo_mysql,discuz对原生mysql函数做了如下处理,通过mysqli代替原mysql函数 http://blog ...
- Spring_使用 JdbcTemplate和JdbcDaoSupport
- 关于阿里云Symantec免费DV证书部署HTTPS
获取阿里云Symantec免费DV证书: 官方文件说明: 证书文件214188487290026.pem,包含两段内容,请不要删除任何一段内容. 如果是证书系统创建的CSR,还包含:证书私钥文件214 ...
- Python基础笔记系列四:工具的安装与配置
本系列教程供个人学习笔记使用,如果您要浏览可能需要其它编程语言基础(如C语言),why?因为我写得烂啊,只有我自己看得懂!! 一开始是没有打算写工具这篇的,后来发现在某些情况下会遇到一些奇怪的问题,这 ...
- BZOJ 1185 [HNOI2007]最小矩形覆盖:凸包 + 旋转卡壳
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 题意: 给出二维平面上的n个点,问你将所有点覆盖的最小矩形面积. 题解: 先找出凸 ...
- 在oracle中插入数据报错:ORA-00984列在此处不允许
这里报错的原因就是当数据类型varchar2时没有使用单引号. 没写单引号,不管是双引号还是什么都没写都会报这个错误.
- DatePicker日期与时间控件
DatePicker日期与时间控件 一.简介 二.方法 最日常的使用方法了 日期控件DatePicker 时间控件TimePicker 月份从0开始 三.代码实例 效果图: 代码: fry.Activ ...
- 绝对布局absoluteLayout
绝对布局absoluteLayout 一.简介 二.实例 绝对布局我们是指定的横纵坐标,所以可以这样直接拖 绝对布局实际中用的少
- selenium学习笔记(selenium IDE下载安装)
今天自己一直在瞎捣鼓 最后这里整理下 selenium IDE 这个录制工具的下载安装 首先这个工具只支持火狐浏览器firefox.使用火狐浏览器进入selenium官网: http://www.se ...
- Jexus部署Asp.Net Core项目
在之前的我的博客项目中,我将.net Core发布到Cent OS 上,使用的Nginx代理以及Supervisor进程守护,看过我的博客的童鞋,也会发现,这种方式比较麻烦,光命令行就看的头大,总共部 ...