| Author |
Initialization through Spring
|
Saptarshi Chakraborty
Greenhorn
Joined: Jul 26, 2007
Posts: 23
|
|
Hi All,
I am new in Spring framework. I want to initialize a process using spring framework.
Typically this can be done by overriding init() method in servlet and making the <load-on-startup>1</load-on-startup> in web.xml .I want to use spring as it provides DI features through which I can initialize the dependent objects in time of initialization.
Please guide me how this can be done by using spring. What should be the servlet class in web.xml.
|
 |
Rajkamal Pillai
Ranch Hand
Joined: Mar 02, 2005
Posts: 434
|
|
Try this:-
<beans>
<bean id="..." class="..." init-method="..."/>
</beans>
This will call the 'init-method' method when the bean is instantiated.
Another way is to implement InitializingBean available along in the Spring framework and overload afterPropertiesSet() to perform custom initialization.
Raj.
|
 |
Saptarshi Chakraborty
Greenhorn
Joined: Jul 26, 2007
Posts: 23
|
|
Thanks Raj.
but what to write inside web.xml as <servlet-class> ?
There should be a spring servlet (like org.springframework.web.servlet.DispatcherServlet when I am using spring MVC) which will initialize the other objects through IOC.
|
 |
Saptarshi Chakraborty
Greenhorn
Joined: Jul 26, 2007
Posts: 23
|
|
Thanks Raj.
But anything to write inside web.xml as <servlet-class> (like org.springframework.web.servlet.DispatcherServlet when we use spring MVC) .
|
 |
Rajkamal Pillai
Ranch Hand
Joined: Mar 02, 2005
Posts: 434
|
|
<servlet>
<servlet-name>.....</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>.....</param-value>
</init-param>
</servlet>
|
 |
Saptarshi Chakraborty
Greenhorn
Joined: Jul 26, 2007
Posts: 23
|
|
Can I use ContextLoaderServlet instead of DispatcherServlet ?
I think ContextLoaderListener or ContextLoaderServlet should be used if I want the objects to be visible application wide.The code above will initialize objects for that specific servlet.
Am I right ?
|
 |
 |
|
|
subject: Initialization through Spring
|
|
|