首页>代码>spring通过3种写法来inject value到bean的property中。>/injectbean/src/main/java/com/javaniu/test/Main.java
package com.javaniu.test; import org.springframework.context.support.GenericXmlApplicationContext; import com.javaniu.bean.TestBean; public class Main { public static void main(String[] args) throws InterruptedException { GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.setValidating(false); context.load("classpath*:applicationContext1.xml"); context.refresh(); TestBean bean = context.getBean(TestBean.class); System.out.println("applicationContext1.xml:" + bean.getName()); context.destroy(); context = new GenericXmlApplicationContext(); context.setValidating(false); context.load("classpath*:applicationContext2.xml"); context.refresh(); bean = context.getBean(TestBean.class); System.out.println("applicationContext2.xml:" + bean.getName()); context.destroy(); context = new GenericXmlApplicationContext(); context.setValidating(false); context.load("classpath*:applicationContext3.xml"); context.refresh(); bean = context.getBean(TestBean.class); System.out.println("applicationContext3.xml:" + bean.getName()); context.destroy(); } }
最近下载更多