-
1. Bootstrap custom class during Jboss startup
welle Mar 1, 2011 9:47 PM (in response to amathewjboss1)You could implement it in a JBoss lifecycle MBean (use it's startup callbacks). Put in it's own jar file
togheter with a dependecies towards the jars that contains the EJB it will call.
-
2. Re: Bootstrap custom class during Jboss startup
welle Mar 1, 2011 9:53 PM (in response to welle)Perhaps a simpler way is to use the
@Singleton (or @Service in JBoss 5) and the standard callback annotations like @
PostConstruct. -
3. Bootstrap custom class during Jboss startup
amathewjboss1 Mar 2, 2011 2:59 AM (in response to welle)Thank you for sharing your thoughts. Yes, @Service along with @PostConstruct should work. But I really can't find the jar which has the @Service annotation. Like i said i am using Jboss 5.1. Does the jar comes with the Jboss 5.1?
Thanks
Anil Mathew
-
4. Bootstrap custom class during Jboss startup
jaikiran Mar 2, 2011 3:04 AM (in response to amathewjboss1)@org.jboss.ejb3.annotation.Service comes in jboss-ejb3-ext-api.jar which you can find in JBOSS_HOME/client folder. And by the way, be sure to use our latest EJB3 plugin http://www.jboss.org/ejb3/ejb3plugin.html against JBoss AS 5.1.0 since there have been some @Service related fixes after JBoss AS 5.1.0 was released.
-
5. Bootstrap custom class during Jboss startup
amathewjboss1 Mar 2, 2011 10:01 PM (in response to jaikiran)Thank You Jaikiran.
I was able to get the jboss-ejb3-ext-api.jar and also I created a class which has @Service and @PostConstruct. As you suggested i also ran the plugin (and I could see it ran correctly - which was really Awesome!). As expected the PostConstruct method is called during the Jboss startup (whowhoo..i was so excited).
But when i updated my @PostConstruct method to call a EJB method to get records, it is failing with the below error:
17:46:27,511 ERROR [ServiceContainer] Encountered an error in start of PropertyRegistryServiceImpl
java.lang.RuntimeException: javax.ejb.EJBTransactionRequiredException: public java.util.Collection com.tixx.persistence.properties.manager.impl.ApplicationPropertyManagerImpl.findAllApplicationProperties()
at org.jboss.ejb3.interceptors.container.AbstractContainer.invokeCallback(AbstractContainer.java:262)
at org.jboss.ejb3.EJBContainer.invokeCallback(EJBContainer.java:1161)
at org.jboss.ejb3.EJBContainer.invokePostConstruct(EJBContainer.java:1170)
at org.jboss.ejb3.service.ServiceContainer.lockedStart(ServiceContainer.java:265)
at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:905)
at org.jboss.ejb3.service.ServiceContainer.start(ServiceContainer.java:846)
It seems like the transaction (EntityManager) is null. I am using EJB3 with Hibernate. Below is my code snippet:
@Service
@Remote( { com.tickets.service.properties.PropertyRegistryServiceRemote.class })
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class PropertyRegistryServiceImpl implements PropertyRegistryServiceRemote{@EJB
EntityManager entityManager;
@PostConstruct
public void applicationStartup() {
System.out.println("Jboss Properties Initializing!!!!!");
try{
Collection<ApplicationProperty> props = this.entityManager.findAllApplicationProperties(AppContextHolder.getUserContext());
}catch(Throwable e){
System.out.println("Jboss Properties Initializing ERROR: "+ e);
}
}
}Any idea what am i missing here?
-
6. Bootstrap custom class during Jboss startup
alesj Mar 3, 2011 4:58 AM (in response to amathewjboss1)@EJB
EntityManager entityManager;
Shouldn't this be @PersistenceContext?
-
7. Bootstrap custom class during Jboss startup
amathewjboss1 Mar 3, 2011 3:14 PM (in response to alesj)Thanks Ales for the reply.
I was stupid and it was a code mix up and entityManager was the issue and i got ALL working yesterday night!!!!
A wrap up of what I did to make it work:
- Created a class with @Service and @Remote annotation.
- The class has a method with @PostConstruct annotation and this method will call a EJB (via Hibernate) and get all my records (property name/values) from database.
- Make sure to have jboss-ejb3-ext-api.jar and run the necessary plugin as mentioned by Jaikiran.
Thank You all. I AM IN LOVE WITH JBOSS 5.1
Anil
-
8. Bootstrap custom class during Jboss startup
jaikiran Mar 4, 2011 2:38 AM (in response to amathewjboss1)Good to know it's working!
-
9. Bootstrap custom class during Jboss startup
amathewjboss1 Mar 4, 2011 5:22 PM (in response to jaikiran)Thank you for the support. I do have a question in regards to the plugin which i ran for the Jboss 5.1.
I was wondering what exactly does it do when i run the plugin? I mean are we adding new jar files to different directory under Jboss home? The reason i asked is i will have to do the same to my QA / Production environment. I am little hesistant to run this directory in production.
Anil Mathew
-
10. Bootstrap custom class during Jboss startup
jaikiran Mar 4, 2011 11:45 PM (in response to amathewjboss1)Anil Mathew wrote:
I was wondering what exactly does it do when i run the plugin? I mean are we adding new jar files to different directory under Jboss home?
The plugin replaces some of the JBoss EJB3 implementation jars with new ones containing bug fixes.