问题
I have a feeling I'm mixing EJB and JSF managed bean responsibilities, but what I want is a scheduled task EJB (@Singleton with @Schedule) that has access to my JSF application scoped beans.
Specifically, I have a JSF @ApplicationScoped bean that sends different e-mails depending on if it's in Development, Test, or Production. I want to schedule this to send e-mails every 24 hours. What's the best way to accomplish this?
回答1:
It's bad design to set the business layer (EJB) as dependent on the Presentation layer. The reverse (Web tier depending on Business tier) is the time tested best practice.
The EJB tier is to provide services to the web tier. Your use case seeks to make the web tier provide services to the EJB tier. And the need, IMO is too trivial to make such a compromise.
I'd recommend instead that you externalize the desired config in a .properties file within a secure location in your application that both tiers have access to.
来源:https://stackoverflow.com/questions/15076409/ejb-schedule-task-with-access-to-jsf-managed-beans