【发布时间】:2014-03-03 06:26:33
【问题描述】:
我正在尝试将 Guice 与 Shiro 集成。我正在拉入最新的 Shiro JAR:
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-guice</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.2.2</version>
</dependency>
我无法编译Shiro documentation 中提供的代码。
class MyShiroModule extends ShiroModule {
protected void configureShiro() {
try {
// compile time error is shown with error message:
// "Method toConstructor is undefined in type LinkedBindingBuilder".
bindRealm().toConstructor(IniRealm.class.getConstructor(Ini.class));
} catch (NoSuchMethodException e) {
addError(e);
}
}
@Provides
Ini loadShiroIni() {
return Ini.fromResourcePath("classpath:shiro.ini");
}
}
似乎存在一些 JAR 版本控制问题。
第一个问题
编译此代码的适当 Maven 配置是什么?
第二个问题
我总是遇到这种类型的版本问题,并在网上搜索正确的版本。或者在程序的另一次运行上使用一个版本并确认程序运行。有没有办法克服这种类型的版本问题,使一个 JAR 版本与每个版本兼容?
【问题讨论】:
-
你的 POM 的其余部分是什么样的?你确定你的类路径中有正确版本的 Guice 吗?
LinkedBindingBuilder在 Guice 罐子里,而不是 Shiro 罐子里。