com.sky.HibakeSeoBootApplication.java Source code

Java tutorial

Introduction

Here is the source code for com.sky.HibakeSeoBootApplication.java

Source

/*
 * Copyright (c) 2015 Sfkj Science And Technology Co.,Ltd.
 * All Rights Reserved.
 * This software is the confidential and proprietary information of
 * Sfkj Science And Technology Co.,Ltd.
 * ("Confidential Information").You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sfkj.
 */
package com.sky;

import com.sky.filter.CustomSEOFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletException;

@Slf4j
@SpringBootApplication
public class HibakeSeoBootApplication extends SpringBootServletInitializer {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(HibakeSeoBootApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
        log.info(application.toString());

        return application.sources(HibakeSeoBootApplication.class);
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        log.info(" prerenderFilter ");
        //servletContext.addFilter("prerenderFilter", PrerenderFilter.class);
        servletContext.addFilter("seoFilter", CustomSEOFilter.class);
        WebApplicationContext rootAppContext = createRootApplicationContext(servletContext);
        if (rootAppContext != null) {
            servletContext.addListener(new ContextLoaderListener(rootAppContext) {
                @Override
                public void contextInitialized(ServletContextEvent event) {
                    // no-op because the application context is already initialized
                }
            });
        } else {
            this.logger.debug("No ContextLoaderListener registered, as " + "createRootApplicationContext() did not "
                    + "return an application context");
        }

    }
}