package com.basicspring.basicapp;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Config {
@Bean
public Dependency dependency(){
System.out.println("In dependency");
return new Dependency();
}
@Bean
public DependencyContainer dependencyContainer(){
System.out.println("In dependencyContainer");
dependency();
dependency();
dependency();
return new DependencyContainer(dependency());
}
}
Вывод:
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify: none and -no verify were deprecated in JDK 13 and will likely be removed in a future release.
22:00:36.567 [main] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7276c8cd
22:00:36.601 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
22:00:36.759 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor'
22:00:36.762 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
22:00:36.765 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
22:00:36.766 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
22:00:36.778 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'config'
22:00:36.798 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'dependency'
In dependency
22:00:36.820 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'dependencyContainer'
In dependencyContainer
22:00:36.833 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Found key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties' with value of type String
Process finished with exit code 0
Пожалуйста, обратите внимание на операторы «В зависимости» и «В dependencyContainer» в выходных данных. Даже после ручного вызова метода dependency () дважды в методе dependencyContainer () он не запускается дважды.