WELD-001408:类型为HttpSession的不满意的依赖关系 [英] WELD-001408: Unsatisfied dependencies for type HttpSession

查看:289
本文介绍了WELD-001408:类型为HttpSession的不满意的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @Named(value =appointmentFormBean)在我的JSF项目中有@SessionScoped bean: )
@SessionScoped
public class AppointmentFormBean实现Serializable {



@Inject
私有瞬态AppointmentService服务;

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;



//其他字段,setters和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存储库){
this.repository = repository;
}
...}

在构建过程中)我得到这个WELD警告:

 信息:WELD-000101:交易服务不可用。注入@Inject UserTransaction不可用。事务性观察者将被同步调用。 
WARN:WELD-000411:Observer方法[BackedAnnotatedMethod] org.jglue.cdiunit.in ...接收所有注释类型的事件。考虑使用@WithAnnotations或具有边界的泛型类型限制事件。

运行期间,我得到以下异常:



<$加载应用程序时出现异常:CDI部署失败:WELD-001408:带有限定符的类型为HttpSession的不满意的依赖项@CdiUnitServlet $ b在注入点的b $ b [BackedAnnotatedField] @Inject @CdiUnitServlet private org.jglue.cdiunit.ContextController.session
at org.jglue.cdiunit.ContextController.session(ContextController.java:0)
WELD-001475:以下bean按类型匹配,但没有匹配的限定符:
- WELD%AbstractSyntheticBean%WEB-INF / lib / cdi-unit-3.1.3%HttpSession

如果您愿意,我可以打印整个堆栈。浏览stackoverflow和网络我发现很多关于什么可能会出错的理论,但不是一个适用的解决方案。有人建议这个错误可能是由于Glassfish与Weld的集成,Glassfish与20年前的Java SE 8集成(我正在使用jdk-8u65-linux-x64.rpm),但后来我看到有人在运行他们的项目时遇到类似的问题因此我打电话给你: - )



ps我的项目可以在这里找到:



a href =https://github.com/vasigorc/rimmaproject =nofollow> https://github.com/vasigorc/rimmaproject

解决方案

经过数小时的调查后,可以解决这个问题。感谢BrynCooke @此链接: https://github.com/BrynCooke/cdi-unit/问题/ 58



问题在于我的 cdi-unit maven dependency,它必须是测试范围。我这样做,也从我使用的cdi-unit工件中排除了焊接核心,并将后者作为单独的依赖项添加到 fix-part 部分。

fix-part from pom .xml:

 <依赖项> 
< groupId> org.jglue.cdi-unit< / groupId>
< artifactId> cdi-unit< / artifactId>
< version> 3.1.3< / version>
<排除项>
<排除>
< groupId> org.jboss.weld.se< / groupId>
< artifactId> weld-se-core< / artifactId>
< /排除>
< /排除>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.jboss.weld.se< / groupId>
< artifactId> weld-se-core< / artifactId>
< version> 2.2.2.Final< / version>
< scope> test< / scope>
< /依赖关系>


I have this (notorious by now) @SessionScoped bean in my JSF project:

@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
}

I have the following interfaces that I use for EJBs:

  @Local
  public interface AppointmentRepository {/**methods*/}

  @Local
  public interface AppointmentService {/**methods*/}

And these are the EJBs (briefly):

@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;
    }
...}

During the build (which is otherwise successful) I get this WELD warnings:

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.

During Run I get this exception:

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

I can print the entire stack if you wish. Browsing stackoverflow and the web I found many theories about what might get wrong, but not an applicable solution. There were suggestions that the error might be due to the Glassfish integration with Weld, Glassfish integration with Java SE 8 before 20 (I am using jdk-8u65-linux-x64.rpm), but then I saw people having similar problems running their projects on WildFly.

Therefore I call you to rescue :-)

ps My project is available here: https://github.com/vasigorc/rimmaproject

解决方案

This one can be solved after hours of investigation. Thanks to BrynCooke @ this link: https://github.com/BrynCooke/cdi-unit/issues/58

The problem was my cdi-unit maven dependency which had to be test scoped. I did that and also excluded the weld-se-core from the cdi-unit artifact that I was using and added the later as a separate dependency but in a version supported by Glassfish 4.1.

This is the fix-part from pom.xml:

   <dependency>
        <groupId>org.jglue.cdi-unit</groupId>
        <artifactId>cdi-unit</artifactId>
        <version>3.1.3</version>
        <exclusions>                
            <exclusion>
                <groupId>org.jboss.weld.se</groupId>
                <artifactId>weld-se-core</artifactId>
            </exclusion>
        </exclusions>
        <scope>test</scope>                          
    </dependency>   
    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se-core</artifactId>
        <version>2.2.2.Final</version>
        <scope>test</scope>
    </dependency>

这篇关于WELD-001408:类型为HttpSession的不满意的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆