java 通过配置监听器(Listener)设置项目启动给LED推送数据
2017-08-18 10:50
507 查看
web.xml 配置
<listener>
<listener-class>com.***.***.listenvision.LedContextListener</listener-class>
</listener>
LedContextListener 文件
package com.***.***.listenvision;
import com.***.***.model.AttDetail;
import com.***.***.service.AttDetailService;
import com.***.***.service.FaceService;
import com.***.pay.common.exceptions.ValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class LedContextListener implements ServletContextListener{
private static Logger logger = LoggerFactory.getLogger(LedContextListener.class);
public static ResourceBundle faceSdk = PropertyResourceBundle.getBundle("face-sdk");
public static String LEDSwitch = faceSdk.getString("led.switch");
private AttDetailService attDetailService;
private FaceService faceService;
/**
* 项目启动给LED推送数据
* @param sce
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
logger.info("获取******信息推送给LED(项目启动给LED推送数据)");
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
attDetailService = webApplicationContext.getBean(AttDetailService.class);
faceService = webApplicationContext.getBean(FaceService.class);
try {
if("ON".equals(LEDSwitch)){
//获取最近一名***的信息
AttDetail attDetail = attDetailService.getLatestEmp();
if(!StringUtils.isEmpty(attDetail)){
faceService.attendanceFace(attDetail.getEmpUuid(),attDetail.getInOut().toString());
}
}
} catch (ValidationException ve) {
logger.error(ve.getMessage(), ve);
throw ve;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
<listener>
<listener-class>com.***.***.listenvision.LedContextListener</listener-class>
</listener>
LedContextListener 文件
package com.***.***.listenvision;
import com.***.***.model.AttDetail;
import com.***.***.service.AttDetailService;
import com.***.***.service.FaceService;
import com.***.pay.common.exceptions.ValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
public class LedContextListener implements ServletContextListener{
private static Logger logger = LoggerFactory.getLogger(LedContextListener.class);
public static ResourceBundle faceSdk = PropertyResourceBundle.getBundle("face-sdk");
public static String LEDSwitch = faceSdk.getString("led.switch");
private AttDetailService attDetailService;
private FaceService faceService;
/**
* 项目启动给LED推送数据
* @param sce
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
logger.info("获取******信息推送给LED(项目启动给LED推送数据)");
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
attDetailService = webApplicationContext.getBean(AttDetailService.class);
faceService = webApplicationContext.getBean(FaceService.class);
try {
if("ON".equals(LEDSwitch)){
//获取最近一名***的信息
AttDetail attDetail = attDetailService.getLatestEmp();
if(!StringUtils.isEmpty(attDetail)){
faceService.attendanceFace(attDetail.getEmpUuid(),attDetail.getInOut().toString());
}
}
} catch (ValidationException ve) {
logger.error(ve.getMessage(), ve);
throw ve;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
相关文章推荐
- java项目通过设置JVM属性参数依赖本地配置
- 【Java】在JTable中设置鼠标监听器,点击操作对应数据
- java 监听器(监听用户监听器也叫Listener,是Servlet的监听器,它可以监听客户端的请求、服务端的操作等。通过监听器,可 以自动激发一些操作,比如监听在线的用户的数量。当增加一在线人数)
- Java web项目listener Filter servlet启动顺序和配置
- Tomcat设置默认启动项目及Java Web工程设置默认启动页面
- tomcat6配置java项目启动动态加载配置文件
- 通过环境变量设置WEB项目数据源(Spring)及其项目配置文件路径,动态更新数据源及项目配置
- Tomcat设置默认启动项目及Java Web工程设置默认启动页面
- 监听器配置,java监听器,登陆监听,Listener,struts监听器配置,用户在线统计
- maven项目 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 启动maven项目报错:java.lang.ClassNotFoundException: ContextLoaderListener解决方法
- maven项目 启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 通过conf/server.xml中的context配置的web项目启动的时候没有发布情况日志信息
- Tomcat设置默认启动项目及Java Web工程设置默认启动页面
- 监听器配置,java监听器,登陆监听,Listener,struts监听器配置,用户在线统计
- Java opencsv--使用 Spring 的 PostConstruct机制,项目启动时,将CSV配置文件读取到内存 map 中
- 2、MyEclipse和Eclipse调优,MyEclipse配置(tomcat和jdk的内存设置),jar引入相关知识点,将Java项目编程web项目的办法
- spring项目中监听器作用-ContextLoaderListener(项目启动时,加载一些东西到缓存中)
- 2、MyEclipse和Eclipse调优,MyEclipse配置(tomcat和jdk的内存设置),jar引入相关知识点,将Java项目编程web项目的办法
- 【Java】在JTable中设置鼠标监听器,点击操作对应数据