1

i`m going to develop a web application and I wanted to use hibernate + spring. in a standalone application, for initializing hibernate or spring we will call the factory object or etc. i mean it is the main function responsibility to create first spring or hibernate beans.

but in a web application which is based on jsp+servlets and other beans, i don`t know who is responsible to prepare spring or hibernate. what is the solution?

3 Answers 3

1

I think context listener. In web.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Sign up to request clarification or add additional context in comments.

Comments

0

If you're developing an application based on JSP + servlets (does not matter if you actually use Spring MVC), you should configure a dataSource bean and a SessionFactory bean in your Spring configuration file. Then, from within your application, you could autowire SessionFactory where it is needed, and use it to open new sessions.

Comments

0

In web applications in general, the servlet container will load a file named web.xml where you can initiate the configuration files that your web-app needs, in your case spring and hibernate config files in the context-param and listener sections.
You should configure dataSource and SessionFactory beans in your Spring configuration file.
Then, from your java classes, you should autowire the beans where they are needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.