2017-05-28 102 views
0

我在配置java中的定时器时遇到了一些麻烦。确切地说 - 我试图部署我的peripherial.war时收到以下错误。Wildfly TimerService不满意依赖关系

{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"peripherial.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"peripherial.war\".WeldStartService: Failed to start service 
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type TimerService with qualifiers @Default 
    at injection point [BackedAnnotatedParameter] Parameter 2 of [BackedAnnotatedConstructor] @Inject public io.github.tastypenguinbacon.peripherial.heartbeat.service.PassiveHeartbeatService(Cache, TimerService) 
    at io.github.tastypenguinbacon.peripherial.heartbeat.service.PassiveHeartbeatService.<init>(PassiveHeartbeatService.java:0) 
"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.deployment.unit.\"peripherial.war\".WeldStartService"]} 

standalone.xml文件似乎很好。该部分(至少我希望它是)负责配置定时服务似乎也未尝不可:

<timer-service thread-pool-name="default" default-data-store="default-file-store"> 
    <data-stores> 
    <file-data-store name="default-file-store" path="timer-service-data" relative-to="jboss.server.data.dir"/> 
    </data-stores> 
</timer-service> 

我通过@Inject实例化TimerService,采用基于构造器注入,如果它以某种方式相关。 我使用的是wildfly-11.0.0.Alpha。默认standalone.xml文件中唯一更改的是能够访问服务器的IP地址。

回答

2

TimerService是JEE应用服务器资源。它不会自动提供给CDI @Inject -ed。该办法得到它(参见例如在JEE tutorial)是:

@Resource 
TimerService timerService; 

这可能会满足你的目的;如果你真的想把它作为一个CDI bean暴露出来,那么幸运的是它是微不足道的。只是使@Resource领域的生产商太 - 你可以有一个单独的类为:

@ApplicationScoped 
public class TimerServiceProducer { 
    @Resource 
    @Produces 
    TimerService timerService; 
} 

我不知道,如果@ApplicationScoped是绝对必要的,但它不会伤害任何。

相关问题