2022-04-13

org.springframework.beans.factory.BeanFactory.getBean( ) with args

 


org.springframework.beans.factory.BeanFactory.getBean( ) with args


Source URL: https://www.programcreek.com/java-api-examples/?class=org.springframework.beans.factory.BeanFactory&method=getBean

public static void main(String[] args) {
    // 配置 XML 配置文件
    // 启动 Spring 应用上下文
    BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-instantiation-context.xml");
    User user = beanFactory.getBean("user-by-static-method", User.class);
    User userByInstanceMethod = beanFactory.getBean("user-by-instance-method", User.class);
    User userByFactoryBean = beanFactory.getBean("user-by-factory-bean", User.class);
    System.out.println(user);
    System.out.println(userByInstanceMethod);
    System.out.println(userByFactoryBean);

    System.out.println(user == userByInstanceMethod);
    System.out.println(user == userByFactoryBean);

}


Details at:







No comments:

Post a Comment