|
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的人。 |
![]() |
DrunkOnBytes · Jersey 2-请求范围绑定与单例绑定 7 年前 |
![]() |
StackUser · 为什么不执行LoggingFilter? 7 年前 |
![]() |
GLMills · 身份验证AWS方法Rest DSL 7 年前 |
![]() |
BCartolo · 如何使用实例PathParam创建对象 7 年前 |
![]() |
Vitor Ferreira · 从JSON文档中检索三个元素 7 年前 |
![]() |
newdev · AngularJS:用户可以注册两次,如何防止? 7 年前 |
![]() |
arsis-dev · 定义地图的清晰响应<字符串,字符串> 7 年前 |