【发布时间】:2015-11-10 14:05:56
【问题描述】:
我需要创建一个 EJB 计时器(使用 @Schedule),但我知道 Websphere Liberty 配置文件不支持此功能?根据之前在 StackOverflow 上发布的问题,截至 2013 年 8 月,它不受支持:
Java EE-Timer / @Schedule in Websphere Liberty Profile
目前,当我尝试使用 @Schedule 注释时,出现以下异常:
[ERROR ] CWWKZ0004E: An exception occurred while starting the application
<EAR>. The exception message was: com.ibm.ws.container.service.state.StateChangeException: com.ibm.ws.exception.RuntimeError: java.lang.IllegalStateException: The ejbPersistentTimer feature is enabled, but the defaultEJBPersistentTimerExecutor persistent executor cannot be resolved. The most likely cause is that the DefaultDataSource datasource has not been configured. Persistent EJB timers require a datasource configuration for persistence.
问题是我确实定义了默认数据源。这是 EJB 代码 - 它非常简单,因为我只是想测试计时器功能:
import javax.ejb.Schedule;
import javax.ejb.Stateless;
@Stateless
public class TimerBean {
@Schedule(second="*/10", persistent=false)
public void doSomething() {
System.out.println("Hello World!");
}
}
更新:
我将 dataSource id 更改为“DefaultDataSource”,现在在启动服务器时我的控制台中出现了不同的异常:
[ERROR ] WTRN0078E: An attempt by the transaction manager to call start on a transactional resource has resulted in an error. The error code was XAER_RMERR. The exception stack trace follows: javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'master..xp_sqljdbc_xa_start'.
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:647)
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.start(SQLServerXAResource.java:679)
at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.start(WSRdbXaResourceImpl.java:1189)
at [internal classes]
[ERROR ] J2CA0030E: Method enlist caught javax.transaction.SystemException: XAResource start association error:XAER_RMERR
at com.ibm.tx.jta.impl.RegisteredResources.startRes(RegisteredResources.java:1048)
at [internal classes]
Caused by: javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'master..xp_sqljdbc_xa_start'.
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:647)
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.start(SQLServerXAResource.java:679)
这是计时器尝试写入我的 SQL DB 的结果吗?如果是,有没有办法避免这种情况?
【问题讨论】:
-
即使您有这些错误消息,应用程序是否仍在启动?或者这是否会使应用程序启动过程失败?
-
由于消息的原因,它没有启动。我用 ejbLite-3.2 替换了 ejb-3.2,并将我的数据库名称恢复为原来的名称,一切正常。
标签: java jakarta-ee timer ejb websphere-liberty