Spring Ders08 - Bean Factory ve Application Context
Bu derste kısaca bean factory containerı ve application context containerı arasındaki bazı farkları ele alacağız.
Bean Factory | Application Context |
Temel containerdır. Sadece nesneler üretir ve bağımlılıkları enjekte eder. | Security, transaction, messaging gibi tüm servisleri sağlayan containerdır. |
AutoScanningi desteklemez. | AutoScaningi destekler. |
İstek süresine kadar bean üretmez. Bu beanleri gevşek yüklediği anlamına gelir. | Sadece yükleme zamanında singleton beanleri oluşturur. |
Sadece singleton ve prototype bean scopelarını destekler. | Tüm bean scopelarını destekler. |
Anotasyon tabanlı dependency injection (bağımlılık enjektesi)nı desteklemez. | Anotasyon tabanlı dependency injection (bağımlılık enjektesi)nı destekler. |
Internationalization (I18N)mesajlarını desteklemez. | Internationalization (I18N) mesajlarını destekler. |
Kaydedilmiş beanlere listener gibi eventlar yayınlayamaz. | Kaydedilmiş beanlere listener gibi eventlar yayınlayabilir. |
|
|
Main.java
package test; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { BeanFactory beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml"); Test t=(Test)beanFactory.getBean("t"); t.yazdir(); } }
Test.java
package test; public class Test { private String ad; public Test(){} public String getAd() { return ad; } public void setAd(String ad) { this.ad = ad; } public void yazdir(){ System.out.println("Ad\t:\t"+ad); } }
applicationContext.xml
<?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="t" class="test.Test"> <property name="ad" value="enes" /> </bean> </beans>
Yorumlar
Yorum Gönder