Reputation: 11
I'm using some support data in my application and I want to load that data at the time of server start. I'm using spring context. If I would be able to load application context at the time of server start up, the problem would be solved.
Upvotes: 1
Views: 881
Reputation: 328750
Register a ServletContextListener
and fetch the bean in contextInitialized()
(see Servlet Life-Cycle Events).
This has two advantages:
Upvotes: 2
Reputation: 1109342
Not sure about the Spring part as I don't use it, but in JSF you can use an @ApplicationScoped
@ManagedBean
whose eager
attribtue is set to true
.
@ManagedBean(eager=true)
@ApplicationScoped
public class Data {
// ...
}
This will autoconstruct the managed bean on webapp's startup.
Upvotes: 2