【问题标题】:Shiro Integration with GuiceShiro 与 Guice 的集成
【发布时间】: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 罐子里。

标签: java guice shiro


【解决方案1】:

Shiro 包的某些类与本地 java 类具有相同的名称,请确保您正在导入正确的类。

【讨论】:

    猜你喜欢
    • 2016-12-20
    • 2014-10-29
    • 1970-01-01
    • 2015-01-01
    • 2015-05-13
    • 2013-12-11
    • 1970-01-01
    • 2014-10-13
    • 2019-04-15
    相关资源
    最近更新 更多