18 Nisan 2019 Perşembe

SpringContext @Configurable Anotasyonu

Giriş
Kod içinde new() ile yaratılan nesneye Spring bean'lerini injekte etmek için kullanılır. Açıklaması şöyle. Bu yöntem AutowireCapableBeanFactory arayüzüne tercih edilebilir.
@Configurable is an annotation that injects dependencies into objects that are not managed by Spring using aspectj libraries. i.e., you still use old way of instantiation with plain new operator to create objects but the spring will take care of injecting the dependencies into that object automatically for you.
@EnableSpringConfigured İle İlişkisi
Bu anotasyon tanımlı olmalıdır. Ayrıca maven için pom.xml dosyasına org.springframework.boot:spring-boot-starter-aop eklenir. Açıklaması şöyle.
You need to enable load-time weaving (or other kinds of weaving) in order to use @Configurable.
Örnek
Şöyle yaparız
@Configurable
public class MyClass {
  @Autowired private AnotherClass instance
}
preConstruction Alanı
Örnek
Şöyle yaparız
@Configurable(preConstruction=true,dependencyCheck=true,autowire=Autowire.BY_TYPE)

Hiç yorum yok:

Yorum Gönder