Car 类 public class Car { private String brand; private String corp; private double price; private int maxSpend; get set方法.... @Override public String toString() { return "Car [brand=" + brand + ", corp=" + corp + ", price=" + price + ", maxSpend=" + maxSpend + "]"; } } bean配置 <bean id="car" class="com.wzq.spring.bears.collection.Car"> <property name="brand" value="Audi" ></<property > <property name="corp" value="Shanghai"></<property > <property name="price" value="30000"></<property > <property name="maxSpend" value="300"></<property > </bean> main方法 public class Mian { public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext( "applicationContext.xml"); Car car = (Car) ctx.getBean("car"); System.out.println(car); } }
|
|