Startup POJO On A Weld/Seam3 Application

≡放荡痞女 提交于 2019-12-01 09:33:09

问题


I'm trying to get a POJO starting on startup within my Weld/Seam3 application but not having much luck. I've tried the following but none of them have worked:

@Singleton
public class StartupJobs {
    @Inject
    private Logger log;

    public void onStartup(@Observes @Initialized ServletContextEvent event) {
        log.info("Starting startup jobs");
    }

    public void onStartupTwo(@Observes @Initialized WebApplication webApplication) {
        log.info("Starting startup jobs");
    }
}

-

// Guessing this way is no good as I can't use the javax.ejb.Startup annotation here
@ApplicationScoped
public class StartupJobs {
    @Inject
    private Logger log;

    @PostConstruct
    public void onStartup() {
        log.info("Starting startup jobs");
    }
}

But neither of those ways worked. My log message was never raised. As this application is run on Tomcat6 and I've had to add the "org.jboss.weld.environment.servlet.Listener" listener to my web.xml, I'm wondering if there's something that class raises that I could observe. I didn't notice anything in particular though.

Any clue what else I could try?


回答1:


Found out my issue was configuration. I hadn't seen I needed some extra configuration due to being on Tomcat 6: http://docs.jboss.org/seam/3/servlet/latest/reference/en-US/html/servlet-installation.html#installation.pre-servlet-3

A quick note on the documentation on that page as it stands as I write this, the class for the "Catch Exception Filter" should be "org.jboss.seam.servlet.exception.CatchExceptionFilter". The documentation is missing out the "exception". It seems to have been fixed in the Seam Servlet code so I imagine this bug will be fixed next time the documentation is released.



来源:https://stackoverflow.com/questions/7347516/startup-pojo-on-a-weld-seam3-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!