首页>代码>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()); } }