zoukankan      html  css  js  c++  java
  • spring注解开发AnnotationConfigApplicationContext的使用

    转自:https://www.cnblogs.com/kaituorensheng/p/8024199.html
    使用AnnotationConfigApplicationContext可以实现基于Java的配置类加载Spring的应用上下文.避免使用application.xml进行配置。在使用spring框架进行服务端开发时,个人感觉注解配置在便捷性,和操作上都优于是使用XML进行配置;

     

    很简单的接口output

    public interface outPut {
    
        public void helloworld();
    }

    实现类

    public class outPutImpl implements outPut {
    
        public void helloworld() {
            System.out.println("hellworld");
        }
    
    }

     

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

    @Configuration
    public class hello {
    
        @Bean(name = "helloworl")
        public outPut impl() {
            return new outPutImpl();
        }
    }

     

    这里的重点在于不是引用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();
        }
    }
  • 相关阅读:
    2021.Jan.11.Mon
    Samba
    nfs
    python数据类型(字典dictionary2)
    python数据类型(字典dictionary1)
    python数据类型(元祖tuple)
    python数据类型(列表List2)
    python数据类型(列表List1)
    python数据类型(字符串String2)
    python数据类型(数字Numbers)
  • 原文地址:https://www.cnblogs.com/sharpest/p/7748438.html
Copyright © 2011-2022 走看看