修改网站名配置方式

This commit is contained in:
xiongxiaoyang
2019-12-28 11:46:34 +08:00
parent 8db9eb6042
commit 3986557be9
10 changed files with 46 additions and 24 deletions

View File

@ -3,6 +3,7 @@ package xyz.zinglizingli;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.TaskScheduler;
@ -13,6 +14,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@EnableCaching
@EnableScheduling
@MapperScan({"xyz.zinglizingli.*.mapper"})
@ServletComponentScan
public class BookApplication {
public static void main(String[] args) {

View File

@ -7,25 +7,35 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.support.WebApplicationContextUtils;
import xyz.zinglizingli.books.core.crawl.BaseCrawlSource;
import xyz.zinglizingli.books.core.utils.Constants;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
/**
* @author 11797
*/
@Component
@WebListener
@Slf4j
@RequiredArgsConstructor
public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
public class StartListener implements ServletContextListener {
private final BaseCrawlSource crawlSource;
@Value("${crawl.book.new.enabled}")
private String crawlEnable;
@SneakyThrows
@Value("${website.name}")
private String webSiteName;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
public void contextInitialized(ServletContextEvent servletContextEvent) {
servletContextEvent.getServletContext().setAttribute("websiteName",webSiteName);
if (!Constants.ENABLE_NEW_BOOK.equals(crawlEnable.trim())) {
log.info("程序启动");
new Thread(() -> {
@ -45,4 +55,8 @@ public class StartListener implements ApplicationListener<ContextRefreshedEvent>
}
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}

View File

@ -2,6 +2,7 @@ package xyz.zinglizingli.books.web;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@ -11,6 +12,8 @@ import xyz.zinglizingli.books.service.BookService;
import xyz.zinglizingli.common.cache.CommonCacheUtil;
import xyz.zinglizingli.books.core.config.IndexRecBooksConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@ -21,6 +24,7 @@ import java.util.Map;
@Controller
@RequestMapping
@RequiredArgsConstructor
@Slf4j
public class IndexController {