@Singleton bean由于未预期的事务状态而无法初始化 [英] @Singleton bean failed to initialize because of not expected transaction status

本文介绍了@Singleton bean由于未预期的事务状态而无法初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!


我有一个场景,我需要在应用程序启动时加载一个bean(ReportManager),因此它可以安排执行报告(由DataStore bean从数据库中轮询)。

I had a scenario in which I needed one bean (ReportManager) to be loaded at application startup, so it can schedule reports for execution (polled from database by DataStore bean).

谷歌搜索我发现@Singleton,@ Startup和@DependsOn注释,我用过这样的:

Googling around I found @Singleton, @Startup and @DependsOn annotations, which I've used like this:

public class ReportManager {
    DataStore dataStore;

    public void scheduleReports() {
       List<Report> reports = dataStore.getReports();

@RolesAllowed("user") //I had security checks implemented like that beforehand
public class DataStore {
    public void initialize() {

    public List<Report> getReports() {


The problem was that I was getting really strange exception during deployment time:

<2012-09-27 14:04:15 CEST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "app".>
<2012-09-27 14:04:15 CEST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: Exception starting module: EJBModule(app-ejb-1.0-SNAPSHOT.jar)

Unable to deploy EJB: ReportManager from app-ejb-1.0-SNAPSHOT.jar:

Singleton ReportManager(Application: app, EJBComponent: app-ejb-1.0-SNAPSHOT.jar) failed to initialize.

   at weblogic.ejb.container.deployer.EJBModule.start(EJBModule.java:592)

Caused By: weblogic.ejb.container.InternalException: Transaction marked rollback or not expected transaction status: 1
   at weblogic.ejb.container.manager.SingletonSessionManager.postCallback(SingletonSessionManager.java:464)


Not really heplful exception message. Especially that I was also not getting any "INITIALIZED" log entries. When I commented out the dataStore.getReports() invocation everything was working fine and beans were constructed in proper order ("INITIALIZED" messages were produced). Including dataStore method invocation was causing above error and was somehow supressing all the log output.

我正在使用Weblogic 12c。

I am using Weblogic 12c.


最后我弄清楚导致错误的原因。由于空安全上下文而未在 @PostConstruct 方法中设置,因此 @RolesAllowed 声明阻塞了方法调用在 @Startup bean中执行时(来自 EJB 3.1规范,ch.4.3.4 :PostConstruct生命周期回调拦截器方法在未指定的安全上下文中执行。)。

Finally I've figured out what was causing the error. It was the @RolesAllowed declaration which was blocking method invocation due to the empty security context, not set in @PostConstruct method when executed in @Startup bean (From EJB 3.1 spec, ch. 4.3.4: The PostConstruct lifecycle callback interceptor methods execute in an unspecified security context.).

使其工作所需的只是在调用的方法中添加 @PermitAll

What was needed to make it work was just the addition of @PermitAll to the invoked method:

public List<Report> getReports() {


The error was so misleasing I've decided to put this case here, as I couldn't google the answer.

这篇关于@Singleton bean由于未预期的事务状态而无法初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
发送“验证码”获取 | 15天全站免登陆