You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
767 B

package com.ssm.di.xml;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDI {
public static void main(String[] args) {
// 1. 加载 src 下的 bean-di-xml.xml
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-di-xml.xml");
// 2. 获取 Product 并输出
Product product = ac.getBean("product", Product.class);
System.out.println("===== 商品信息 =====");
System.out.println(product);
// 3. 获取 Category 并输出
Category category = ac.getBean("category", Category.class);
System.out.println("\n===== 分类信息 =====");
System.out.println(category);
}
}