WELD-001408:类型HttpSession的不满意依赖项

时间:2015-12-08 02:01:38

标签: glassfish cdi jboss-weld

我的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

1 个答案:

答案 0 :(得分:0)

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

问题是我的 cdi-unit maven依赖,必须测试范围。我这样做了,并且还从我正在使用的cdi-unit工件中排除了焊接se-core,并将后者作为单独的依赖项添加到version supported by Glassfish 4.1中。

这是来自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>