|
|
1
4
我意识到这个问题已经存在了将近一年,但我最近在Shiro(注:不是GAE Shiro)和RESTEasy遇到了类似的问题,我想我会在这里发布我使用的解决方案,这样它就可以让其他遇到这个特殊问题的人受益。
问题是RESTEasy的
我决定采用的解决方案是
例如: public class MyBootstrapServletContextListener extends GuiceResteasyBootstrapServletContextListener {
@Override
protected List getModules(final ServletContext context) {
final List result = new ArrayList();
final String modulesString = context.getInitParameter("resteasy.guice.modules");
if (modulesString != null) {
final String[] moduleStrings = modulesString.trim().split(",");
for (final String moduleString : moduleStrings) {
try {
log.info("Found module: {}", moduleString);
final Class cls = Thread.currentThread().getContextClassLoader().loadClass(moduleString.trim());
final Module module = createModule(cls, context);
result.add(module);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
return result;
}
private Module createModule(Class cls, ServletContext context) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Constructor constructor = null;
try {
constructor = cls.getConstructor(ServletContext.class);
} catch (NoSuchMethodException e) {
log.info("Class {} has no constructor that takes just a ServletContext parameter; defaulting to no-args constructor.", cls);
}
return constructor == null ? (Module) cls.newInstance() : (Module) constructor.newInstance(context);
}
}
一旦这一点到位,我就改变了
同样,我意识到你可能不再需要解决方案,但我在研究Shiro的类似问题时偶然发现了这个问题,并希望能帮助其他试图在其网络应用程序中结合RESTEasy和Shiro的人。 |
|
|
bobi · 如何修复:谷歌登录按钮未经验证 2 年前 |
|
|
Jad Chahine · 谷歌应用引擎灵活环境中的日志出现错误 3 年前 |
|
|
Community wiki · 上下文中的用户和角色 3 年前 |
|
|
Pebii Root · 点击提交按钮时防止重复条目谷歌工作表 3 年前 |
|
|
Pebii · 谷歌表单防止点击提交按钮后出现重复条目 3 年前 |