In one of my classes, I have the following line of code. I don't know how these objects are registered as beans with spring's application context without any auto wiring and all.
public class EmailAction<R, T> extends Action<R, T> {
private EmailService emailService = SpringContextBridge.services().getEmailService();
.
.
}
I want to know how this emailService object is created without any auto wiring
The SpringContextBridge class is as follows
@Component
@Getter
public class SpringContextBridge implements SpringContextBridgedServices, ApplicationContextAware {
private static ApplicationContext applicationContext;
@Autowired
private CoffeeAuthorizationService authorizationService;
@Autowired
private CoffeeGroupParser coffeeGroupParser;
@Autowired
private CoffeeGroupService coffeeGroupService;
@Autowired
private AppProperties appProperties;
@Autowired
private EmailService emailService;
@Autowired
private CoffeeCloudProperties coffeeCloudProperties;
@Autowired
private CoffeeUtil coffeeUtil;
@Autowired
private CoffeeRuleService coffeeRuleService;
@Autowired
private CoffeeRuleRepository coffeeRuleRepository;
@Override
public void setApplicationContext(ApplicationContext ac) throws BeansException {
applicationContext = ac;
}
/**
* A static method to lookup the SpringContextBridgedServices Bean in the
* applicationContext. It is basically an instance of itself, which was
* registered by the @Component annotation.
*
* @return the SpringContextBridgedServices, which exposes all the Spring
* services that are bridged from the Spring context.
*/
public static SpringContextBridgedServices services() {
return applicationContext.getBean(SpringContextBridgedServices.class);
}
}
You may wonder what is SpringContexxtBridgedServices. Yes That class is as follows
public interface SpringContextBridgedServices {
CoffeeAuthorizationService getAuthorizationService();
CoffeeGroupParser getCoffeeGroupParser();
CoffeeGroupService getCoffeeGroupService();
AppProperties getAppProperties();
EmailService getEmailService();
CoffeeCloudProperties getCoffeeCloudProperties();
CoffeeUtil getCoffeeUtil();
}