File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Initialization through Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Initialization through Spring" Watch "Initialization through Spring" New topic
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: 443
    
    1

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: 443
    
    1

<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 ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Initialization through Spring
 
Similar Threads
Declarative Usage of Application Contexts
How to disallow directory browsing on web server
load-on-startup
how to deploy servlet at startup
Deploy struts app