有关创建启用CDI的shiro Realms的足够信息。就我而言,我需要在自定义shiro过滤器中使用CDI,这有可能吗?
public class com.moc.CustFilter {
@Inject
private MyUtil myUtil;
// .... using myUtil
}
shiro.ini
[main]
custFilter = com.moc.CustFilter
[urls]
/web/** = custFilter
答案 0 :(得分:0)
过滤器的构造函数中的这段代码对我来说足够了
private SomeUtils utils;
public ApisecAuthcFilter() {
try {
BeanManager beanManager = (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
Bean<SomeUtils> utilsBean = (Bean<SomeUtils>) beanManager.resolve(beanManager.getBeans(SomeUtils.class));
CreationalContext<SomeUtils> creationalContext = beanManager.createCreationalContext(null);
utils = utilsBean.create(creationalContext);
} catch (NamingException e) {
throw new SomesException();
}
}