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的更多相关文章
随机推荐
- 强大的jQuery幻灯片播放插件 支持全拼、拖拽和下载等功能
在线演示 本地下载
- 20162326 齐力锋 2016-2017-2 《程序设计与数据结构》 MySort.java 实验博客
实验代码学习编程中的问题及解决方法 代码运行成功截图 首次代码运行出现的问题截图 问题1:无法从静态上下文中引用非静态方法 问题1解决方法及思考: split方法是非静态方法,需要借助对象来调用.我查 ...
- React Native混合开发中必须要学会点FlexBox布局
在前面的案例中,界面的搭建都是采用CSS的布局,基于盒子模型,依赖 display属性 , position属性, float属性.但对于那些特殊布局非常不方便,比如,垂直居中. 一种全新的针对web ...
- [SCOI2005]扫雷Mine
1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2028 Solved: 1187[Submit][St ...
- JZ2440裸机点亮LED【学习笔记】
平台:jz2440 作者:庄泽彬(欢迎转载,请注明作者) 说明:韦东山一期视频学习笔记 一.我们首先来做第一个实验,用汇编语言点亮板子上的LED. 1.1 LED的原理图 从下面的原理图可知LED1是 ...
- 迁移cnblog博客
title: 迁移cnblog博客 date: 2018-03-18 categories: cnblogs tags: life 写博客最怕就是这种迁来迁去的,太麻烦了 还好老早就使用markdow ...
- springboot创建多环境profile打包
springboot开发打包时,一般会有多个环境,dev,qa,prod等,配置文件大多雷同,只是方便开发切换,但是生成部署时产生的war包就无需这么多重复配置了,这时这些dev,qa的配置就不应该打 ...
- ATCODER ABC 099
ATCODER ABC 099 记录一下自己第一场AK的比赛吧...虽然还是被各种踩... 只能说ABC确实是比较容易. A 题目大意 给你一个数(1~1999),让你判断它是不是大于999. Sol ...
- hbase learning
万万没想到,促使我填坑的居然是学习HBase,之前听分享的时候知道它是一个kv型的数据库就没有多了解,现在才开始学习. hbase和bigtable很像,入门看起来也不太难#flag #下面是对于我看 ...
- GridView右键菜单
一.添加右键菜单 1.在VS工具箱中的“菜单和工具栏”找到ContextMenuStrip控件,双击添加. 2.点击ContextMenuStrip右上方的小三角形,打开编辑项,可以添加菜单项.至于菜 ...