| |
| | Replied By -> Sameer | I think, you can use Servlet that loads at web server start up or Filter that is invoked on every request,
to create Hibernate SessionFactory by using hibernate.cfg.xml file
and using Configuration API from Hibernate.
But remember to create SessionFactory for once, for a database and
reuse it , as it is very expensive interms of resources to create Hibernate SessionFactory.
Thanks,
Sameer. |
| | |
Commented By -> Amit | There are two ways one can load application context descriptor
XML file for Spring Framework, that are by using context Listener
or by using context loader Servlet. Remember to provide context-param as the location of the
applicationContext file as
mentioned below:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/spring-config/applicationContext.xml</param-value>
</context-param>
Spring context Listener can be configured in web.xml file of
the web application as mentioned below:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
OR
Context loader servlet from Spring Framework to be mentione d in
web.xml web application descriptor file as :
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Hope this Helps. |
| | |
Commented By -> Amit | Another API org.springframework.context.support.ClassPathXmlApplicationContext
can be used with the application context XML file along with complete path.
In onw of the example I have used ClassPathXmlApplicationContext in SessionFactoryProvider
as follows:
BeanFactory beanFactory =
new ClassPathXmlApplicationContext
("/WEB-INF/config/spring-config/applicationContext.xml");
this.sessFactory = (SessionFactory) beanFactory.getBean("mySessionFactory");
And it worked without any exception.
|
| |
|
|