I found this piece of code in my codebase. Actually the class:
package my.services.config;
@Configuration
@ImportResource("classpath:spring/*.xml")
@ComponentScan("my.services.jms.server")
public class MyServicesConfiguration {
@Bean
public ApplicationLifecycle lifecycle() {
return new MyServicesLifecycle();
}
}
I’m trying to understand:
So, it uses all spring/*.xml files/beans before/while staring up, then it injects ApplicationLifecycle bean into the spring context (along with other beans from spring/*xml and from beans from ‘my.services.jms.server’ packages). So, in the end we gonna have one global context with all beans (?)
The question: How does it possible to launch this application (if, as I understand this class is only one entry point to the app) ?
It’s gonna be some main(String[] args) {} function that would able to launch it by ‘my.services.config’ path, let’s say, as an argument.
That’s right. From Spring perspective
@Configurationclass is just a different way to define beans, equivalent to XML. Both Java configuration and XML configuration is merged and treated equally later.And this is how you can start you context from withing
main():and later: