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的更多相关文章
随机推荐
- PHP memcache扩展模块安装
安装php扩展模块memcache memcache 的工作就是在专门的机器的内存里维护一张巨大的hash表,来存储经常被读写的一些数组与文件,从而极大的提高网站的运行效率,减轻后端数据库的读写压力. ...
- Oracle中对现有表增加列
altertable Tablename add(column1 varchar2(20),column2 number(7,2)...) --Oracle中修改列名不可以,但是可以删除列,增加列 a ...
- 解析WEB开发编码问题
解析WEB开发编码问题 URL: http://tcking.javaeye.com/blog/726643 在进行web开发的时候经常会遇到乱码的问题,乱码一般出现在: 1.写在jsp文件中的中文变 ...
- Asp.net Core, 基于 claims 实现权限验证 - 引导篇
什么是Claims? 这个直接阅读其他大神些的文章吧,解释得更好. 相关文章阅读: http://www.cnblogs.com/JustRun1983/p/4708176.html http://w ...
- tomcat配置访问图片路径映射到磁盘路径
首先,我在调试页面的时候发现,图片路径为: /webapps/pic_son/img/1234565456.jpg 但是,tomcat中webapps的文件夹下的pic_son项目中,img文件夹是空 ...
- Ubuntu 1210怎么获得root权限登录
Ubuntu 12.10 怎么用Root 登录?以下是Ubuntu 12.10 启用Root 登录的方法吗,希望对大家有些帮助吧! 方法如下: 1.先设定一个 Root 密码 sudo passwd ...
- 编写一个程序,将 a.txt 文件中的单词与 b.txt 文件中的单词交替合并到 c.txt 文件中,a.txt 文件中的单词用回车符分隔,b.txt 文件中用回车或空格进行分隔。
package IO; import java.io.*; public class test { public void connectWords(File file1, File file2, F ...
- numpy数组各种乘法
In [34]: a Out[34]: array([[1, 4], [5, 6]]) In [35]: b Out[35]: array([[4, 1], [2, 2]]) In [36]: np. ...
- ps切图步骤
1.复制图层到新建 2.alt + i + r 裁剪 依次按 3.ctrl + alt + shift + s 保存 裁剪图标 复制到图层 , 删除背景,并复制样式 就可以做到 背景透明.
- tflearn kears GAN官方demo代码——本质上GAN是先训练判别模型让你能够识别噪声,然后生成模型基于噪声生成数据,目标是让判别模型出错。GAN的过程就是训练这个生成模型参数!!!
GAN:通过 将 样本 特征 化 以后, 告诉 模型 哪些 样本 是 黑 哪些 是 白, 模型 通过 训练 后, 理解 了 黑白 样本 的 区别, 再输入 测试 样本 时, 模型 就可以 根据 以往 ...