0

アプリケーションの起動時にServletContextからサーバーURL(例:http://www.mywebapp.com/myapp )を取得しようとしています。これは、起動時にBeanメソッドを呼び出して(@Startupを使用して)取得します。サーブレットコンテキスト、

@Startup
@Name("startupActions")
@Scope(ScopeType.APPLICATION)
public class StartupActionsBean implements StartupActions,
Serializable {

@Logger private Log log;

/**
 * 
 */
private static final long serialVersionUID = 1L;

@Create
@Override
public void create(){
    ServletContext sc = org.jboss.seam.contexts.ServletLifecycle.getServletContext();
    String context = sc.getContextPath();
    String serverInfo = sc.getServerInfo();
    log.debug("__________________START__________________");
    log.debug("Context Path: "+context);
    log.debug("Server Info: "+serverInfo);
}

// Cleanup methods
@Remove
@BypassInterceptors
@Override
public void cleanUp(){}
}

これは問題なく動作しますが、ServletContextパスは空白です。以下のコンソール出力を参照してください。

18:52:54,165 DEBUG [uk.co.app.actions.startup.StartupActionsBean] __________________START__________________
18:52:54,165 DEBUG [uk.co.app.actions.startup.StartupActionsBean] Context Path: 
18:52:54,165 DEBUG [uk.co.app.actions.startup.StartupActionsBean] Server Info: JBoss Web/3.0.0-CR1

これや他の手段でコンテキストパスを取得する方法を知っている人はいますか?

ps。SEAM 2.2.2、Jboss AS6 Final、Richfaces3.3.3を使用

4

2 に答える 2

1

を使用しない@Startupでください。コンテキストが完全にセットアップされ、他のいくつかのファクトリがまだ初期化できなかった前に、コンポーネントの起動コードが呼び出されます。

org.jboss.seam.postInitializationイベントを観察し、同じものを使用してServletLifecycle.getCurrentServletContext()必要なデータを取得します。簡単な例:

@Name("contextPath")
public class ContextPathInit implements Serializable {
    private String contextPath;

    @Observer("org.jboss.seam.postInitialization")
    public void init() {
        contextPath = ServletLifecycle.getCurrentServletContext().getContextPath();
    }
}
于 2012-09-24T23:18:19.733 に答える
0

getContextNameメソッドを使用してExternalContextから取得しようとしましたか?

FacesContext.getCurrentInstance().getExternalContext().getContextName()
于 2012-09-23T18:25:27.120 に答える