WELD-001408: Unsatisfied dependencies for type HttpSession

时间秒杀一切 提交于 2019-12-25 07:39:30

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/34146726/weld-001408-unsatisfied-dependencies-for-type-httpsession

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!