2

DispatcherPortlet を使用せずに、Spring でポートレットを開発する方法はありますか? UI に他のテクノロジー、主に Vaadin を使用したいと考えています。Spring は DI などに使用されます。ポートレット側に ContextLoaderListener クラスに似たものはありますか?

4

3 に答える 3

1

Springのドキュメントを見る:次のように作成できますApplicationContext

ApplicationContext context =
    new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});

クラスパスで xml ファイルを参照する。

その後、 を呼び出して Bean を取得できますcontext.getBean("beanName")。Spring MVC は必要ありません。

于 2010-07-30T06:10:52.437 に答える
0

ノエルが与えたものよりも詳細な答えを期待していました. 多分これにはいくつかのベストプラクティスがありますか?これが私の現在の解決策です:

xml ファイルの場所を init パラメータとしてポートレットに指定します。私のinitメソッドは次のようになります

@Override
public void init(PortletConfig config) throws PortletException {
    super.init(config);
    String configLocations = config.getInitParameter("contextConfigLocation");
    ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext();
    springContext.setConfigLocation(configLocations);
    springContext.refresh();
    config.getPortletContext().setAttribute(APPLICATION_CONTEXT_ATTRIBUTE, springContext);
}

これで、必要なときにいつでも PortletContext を介して applicationContext にアクセスできるようになりました。

(ApplicationContext) portalContext.getAttribute(APPLICATION_CONTEXT_ATTRIBUTE);

APPLICATION_CONTEXT_ATTRIBUTE は、私が作成した単なる文字列定数です。私はまだより良い解決策を求めています。

于 2010-07-30T11:51:04.830 に答える
0

PortletApplicationContextUtils を使用して、Web アプリケーション コンテキストを取得できます。

ApplicationContext ctx = PortletApplicationContextUtils.getWebApplicationContext(getPortletContext());

次に、web.xml に構成を追加するだけです。

于 2011-01-28T07:43:42.710 に答える