我尝试从位于某个 URL 的网络服务器读取数据。
在我们公司,我使用电子商务 API,它处理来自网络服务器的数据。
要首先检索数据,我需要从网络服务器中收集数据。
为了创建数据池,我需要配置连接。
步骤“我需要配置连接”的一部分是函数 getSession(),它使用 Shiro api(org.apache.shiro.SecurityUtils) 因此,每次当我尝试与 Web 服务器建立连接并使用来自 Web 服务器的数据时,我都会出现异常“线程“主”中的异常 org.apache.shiro.UnavailableSecurityManagerException:调用代码也无法访问 SecurityManager”绑定(bind)到 org.apache.shiro.util.ThreadContext 或作为 vm 静态单例。这是无效的应用程序配置。”
在写这个问题之前,我尝试查看日志并阅读其中描述的类和问题。
这一切都在 Windows 10、Java 8、Payara Server(Glassfish) 上运行,带有 EJBAPI 和一些电子商务 API。
我使用的导入
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.InvalidSessionException;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
在
ContentConfiguration conf = new ContentConfiguration(
getSessionId(),
Constant.ENTITYMODELL,
Constant.EMPTY,
context);
protected static Session getSession()
{
Subject subject = SecurityUtils.getSubject();
if(subject.isAuthenticated())
return subject.getSession();
else
return null;
}
错误信息
Exception in thread "main" org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)
at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
at de.kolb.demo.data.ServiceLocator.getSessionId(ServiceLocator.java:15)
at de.kolb.demo.logic.CommonTest.getCommonData(CommonTest.java:32)
at de.kolb.demo.presentation.ContentDirector.main(ContentDirector.java:34)
最佳答案
我想得到代表我公司情况的答案,但是有很多原则,我将描述这些原则与 Shiro hub 中的常见问题有关。
1.我的问题与 getSessionId()
连接enter image description here
2. getSessionId()
这是来自公司 API 的函数。在这个函数中我调用 org.apache.shiro.SecurityUtils.getSubject()
enter
link description here
此时我想到了异常消息
No SecurityManager accessible to the calling code...
。我在这里查看 Shiro 文档 enter link description here 。我发现,每次使用使用身份验证和自动授权的应用程序时,我都需要使用“Realm”对象配置“SecurityManager”。4.这是shiro网站上的小指令和详细指令enter link description here
关于java - 如何使用 "org.apache.shiro.UnavailableSecurityManagerException"修复 "SecurityUtils.getSubject()"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56166460/