com.mycompany.hcsparta_web.StartListener.java Source code

Java tutorial

Introduction

Here is the source code for com.mycompany.hcsparta_web.StartListener.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.hcsparta_web;

import com.mycompany.parcinghtml.MatchManagerImpl;
import com.mycompany.parcinghtml.PlayerManager;
import com.mycompany.parcinghtml.PlayerManagerImpl;
import com.mycompany.parcinghtml.SpringConfig;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 *
 * @author Branislav Smik <xsmik @fi.muni>
 */
@WebListener
public class StartListener implements ServletContextListener {

    final static Logger log = LoggerFactory.getLogger(StartListener.class);

    @Override
    public void contextInitialized(ServletContextEvent ev) {
        log.info("webov aplikace inicializovna");
        ServletContext servletContext = ev.getServletContext();
        ApplicationContext springContext = new AnnotationConfigApplicationContext(SpringConfig.class);

        servletContext.setAttribute("playerManager",
                springContext.getBean("playerManager", PlayerManagerImpl.class));
        PlayerManagerImpl pl = (PlayerManagerImpl) servletContext.getAttribute("playerManager");
        pl.initFunction();

        servletContext.setAttribute("matchManager", springContext.getBean("matchManager", MatchManagerImpl.class));

        log.info("vytvoeny manaery");

    }

    @Override
    public void contextDestroyed(ServletContextEvent ev) {
        log.info("aplikace kon?");
    }

}