Wicket が従う "do-it-all-in-Java" 哲学が好きなら、Spring よりも Guice を好むかもしれません。Guice には XML 構成はありません。すべて GuiceModule
クラスを使用して行われます。
たとえば、WicketWebApplication
クラスは次のようになります。
public class SampleApplication extends WebApplication
{
@Override
protected void init()
{
addComponentInstantiationListener(
new GuiceComponentInjector(this, new GuiceModule()));
}
}
はGuiceComponentInjector
wicket-guice 拡張機能から来ています。モジュールは次のとおりです。
public class GuiceModule extends AbstractModule
{
@Override
protected void configure()
{
// Business object bindings go here.
bind(Greetings.class).to(GreetingRepository.class);
}
}
この例でGreetings
は、具象GreetingRepository
クラスによって実装されるインターフェイスです。Guice がGreetings
オブジェクトを注入する必要がある場合、依存関係を a で満たしGreetingRepository
ます。
Google App Engine 用の Wicket/Guice アプリケーションを構築する方法を示すサンプル プロジェクトをまとめました。App Engine の仕様を安全に無視して、Wicket-Guice 統合がどのように機能するかに集中できます。