[英]Problem deploying scheduled EJB to Glassfish server
I have a weird (?) problem with an EJB I want to deploy to my Glassfish 3.1 application server. 我有一个想部署到我的Glassfish 3.1应用程序服务器上的EJB的怪异(?)问题。
I have this bean, which should be executed continuously in Glassfish using the @Schedule
annotation. 我有这个bean,应该使用@Schedule
批注在Glassfish中连续执行。 This worked fine for me until I added some code to the EJB accessing a database. 在我向访问数据库的EJB添加一些代码之前,这对我来说效果很好。
@Stateless
public class MyBean implements MyBeanLocal {
@Schedule(second = "*", minute = "*", hour = "*")
public void initiateProcess() {
MyCoordinator mc = new MyCoordinatorImpl();
List<Entity> entities = mc.methodAccessingDB();
}
}
This is my EJB, which is executed every second. 这是我的EJB,每秒执行一次。 How I said above, I can deploy this EJB and it executed successfully, if I don't call ac.methodAccessingDB()
. 上面我怎么说,如果不调用ac.methodAccessingDB()
,则可以部署此EJB并成功执行。 This means, that I can't even deploy it to Glassfish. 这意味着,我什至无法将其部署到Glassfish。 Glassfish tells me 玻璃鱼告诉我
Invalid ejb jar [...]: it contains zero ejb. 无效的ejb jar [...]:它包含零ejb。 Note: 1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-driven bean. 注意:1.一个有效的ejb jar需要至少一个会话,实体(1.x / 2.x样式)或消息驱动的bean。 2. EJB3+ entity beans (@Entity) are POJOs and please package them as library jar. 2. EJB3 +实体bean(@Entity)是POJO,请将其打包为库jar。 3. If the jar file contains valid EJBs which are annotated with EJB component level annotations (@Stateless, @Stateful, @MessageDriven, @Singleton), please check server.log to see whether the annotations were processed properly.. Please see server.log for more details. 3.如果jar文件包含用EJB组件级别注释(@ Stateless,@ Stateful,@ MessageDriven,@ Singleton)注释的有效EJB,请检查server.log以查看注释是否已正确处理。请参阅服务器。登录以获取更多详细信息。
If I just write List<Entity> entities = null;
如果我只写List<Entity> entities = null;
instead of List<Entity> entities = ac.methodAccessingDB();
而不是List<Entity> entities = ac.methodAccessingDB();
I can deploy it and it runs fine. 我可以部署它,并且运行良好。
OK, now I have found the solution for this problem. 好的,现在我找到了解决该问题的方法。 The EJB couldn't find the classes on the deployed version. EJB在部署的版本上找不到类。 The solution was to pack everything into an ear project. 解决方案是将所有内容打包到一个耳朵项目中。 I am using maven, so I created in the end 3 projects. 我正在使用maven,所以我在最后3个项目中创建了。
<packaging>ejb</packaging>
一个用于EJB <packaging>ejb</packaging>
<packaging>ear</packaging>
一个用于EAR <packaging>ear</packaging>
<module>
. 第三个父项目,它将两个其他项目集成为<module>
。 I then deployed the packed ear to Glassfish and the timer started and everything was there. 然后,我将打包好的耳朵放到Glassfish上,计时器开始计时,一切都准备就绪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.