我需要创建一个 EJB 计时器(使用 @Schedule),但是我听说 Websphere Liberty 配置文件不支持它吗?根据之前在 StackOverflow 上发布的问题,截至 08/2013 不支持它:
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!");
}
}
更新:
我将我的数据源 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 数据库的结果吗?如果是,是否有办法避免这种情况?
最佳答案
看起来您打开了 ejbPersistentTimer-3.2
功能,因为您正在获取配置数据源的异常。
如果您打算使用 ejbPersistentTimer-3.2
(或包含它的 ejb-3.2
),您需要配置一个数据源以用于持久计时器。
由于您不需要永久性 EJB 计时器(因为您在 @Schedule
注释中有 persistent=false
),您可以删除 ejbPersistentTimer-3.2
功能并仅使用 ejbLite-3.2
功能(不包括持久计时器功能)。
ejbLite-3.2
功能包括对非持久计时器的支持,您无需担心配置数据源的问题。
关于java - 在 Liberty 中创建 EJB 计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33631860/