I work with Spring in the Swing application, the application is divided into two main parts:
1. Authorization
2. Application

The authorization and the application are loaded in the same Spring context, but the problem is that the loading of the application's bins must be initialized after authorization, since the authorization is used to get the user id.
How to do it correctly so that the authorization is loaded first, the user is authorized, and then the main application is loaded in the same context.
Or use different contexts?

Thank you in advance.

    1 answer 1

    You can make the initialization of some bins lazy by marking them with @Lazy annotation in the code or @Lazy the lazy-init="true" parameter in the configuration. Then initialization will be delayed until the first call to the bean.

    • the fact is that I used to implement Autowired, and after that the object is wrapped in Proxy and is not brought to the class I need. And since the application classes are overwhelming, I think it's wrong to make them Lazy. Maybe it makes sense to remove Spring from authorization and only after authorization already load the context and initialize the beans? - ezhov_da
    • That you know better. But yes, nothing prevents initialization of the context later. - Sergey Gornostaev
    • Thank you, I will consider this option in more detail. - ezhov_da