• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@PostConstruct is never called.

 
ray frid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am running jboss 5.1

this is what i have done:
package beans;


@Local
public interface RequestHandlerBeanLocal
{
public void getAllClocksFromDB();
public void start();
}


@Stateless
public class RequestHandlerBean implements RequestHandlerBeanLocal
{

@PostConstruct
public void getAllClocksFromDB()
{

}

@PostConstruct
public void start()
{
System.out.print("start here");
}


this is the console ouput after deployment:

11:16:59,906 INFO [TomcatDeployment] undeploy, ctxPath=/ECMSWeb
11:16:59,921 INFO [SessionSpecContainer] Stopping jboss.j2ee:ear=ECMS.ear,jar=ECMSEJB.jar,name=RequestHandlerBean,service=EJB3
11:16:59,937 INFO [EJBContainer] STOPPED EJB: beans.RequestHandlerBean ejbName: RequestHandlerBean
11:17:00,234 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@16501212{vfsfile:/D:/jboss-5.1.0.GA/server/default/deploy/ECMS.ear/ECMSEJB.jar/}
11:17:00,234 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@16501212{vfsfile:/D:/jboss-5.1.0.GA/server/default/deploy/ECMS.ear/ECMSEJB.jar/}
11:17:00,250 INFO [JBossASKernel] Created KernelDeployment for: ECMSEJB.jar
11:17:00,250 INFO [JBossASKernel] installing bean: jboss.j2ee:ear=ECMS.ear,jar=ECMSEJB.jar,name=RequestHandlerBean,service=EJB3
11:17:00,250 INFO [JBossASKernel] with dependencies:
11:17:00,250 INFO [JBossASKernel] and demands:
11:17:00,250 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
11:17:00,250 INFO [JBossASKernel] and supplies:
11:17:00,250 INFO [JBossASKernel] jndi:ECMS/RequestHandlerBean/local
11:17:00,250 INFO [JBossASKernel] Class:beans.RequestHandlerBeanLocal
11:17:00,250 INFO [JBossASKernel] jndi:ECMS/RequestHandlerBean/local-beans.RequestHandlerBeanLocal
11:17:00,250 INFO [JBossASKernel] jndi:ECMS/RequestHandlerBean/remote
11:17:00,250 INFO [JBossASKernel] Added bean(jboss.j2ee:ear=ECMS.ear,jar=ECMSEJB.jar,name=RequestHandlerBean,service=EJB3) to KernelDeployment of: ECMSEJB.jar
11:17:00,265 INFO [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@1d1327c{name=jboss.j2ee:ear=ECMS.ear,jar=ECMSEJB.jar,name=RequestHandlerBean,service=EJB3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=null autowireCandidate=true}
11:17:00,343 INFO [SessionSpecContainer] Starting jboss.j2ee:ear=ECMS.ear,jar=ECMSEJB.jar,name=RequestHandlerBean,service=EJB3
11:17:00,343 INFO [EJBContainer] STARTED EJB: beans.RequestHandlerBean ejbName: RequestHandlerBean
11:17:00,359 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

ECMS/RequestHandlerBean/local - EJB3.x Default Local Business Interface
ECMS/RequestHandlerBean/local-beans.RequestHandlerBeanLocal - EJB3.x Local Business Interface

11:17:00,468 INFO [TomcatDeployment] deploy, ctxPath=/ECMSWeb


as you have noticed: the print "start here" isnt shown in the output, which means @PostConstructis, never got called on deployment,


any idea?

thanks,

ray.








}
 
Costi Ciudatu
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container doesn't need to instantiate a bean just because you deployed it. It may very well lazily instantiate one when you look it up / inject it in some client.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you cannot mark 2 methods in a bean for lifecycle annotations (ex: @PostConstruct)
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Costi Ciudatu wrote:The container doesn't need to instantiate a bean just because you deployed it. It may very well lazily instantiate one when you look it up / inject it in some client.

You can, though, use the @Startup annotation to force it to instantiate one straight away.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:
You can, though, use the @Startup annotation to force it to instantiate one straight away.

Yes, that's a EJB3.1 feature which applies to only @Singleton beans.
 
ray frid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:
Matthew Brown wrote:
You can, though, use the @Startup annotation to force it to instantiate one straight away.

Yes, that's a EJB3.1 feature which applies to only @Singleton beans.


Yes, but i`am using jboss 5.1, which doesn't support EJB3.1.
any alternative way of having the same mechanism?
thanks
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try the JBoss specific @Service http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/Service_POJOs.html
 
ray frid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:You can try the JBoss specific @Service http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/Service_POJOs.html


Thanks.
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:
Matthew Brown wrote:
You can, though, use the @Startup annotation to force it to instantiate one straight away.

Yes, that's a EJB3.1 feature which applies to only @Singleton beans.

Ah, good point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic