• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Initialization through Spring

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
reply
    Bookmark Topic Watch Topic
  • New Topic