I want to add @Component classes to spring container after ApplicationContext load. But I cannot use BeanFactory. Because I'm using BeanFactory I have to define beans for these classes. But I cannot defined it(If I am not use reflection). Because these classes will load at runtime by ClassLoader.
For example
@Component
public class Service {
private final CustomerService customerService;
private final OrderService orderService;
private final PaymentService paymentService;
@Autowired
public Service(CustomerService customerService, OrderService orderService, PaymentService paymentService) {
this.customerService = customerService;
this.orderService = orderService;
this.paymentService = paymentService;
}
}
In this example Spring create bean for this class while application invoking. There is no need to define bean with @Bean. But what I want is compile spring projects and load those clasess from another project and add to Spring ApplicationContext. So i can autowire these. Otherwise I have to create bean with reflection at runtime. And if I use reflection, I have invoke all dependent class recursively.
Is there any way do it without create beans using reflection at runtime.