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

相关文章

Redis在windows环境下如何启动

《Redis在windows环境下如何启动》:本文主要介绍Redis在windows环境下如何启动的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Redis在Windows环境下启动1.在redis的安装目录下2.输入·redis-server.exe

解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'

《解决SpringBoot启动报错:Failedtoloadpropertysourcefromlocationclasspath:/application.yml问题》这篇文章主要介绍... 目录在启动SpringBoot项目时报如下错误原因可能是1.yml中语法错误2.yml文件格式是GBK总结在启动S

SpringBoot启动报错的11个高频问题排查与解决终极指南

《SpringBoot启动报错的11个高频问题排查与解决终极指南》这篇文章主要为大家详细介绍了SpringBoot启动报错的11个高频问题的排查与解决,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一... 目录1. 依赖冲突:NoSuchMethodError 的终极解法2. Bean注入失败:No qu

一文带你了解SpringBoot中启动参数的各种用法

《一文带你了解SpringBoot中启动参数的各种用法》在使用SpringBoot开发应用时,我们通常需要根据不同的环境或特定需求调整启动参数,那么,SpringBoot提供了哪些方式来配置这些启动参... 目录一、启动参数的常见传递方式二、通过命令行参数传递启动参数三、使用 application.pro

SpringBoot项目启动报错"找不到或无法加载主类"的解决方法

《SpringBoot项目启动报错找不到或无法加载主类的解决方法》在使用IntelliJIDEA开发基于SpringBoot框架的Java程序时,可能会出现找不到或无法加载主类com.example.... 目录一、问题描述二、排查过程三、解决方案一、问题描述在使用 IntelliJ IDEA 开发基于

SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法

《SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法》本文主要介绍了SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法,具有一定的参考价值,感兴趣的可以了解一下... 目录方法1:更改IDE配置方法2:在Eclipse中清理项目方法3:使用Maven命令行在开发Sprin

Nginx启动失败:端口80被占用问题的解决方案

《Nginx启动失败:端口80被占用问题的解决方案》在Linux服务器上部署Nginx时,可能会遇到Nginx启动失败的情况,尤其是错误提示bind()to0.0.0.0:80failed,这种问题通... 目录引言问题描述问题分析解决方案1. 检查占用端口 80 的进程使用 netstat 命令使用 ss

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

Windows设置nginx启动端口的方法

《Windows设置nginx启动端口的方法》在服务器配置与开发过程中,nginx作为一款高效的HTTP和反向代理服务器,被广泛应用,而在Windows系统中,合理设置nginx的启动端口,是确保其正... 目录一、为什么要设置 nginx 启动端口二、设置步骤三、常见问题及解决一、为什么要设置 nginx

springboot启动流程过程

《springboot启动流程过程》SpringBoot简化了Spring框架的使用,通过创建`SpringApplication`对象,判断应用类型并设置初始化器和监听器,在`run`方法中,读取配... 目录springboot启动流程springboot程序启动入口1.创建SpringApplicat