好的,这是我的会话bean.我总是可以从任何Servlet或Filter中检索currentUser.这不是问题问题是fileList和currentFile.我用简单的int和Strings进行了测试,并且它的效果相同.如果我从视图范围bean中设置一个值,我可以从另一个类中获取数据.
@ManagedBean(name = "userSessionBean")
@SessionScoped
public class UserSessionBean implements Serializable, HttpSessionBindingListener {
final Logger logger = LoggerFactory.getLogger(UserSessionBean.class);
@Inject
private User currentUser;
@EJB
UserService userService;
private List<File> fileList;
private File currentFile;
public UserSessionBean() {
fileList = new ArrayList<File>();
currentFile = new File("");
}
@PostConstruct
public void onLoad() {
Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
String email = principal.getName();
if (email != null) {
currentUser = userService.findUserbyEmail(email);
} else {
logger.error("Couldn't find user information from login!");
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个例子.
我的观点是scoped bean.这就是它的装饰方式.
@ManagedBean
@ViewScoped
public …Run Code Online (Sandbox Code Playgroud) 以下情况可能吗?
"SessionService"是一个无状态EJB,它触发一个事件"LoggedInEvent".调用具有观察LoggedInEvent的非静态方法的SessionScoped(Weld)bean"SessionBean",并为该特定用户初始化一些内容.
是否调用了"SessionBean"的正确实例?所有实例都被调用了?我在文档中找不到任何内容.
我正在使用RestEasy 3.0.2,它是最早的JAX-RS 2实现之一,并在Tomcat 7中运行我的应用程序.我还通过WELD在我的应用程序中使用注入,WELD通过其CDI适配器与RestEasy集成.到目前为止一切正常.
现在,我编写了一个ContainerRequestFilter的实现,以在传入请求到达资源之前对其进行身份验证.JAX-RS标准表示可以为每个资源以及使用@Provider注释注释的每个其他JAX-RS组件进行注入.
以下是我的过滤器实现的简化版本:
@Provider
@Priority(Priorities.AUTHENTICATION)
public class AuthenticationFilter implements ContainerRequestFilter {
@Inject
AuthenticationProvider authenticationProvider;
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
authenticationProvider.authenticate(requestContext);
}
}
Run Code Online (Sandbox Code Playgroud)
注意:AuthenticationProvider是@RequestScoped.
通常,此解决方案有效.正在注入组件并按预期处理请求.
但我仍然怀疑过滤器的生活范围.如果它是应用程序作用域,那么这显然会导致"有趣"的并发问题,这些问题在确定性测试中无法找到.
我已经查看了各种文档,指南和示例,但我发现没有使用过滤器注入或者说过滤器范围.
我是Agorava的技术主管,Agorava是一个帮助消费社交网络数据的框架.
今天,Agorava基于CDI构建,以简化其在Java EE堆栈中的使用,但我们希望为Dagger提供一个实现,以便为Android提供更轻松的解决方案.
我的问题是:我们可以在CDI和Dagger实现之间共享通用的JSR 330兼容代码吗?换句话说,是否有可能与匕首在罐子轴承JSR 330注释已经编译代码和源代码延伸或在一个特定匕首罐使用此代码(与@Provides,@Modules和其他匕首特定项目)?
如果答案是否,是否有任何问题用Dagger编译器编译我的常见JSR 330 jar并在我的CDI实现中使用它?更准确地说@Inject,限定符和其他JSR 330细节仍然可以在运行时使用,带有这些注释代码的类是否仍然不受Dagger编译器的影响?最后是否有一种关于Dagger生成的代码(类名,注释)的跟踪器,以允许CDI检测它并忽略它?
我有以下服务:
@Singleton
@Startup
public class VideoFeedService {
@Inject
private Logger logger;
@PostConstruct
public void start() {
//do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
我在哪里注入从这个类产生的记录器:
public class Resources {
@Produces
public Logger produceLog(InjectionPoint injectionPoint) {
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass()
.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
我在部署时遇到以下异常:
10:21:45,789 INFO [org.jboss.as.controller] (management-handler-thread - 2) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.deployment.unit."videofeed.ws.war".WeldBootstrapService (missing) dependents: [service jboss.deployment.unit."videofeed.ws.war".component."org.jboss.weld.servlet.WeldTerminalListener".WeldInstantiator, service jboss.deployment.unit."videofeed.ws.war".component."com.sun.faces.config.ConfigureListener".WeldInstantiator, service jboss.deployment.unit."videofeed.ws.war".CdiValidatorFactoryService, service jboss.deployment.unit."videofeed.ws.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".WeldInstantiator, JBAS014799: ... and 8 more ]
service jboss.deployment.unit."videofeed.ws.war".WeldStartService (missing) dependents: [service jboss.deployment.unit."videofeed.ws.war".component."com.sun.faces.config.ConfigureListener".WeldInstantiator, service jboss.deployment.unit."videofeed.ws.war".CdiValidatorFactoryService, service jboss.deployment.unit."videofeed.ws.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".WeldInstantiator, service …Run Code Online (Sandbox Code Playgroud) 我有三个类定义如下.
class A {
}
class B extends A{
}
class C extends A{
}
class D{
//Inject class A
}
Run Code Online (Sandbox Code Playgroud)
我正在D类中注入A类.CDI正在抛出不明确的解决方案异常.解决这个问题的正确方法是什么?感谢您的帮助.
当豆子是POJO时,Weld说"Foo类型的依赖性不满意"是什么意思,但是,只要我@Dependent在顶部添加,一切正常?我记得它曾经很好地工作而没有指定范围.我想我弄坏了什么.
规格说:
托管bean由Java类实现,该类称为bean类.如果顶级Java类被任何其他Java EE技术规范(例如JavaServer Faces技术规范)定义为托管bean,或者满足以下所有条件,则它是托管bean.
它不是一个非静态的内部阶级.
它是一个具体的类或注释@Decorator.
它没有使用EJB组件定义注释或在ejb-jar.xml中声明为EJB bean类.
它有一个合适的构造函数.也就是说,以下之一就是这种情况.
该类有一个没有参数的构造函数.
该类声明了一个注释为@Inject的构造函数.
定义托管bean不需要特殊声明(例如注释).
我有带CDI bean的WAR包.部署包非常慢,因为每次部署期间都会扫描包以查找CDI bean.有没有选项可以禁用此过程?
鉴于以下课程
private static class ProducedInSubClass {
}
private static class ProducedInSuperClass {
}
public static class SuperClass {
@Produces
public ProducedInSuperClass producedInSuperClass = new ProducedInSuperClass();
}
public static class SubClass extends SuperClass {
@Produces
ProducedInSubClass producedInSubClass = new ProducedInSubClass();
}
public static class BeanWithSubClass {
@Inject
SubClass subClass;
@Inject
ProducedInSuperClass producedInSuperClass;
@Inject
ProducedInSubClass producedInSubClass;
}
Run Code Online (Sandbox Code Playgroud)
ProducedInSuperClass的注入仍然不满意.这与CDI-Spec第4.2章一致,我知道.
为了使这项工作,我需要扩展SubClass
@Produces
ProducedInSuperClass producedInSuperClassInSubClass = producedInSuperClass;
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释一下吗?为什么Injects,Annotations Interceptors ...继承但不是生产者?
我有一个豆:
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
...
@Named
@ViewScoped
public class SimpleBean implements Serializable
{
private static final long serialVersionUID = 1L;
@Inject
protected FacesContext facesContext;
...
}
Run Code Online (Sandbox Code Playgroud)
根据
https://arjan-tijms.omnifaces.org/p/jsf-23.html#1316
这应该与2.3一起工作...
部署到Wildfly 14时,结果是:
13:02:33,516 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 72) HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
13:02:33,563 INFO [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 72) Envers integration enabled? : true
13:02:34,344 INFO [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (ServerService Thread Pool -- 72) HHH000397: Using ASTQueryTranslatorFactory
13:02:34,531 WARN [org.jboss.weld.Bootstrap] (MSC service thread 1-1) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class …Run Code Online (Sandbox Code Playgroud)