spring注解开发AnnotationConfigApplicationContext的使用

来源:互联网 发布:qt html5 混合编程 编辑:程序博客网 时间:2024/05/21 09:22

spring注解开发AnnotationConfigApplicationContext的使用

使用AnnotationConfigApplicationContext可以实现基于Java的配置类加载Spring的应用上下文.避免使用application.xml进行配置。在使用spring框架进行服务端开发时,个人感觉注解配置在便捷性,和操作上都优于是使用XML进行配置;
  • 1
  • 2

很简单的接口output

public interface outPut {    public void helloworld();}
  • 1
  • 2
  • 3
  • 4

实现类

public class outPutImpl implements outPut {    public void helloworld() {        System.out.println("hellworld");    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

注解的使用 实际上我觉得这个是充当一个容器的角色

@Configurationpublic class hello {    @Bean(name = "helloworl")    public outPut impl() {        return new outPutImpl();    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

这里的重点在于不是引用ClassPathXmlApplicationContext() 这个是对xml配置spring的使用

public class Client {    public static void main(String[] args) {        ApplicationContext context = new AnnotationConfigApplicationContext(hello.class);        outPut outPut = (com.spring.lzx.interfacer.outPut) context.getBean("helloworl");        outPut.helloworld();    }}
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 大夹子图片 夹子的拼音 夹子的读音 长夹子 夹子怎么画 麻核桃夹子 夹子虫 野兽夹子 山猪夹子 螃蟹夹子 夹子肉 兔子夹子 钢丝夹子 夹子大全 画夹子 夹子英文 板夹子 衬衫夹子 u型夹子 兔夹子 黄鳝夹子 机械夹子 鸟夹子 水泥砖夹子 胡桃夹子绿宝石 胡桃夹子和绿宝石 胡桃夹子与四个王国 蒙面胡桃夹子 胡桃夹子是谁 小怪兽口塞夹子 老公喜欢用夹子夹奶 胡桃夹子和四个王国 男士夹子烫图片 胡桃夹子蒙面唱将 胡桃夹子的故事 胡桃夹子故事 男s训练女m夹子 胡桃夹子蒙面 乳夹子惩罚老婆 胡桃夹子图片 胡桃夹子哥宝宝