導入方式爲 選中包 右鍵add as libraryspring
1.application.xml代碼 app
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- bean的id沒有關係 以後ac.getBean("peo2",People.class); 的時候使用相同的名稱獲取就能夠 class是對象的全地址-->
<bean id="peo2" class="com.bjsxt.pojo.People"></bean>
</beans>
2.People類
package com.bjsxt.pojo; public class People { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "People [id=" + id + ", name=" + name + "]"; } }
3.測試類
package com.bjsxt.test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.bjsxt.pojo.People; import com.bjsxt.pojo.PeopleFactory; public class Test { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); People people = ac.getBean("peo2",People.class); System.out.println(people); } }
4.執行測試類便可完成people類註冊
以上即爲spring環境搭建ide