【发布时间】:2015-12-08 02:01:37
【问题描述】:
我的 JSF 项目中有这个(现在臭名昭著)@SessionScoped bean:
@Named(value = "appointmentFormBean")
@SessionScoped
public class AppointmentFormBean implements Serializable {
@Inject
private transient AppointmentService service;
public AppointmentFormBean() {
bookedAlready = new ArrayList<>();
types = new LinkedHashMap<>(4, (float) 0.75);
}
public AppointmentService getService() {
return service;
}
public void setService(AppointmentService service) {
this.service = service;
}
...
//other fields, setters and getters
}
我有以下用于 EJB 的接口:
@Local
public interface AppointmentRepository {/**methods*/}
@Local
public interface AppointmentService {/**methods*/}
这些是 EJB(简要):
@Singleton
@InMemoryRepository
public class InMemoryAppointmentRepository implements AppointmentRepository {/**code*/}
@Stateless
@Default
public class DefaultAppointmentService implements AppointmentService {
private AppointmentRepository repository;
@Inject
public DefaultAppointmentService(@InMemoryRepository AppointmentRepository repository) {
this.repository = repository;
}
...}
在构建期间(否则会成功)我收到以下 WELD 警告:
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.jglue.cdiunit.in...receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
在运行期间我得到这个异常:
Severe: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type HttpSession with qualifiers @CdiUnitServlet
at injection point [BackedAnnotatedField] @Inject @CdiUnitServlet private org.jglue.cdiunit.ContextController.session
at org.jglue.cdiunit.ContextController.session(ContextController.java:0)
WELD-001475: The following beans match by type, but none have matching qualifiers:
- WELD%AbstractSyntheticBean%WEB-INF/lib/cdi-unit-3.1.3%HttpSession
如果您愿意,我可以打印整个堆栈。浏览 stackoverflow 和网络我发现了许多关于可能出错的理论,但不是一个适用的解决方案。有人建议该错误可能是由于 Glassfish 与 Weld 集成、Glassfish 与 Java SE 8 20 之前的集成(我使用的是 jdk-8u65-linux-x64.rpm),但后来我看到人们在运行他们的项目时遇到了类似的问题在 WildFly 上。
所以我叫你来救援:-)
ps 我的项目在这里可用:https://github.com/vasigorc/rimmaproject
【问题讨论】:
标签: glassfish cdi jboss-weld