aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes @PostConstruct is never called. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "@PostConstruct is never called." Watch "@PostConstruct is never called." New topic
Author

@PostConstruct is never called.

ray frid
Ranch Hand

Joined: Dec 23, 2010
Posts: 79
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

Joined: Oct 24, 2006
Posts: 74
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

Joined: Jul 20, 2005
Posts: 10289
    
168

Also you cannot mark 2 methods in a bean for lifecycle annotations (ex: @PostConstruct)

[My Blog] [JavaRanch Journal]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

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

Joined: Jul 20, 2005
Posts: 10289
    
168

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

Joined: Dec 23, 2010
Posts: 79
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

Joined: Jul 20, 2005
Posts: 10289
    
168

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

Joined: Dec 23, 2010
Posts: 79
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

Joined: Apr 06, 2010
Posts: 4490
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @PostConstruct is never called.