Seam是如何启动的

2024-03-05 11:48
文章标签 启动 seam

本文主要是介绍Seam是如何启动的,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

开发Seam应用,需要了解JSF生命周期、Seam生命周期和它(Seam)通过phase listener在JSF生命周期上扩展了哪些东西。
(这里省略一些无关紧要的...)

“web应用,启动代码可以写在ServletContextListener里。这些代码、是一系列的事件监听器,在应用初始化之后(在处理请求之前)和销毁之前被调用”

Seam 2.1.2的org.jboss.seam.servlet.SeamListener代码如下:

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.jboss.seam.Seam;
import org.jboss.seam.contexts.ServletLifecycle;
import org.jboss.seam.init.Initialization;
import org.jboss.seam.jmx.JBossClusterMonitor;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;

/**
* Drives certain Seam functionality such as initialization and cleanup
* of application and session contexts from the web application lifecycle.
*
* @author Gavin King
*/
public class SeamListener implements ServletContextListener, HttpSessionListener
{
private static final LogProvider log = Logging.getLogProvider(ServletContextListener.class);

public void contextInitialized(ServletContextEvent event)
{
log.info( "Welcome to Seam " + Seam.getVersion() );
event.getServletContext().setAttribute( Seam.VERSION, Seam.getVersion() );
ServletLifecycle.beginApplication( event.getServletContext() );
new Initialization( event.getServletContext() ).create().init();
}

public void contextDestroyed(ServletContextEvent event)
{
ServletLifecycle.endApplication();
}

public void sessionCreated(HttpSessionEvent event)
{
ServletLifecycle.beginSession( event.getSession() );
}

public void sessionDestroyed(HttpSessionEvent event)
{
JBossClusterMonitor monitor = JBossClusterMonitor.getInstance(event.getSession().getServletContext());
if (monitor != null && monitor.failover())
{
// If application is unfarmed or all nodes shutdown simultaneously, cluster cache may still fail to retrieve SFSBs to destroy
log.debug("Detected fail-over, not destroying session context");
}
else
{
ServletLifecycle.endSession( event.getSession() );
}
}

}

SeamListener实现了ServletContextListener接口.

ServletContextListener参考:
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletContextListener.html

所以你只需要实现ServletContextListener并把作如下配置:

<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>

当应用程序初始化时,contextInitialized()方法会被servlet容器调用,这就是seam如何做到,每次当你部署seam应用到servlet或JEE服务器的时候启动。

下面是一篇相关的关于JSF生命周期和phase listener的实现的文章(高度推荐)。

http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

这篇关于Seam是如何启动的的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/776402

相关文章

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

Spring Boot项目如何使用外部application.yml配置文件启动JAR包

《SpringBoot项目如何使用外部application.yml配置文件启动JAR包》文章介绍了SpringBoot项目通过指定外部application.yml配置文件启动JAR包的方法,包括... 目录Spring Boot项目中使用外部application.yml配置文件启动JAR包一、基本原理

解决若依微服务框架启动报错的问题

《解决若依微服务框架启动报错的问题》Invalidboundstatement错误通常由MyBatis映射文件未正确加载或Nacos配置未读取导致,需检查XML的namespace与方法ID是否匹配,... 目录ruoyi-system模块报错报错详情nacos文件目录总结ruoyi-systnGLNYpe

解决hive启动时java.net.ConnectException:拒绝连接的问题

《解决hive启动时java.net.ConnectException:拒绝连接的问题》Hadoop集群连接被拒,需检查集群是否启动、关闭防火墙/SELinux、确认安全模式退出,若问题仍存,查看日志... 目录错误发生原因解决方式1.关闭防火墙2.关闭selinux3.启动集群4.检查集群是否正常启动5.

Springboot项目启动失败提示找不到dao类的解决

《Springboot项目启动失败提示找不到dao类的解决》SpringBoot启动失败,因ProductServiceImpl未正确注入ProductDao,原因:Dao未注册为Bean,解决:在启... 目录错误描述原因解决方法总结***************************APPLICA编

kkFileView启动报错:报错2003端口占用的问题及解决

《kkFileView启动报错:报错2003端口占用的问题及解决》kkFileView启动报错因office组件2003端口未关闭,解决:查杀占用端口的进程,终止Java进程,使用shutdown.s... 目录原因解决总结kkFileViewjavascript启动报错启动office组件失败,请检查of

Linux下在线安装启动VNC教程

《Linux下在线安装启动VNC教程》本文指导在CentOS7上在线安装VNC,包含安装、配置密码、启动/停止、清理重启步骤及注意事项,强调需安装VNC桌面以避免黑屏,并解决端口冲突和目录权限问题... 目录描述安装VNC安装 VNC 桌面可能遇到的问题总结描js述linux中的VNC就类似于Window

linux下shell脚本启动jar包实现过程

《linux下shell脚本启动jar包实现过程》确保APP_NAME和LOG_FILE位于目录内,首次启动前需手动创建log文件夹,否则报错,此为个人经验,供参考,欢迎支持脚本之家... 目录linux下shell脚本启动jar包样例1样例2总结linux下shell脚本启动jar包样例1#!/bin

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx