Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

@PostConstruct is never called.

 
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.








}
 
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.
 
Sheriff
Posts: 10445
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)
 
Bartender
Posts: 4568
9
  • 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
Sheriff
Posts: 10445
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
Sheriff
Posts: 10445
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: 4568
9
  • 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.
 
this is supposed to be a surprise, but it smells like a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic