Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8039483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:35:11+00:00 2026-06-05T03:35:11+00:00

I want a method (or some functionality) to be executed after my web application

  • 0

I want a method (or some functionality) to be executed after my web application starts (context loaded). I am using spring 3.0 as framework.

I tried using ServletContextListener which I implemented in my class

my listener class

package myapp.listner;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class MyContextListner implements ServletContextListener{

    public static long appStart=0L;
    @Override
    public void contextDestroyed(ServletContextEvent arg0) {

        System.out.println("Context Destroyed");
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        appStart=System.currentTimeMillis();
        System.out.println("Context Initialised");

    }

}

and part of web.xml is

<listner>
     <listner-class>myapp.listner.MyContextListner</listner-class>
    </listner>

    <servlet>
      <servlet-name>dispatcher</servlet-name>

      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>


    <servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>/forms/*</url-pattern>
    </servlet-mapping>

but its not printing that message…..

Please help me….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:35:13+00:00Added an answer on June 5, 2026 at 3:35 am

    PostConstruct and PreDestroy annotations, something like this :

    @Configuration
    public class MyConfig{
    
        @PostConstruct
        public void contextInitialized(){
          System.out.println("Context Initialised");
        }
    
        @PreDestroy
        public void contextdestroyed(){
          System.out.println("Context Destroyed");
        }
    }
    

    You don’t have to use in configuration bean, it can be anywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML that I want to parse using the lxml method in
I'm using some functionality in Java that I don't really understand so I want
I'm recently working on a semantic web application project using Rowlex. I've reached some
I'm trying to make some ajax-functionality in my web application, but I cannot get
I want to find a method to include some files based on the current
I want to override the Tostring() method for changing some characters. Is it possible?
I want to return some errors to my jquery method. What is happening is
I'm doing some work with stats, and want to refactor the following method :
I want a method in a session scoped backing bean to be called after
I'm trying to add some functionality to our code base by using tied scalars.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.