Questions tagged [postconstruct]

@PostConstruct is a Java EE annotation used to select a method that needs to be executed after dependency injection is done to perform any initialization.

The @PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. This method MUST be invoked before the class is put into service.

This annotation is recognized by all Java EE compliant containers as well as .

See also

242 questions
3
votes
3 answers

No Session Hibernate in @PostConstruct

MyDao class have the methods to do whole persistence tasks through Hibernate SessionFactory, it works fine. I inject MyDao in MyService as can see above, but when @PostConstruct init() method is called after injected MyDao (debugging I can see MyDao…
Dani
  • 4,001
  • 7
  • 36
  • 60
3
votes
2 answers

@PostConstruct method is not called

I wanted to use @PostConstruct to initialize a bean in my webapp but I can't get it to work. I've recreated the problem in a new project and it still won't work. Am I missing something obvious here? As far as I can tell my init() method fulfills all…
ddx
  • 33
  • 1
  • 3
3
votes
2 answers

How can I make sure a "pool" bean gets all the other beans it needs?

I have a spring config where I define hundreds of actions which extend MyAction. I have a pool where an execution service can look up actions. I can't use the appContext directly because each action has one or more "keys" which the execution service…
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
3
votes
1 answer

behavior for @PostConstruct exception handling in WebSphere

Short: (Portlet-)Container swallows Exception thrown by @PostConstruct method in backing bean. Is this behavior intentional, a bug or container specific? Long: I am running a portlet on WebSphere Portal 7, where i force managed bean construction in…
Stefan
  • 838
  • 3
  • 13
  • 28
3
votes
1 answer

@PostConstruct not working in @FacesValidator

Is the post construct annotation not supported in validators? I have a application scoped jndi servicelocator bean which I inject as a managed property into my validator. @ManagedProperty(value = "#{jndiServiceLocatorBean}") private final…
djmj
  • 5,579
  • 5
  • 54
  • 92
2
votes
1 answer

Weblogic 12c JSF don't call (ignore) @PostConstruct

In summary, method with @PostConstruct is not call by JSF on WebLogic12c, on managed bean. I have a very basic application. Technologies used: JSF2.0 Application Server: WebLogic 12c Java @ManagedBean @ViewScoped public class BeanTest implements…
2
votes
1 answer

MyFaces - @PostConstruct on abstract class

I'm trying to execute PostConstruct annotated method that is in abstract class, public abstract class AbstractTest { @PostConstruct public void init() { } } @ManagedBean @SessionScoped …
holek
  • 21
  • 2
2
votes
1 answer

@PostConstruct is not invoked by Micronaut when a bean with scope @Context is instantiated in @Factory class

When I create a class annotated with @Context and run a Micronaut application, the @PostConstruct method works. Example: package com.example; import io.micronaut.context.annotation.Context; import javax.annotation.PostConstruct; @Context public…
nikiforov.java
  • 229
  • 4
  • 12
2
votes
2 answers

@Value is Null while using @PostConstruct

I am trying to load YML files from a config package, but whenever I use the @Value("${..}") annotation it is null during the @PostConstruct method causing a Null Pointer. I need the @PostConstruct to load all files at once. …
Beez
  • 478
  • 9
  • 23
2
votes
1 answer

How to call @Scheduled method in only one instance using @PostConstruct

There is job that needs to be done on cron schedule The same logic as in the job must be performed at the start of the spring boot application, therefore @PostConstruct method is used Shedlock is used, since it is planned to run the application in…
2
votes
2 answers

Spring: Why method annotated with @PostConstruct cannot be static?

I am reading documentation about @PostConstruct on this site: https://www.baeldung.com/spring-postconstruct-predestroy It is written: The method annotated with @PostConstruct can have any access level but it can't be static. Can someone tell me…
Jakov
  • 879
  • 2
  • 17
  • 36
2
votes
1 answer

Autowired , Value annotation is not working

I am using below class and my @Autowired, @Value annotation is not working for spring boot application. Also, I use init method with @PostConstruct and initialize the value when the application starts. Then right before use of the variables, the…
Bandita Pradhan
  • 85
  • 2
  • 16
2
votes
0 answers

@PostConstruct populate DB at startup - Spring Boot 2.2.4 upgrade

I'm upgrading my application from Spring Boot 1.5 to 2.2. Now my db inits aren't working. The culprit in my case seems to be the HibernateTransactionManager when using this my @PostConstruct or @EventListener(ApplicationReadyEvent.class)method isn't…
olahell
  • 1,931
  • 3
  • 19
  • 35
2
votes
2 answers

Method with annotation @PostConstruct (javax) doesn't call

Is it possible to call a specific initialization method right after calling the constructor using annotations from javax? I put the @Inject annotation (javax.inject.Inject) over the field that I want to initialize in the method with the…
SorryForAsking
  • 323
  • 2
  • 18
2
votes
1 answer

@Startup annotation does not work

I use the @Startup annotation to set entry point on the deploying process in EJB, but it does not work. See code example below: @Singleton @Startup public class SchedulerManager { private static Logger log =…
Tioma
  • 2,120
  • 9
  • 35
  • 52