2014-02-06 55 views
0

我正在尝试将Guice与Shiro集成。我拉在最新四郎罐子:Shiro与Guice集成

<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与每个版本兼容?

+0

你的POM的其余部分是什么样的?你确定你的类路径上有正确的Guice版本吗? 'LinkedBindingBuilder'在Guice jar中,而不是Shiro jar。 – condit

回答

0

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

相关问题