【问题标题】:Apache Shiro Programmatic ConfigurationApache Shiro 编程配置
【发布时间】:2019-06-29 19:20:28
【问题描述】:

我想使用 Shiro 编程配置并保留 shiro.ini 文件来配置我的应用程序(已经可以在 Shiro 上正常工作)。

我用的是官方教程here

这是我实现的代码:

    Realm realm = new AuthAuthRealmFactory();
    org.apache.shiro.mgt.SecurityManager securityManager = new DefaultSecurityManager(realm);

    //Make the SecurityManager instance available to the entire application via static memory: 
    SecurityUtils.setSecurityManager(securityManager);     

问题是当我删除 shiro.ini 文件时,我遇到了这个异常:

> org.apache.shiro.web.env.IniWebEnvironment               - Checking
> any specified config locations.                                       
> -   org.apache.shiro.web.env.IniWebEnvironment               - No INI instance or config locations specified.  Trying default config
> locations.                     -   org.apache.shiro.io.ResourceUtils  
> - Opening resource from class path [shiro.ini]                                                         -   org.apache.shiro.util.ClassUtils                         - Resource [shiro.ini] was not found via the thread context ClassLoader.
> Trying the current ClassLoader... -   org.apache.shiro.util.ClassUtils
> - Resource [shiro.ini] was not found via the current class loader.  Trying the system/application ClassLoader... -  
> org.apache.shiro.util.ClassUtils                         - Resource
> [shiro.ini] was not found via the thread context, current, or
> system/application ClassLoaders.  All heuristics have been exhausted. 
> Returning null. -   org.apache.shiro.web.env.IniWebEnvironment        
> - Unable to load optional path 'classpath:shiro.ini'.
> - java.io.IOException: Resource [classpath:shiro.ini] could not be found.

谢谢

【问题讨论】:

    标签: java apache ini shiro


    【解决方案1】:

    如果您使用 Shiro 的 servlet 插件(片段): https://github.com/apache/shiro/blob/master/support/servlet-plugin/src/main/resources/META-INF/web-fragment.xml

    您需要直接配置 Shiro(您的 web.xml 或等效文件)并确保未加载默认 impl。如果您分享更多关于您的应用的信息(它是什么类型,您如何尝试配置 Shiro,我猜我们可以更直接地帮助您)

    【讨论】:

    • 感谢布赖恩,抱歉回复晚了。你说得对,我错过了不加载默认 impl!
    猜你喜欢
    • 2016-09-28
    • 2017-01-22
    • 2015-11-19
    • 2011-08-18
    • 2017-02-01
    • 2017-01-16
    • 2014-06-15
    • 2018-09-03
    • 2020-05-30
    相关资源
    最近更新 更多