Ste*_*eve 15
如果你喜欢Wicket遵循的"do-it-all-in-Java"理念,那么你可能更喜欢Guice而不是Spring.Guice中没有XML配置 - 它都是使用Guice Module类完成的.
例如,您的Wicket WebApplication类可能如下所示:
public class SampleApplication extends WebApplication
{
@Override
protected void init()
{
addComponentInstantiationListener(
new GuiceComponentInjector(this, new GuiceModule()));
}
}
Run Code Online (Sandbox Code Playgroud)
将GuiceComponentInjector来自小门吉斯扩展.这是模块:
public class GuiceModule extends AbstractModule
{
@Override
protected void configure()
{
// Business object bindings go here.
bind(Greetings.class).to(GreetingRepository.class);
}
}
Run Code Online (Sandbox Code Playgroud)
在此示例中,Greetings是由具体GreetingRepository类实现的接口.当Guice需要注入一个Greetings对象时,它将满足一个对象的依赖GreetingRepository.
我已经整理了一个示例项目,演示如何为Google App Engine构建Wicket/Guice应用程序.您可以安全地忽略App Engine的细节,并专注于Wicket-Guice集成的工作方式.
Spring可能会给你更大的灵活性,但如果你只需要DI,那么Guice可能是更好的选择.
很难回答,因为Spring有很多功能可以使DAO更灵活,并且与Hibernate配合得很好.如果您对所需内容有更多要求,将会有所帮助.
以下是Spring和Guice以及Spring,Guice和Picocontainer之间的几个比较.
http://code.google.com/p/google-guice/wiki/SpringComparison
http://www.christianschenk.org/blog/comparison-between-guice-picocontainer-and-spring/
| 归档时间: |
|
| 查看次数: |
5064 次 |
| 最近记录: |