首页>代码>Spring Bean的Scopes范围Singleton和Prototype说明>/spring-bean-scope-singleton/src/main/java/com/memorynotfound/spring/core/scope/Run.java
package com.memorynotfound.spring.core.scope;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Run {

    public static void main(String... args) throws InterruptedException {
        ApplicationContext context = new ClassPathXmlApplicationContext("app-config.xml");

        CoffeeMachine coffeeMachine = context.getBean(CoffeeMachine.class);
        coffeeMachine.setSerialNr(12356789);
        coffeeMachine.setName("最代码");
        System.out.println("Serial nr: " + coffeeMachine.getSerialNr() + ",name:" + coffeeMachine.getName() + ",hashCode:" + coffeeMachine.hashCode());

        coffeeMachine = context.getBean(CoffeeMachine.class);
        System.out.println("Serial nr: " + coffeeMachine.getSerialNr() + ",name:" + coffeeMachine.getName() + ",hashCode:" + coffeeMachine.hashCode());
    }
}
最近下载更多
最近浏览更多
微信网友_6040315240812544  LV8 2022年10月27日
最代码-宋家辉  LV61 2021年11月11日
xiao菜  LV2 2021年6月2日
sizeking  LV8 2021年4月12日
骑着鱼儿过海的猫  LV1 2021年2月25日
酷酷的浩浩  LV3 2021年2月23日
lris_luanling  LV11 2021年2月22日
tangang  LV4 2021年2月22日
用户名已经存在了啊  LV2 2021年2月20日
lryepoch  LV7 2021年2月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友