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的更多相关文章
随机推荐
- filter方法解析
filter一般用于将数组中的某些元素过滤掉,并生成一个新的数组 基本语法如下: var newArray= arrayObj.filter(functionObj); newArray 根据过滤条件 ...
- springboot学习(三)——使用HttpMessageConverter进行http序列化和反序列化
以下内容,如有问题,烦请指出,谢谢! 对象的序列化/反序列化大家应该都比较熟悉:序列化就是将object转化为可以传输的二进制,反序列化就是将二进制转化为程序内部的对象.序列化/反序列化主要体现在程序 ...
- MongoDB快速入门(十三)- 聚合count、distinct和group
1. count: --在空集合中,count返回的数量为0. > db.test.count() 0 --测试插入一个文档后count的返回值. > d ...
- Netty-SocketIO的Web推送实战应用
netty-socketio是一个开源的Socket.io服务器端的一个java的实现, 它基于Netty框架.可应用于服务端主动推送消息到客户端等场景,比如说股票价格变化.k线图的走势,和webso ...
- Spring积累
<tx:annotation-driven/> (Spring的XML配置里两大Bean的声明之一) 那我们是否就可以在程序中所有被spring管理的类(@Controller.@Ser ...
- C# word 类库基本属性介绍
using System;using System.Collections.Generic;using System.Text;using Microsoft.Office.Interop.Word; ...
- SpringMVC的HelloWorld快速入门!
1.加入JAR包: commons-logging-1.1.3.jar spring-aop-4.0.0.RELEASE.jar spring-beans-4.0.0.RELEASE.jar spri ...
- MyEclipse 为xml添加本地的dtd文件
在使用Eclipse或MyEclipse编辑XML文件的时候经常会碰到编辑器不提示的现象,这常常是因为其xml文件需要参考的DTD文件找不到,还有因为网络的问题不能及时提示而产生的.Eclipse/M ...
- Sort Colors,颜色排序
问题描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same ...
- jmeter-执行多个sql查询语句
1.添加jdbc connection(注意标红部分) 2.添加jdbc request 3.查看结果树