我想使用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.
谢谢
答案 0 :(得分:0)
如果您使用的是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,我想我们可以直接为您提供帮助)