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
2
votes
3 answers

Is there a way to call a method in a bean after all spring context is initialized

I have a problem and this is the gist of it: (there are more classes involved in the loop but it can be represented this way) @service public class serviceDispatcher{ @Autowired private BeanA a; @Autowired private BeanB b; …
MohammadZoghi
  • 578
  • 1
  • 7
  • 17
2
votes
1 answer

PostConstruct not being called in junits

When i am testing(JUnit) this class i get NullPointerException when i call getdata method private static final Map> REFERENCE_MAP = new HashMap<>(); @Autowired private static classA aobj; @PostConstruct public void…
2
votes
2 answers

Will Bean get created if @PostConstruct fails

I've been trying to solve an issue where my managedBean is sometimes null (I get the target unreachable error message saying that the bean is null) and this intermittent issue usually occurs if I tinker in the @PostConstruct method. While booting…
Joe
  • 181
  • 11
2
votes
1 answer

JSF - Bean injection trouble

As suggested by a user time ago in another question, I need to inject a bean in another bean. So, i do the following : @ManagedBean @RequestScoped public class Articles { private String selectedMenu; @ManagedProperty(value="#{user}") …
markzzz
  • 47,390
  • 120
  • 299
  • 507
2
votes
1 answer

How to call a method present in @PostConstruct class

I have class MyModel.java and I'm constructing it using @PostConstruct. @ConfigurationProperties(prefix = "test") public static class MyModel extends Model { @PostConstruct private void postConstruct() { } } Now I want to call a…
Sai prateek
  • 11,842
  • 9
  • 51
  • 66
2
votes
1 answer

Wait for dependencies to load before starting spring boot service

I have a spring boot application which has two beans - AppState and Users. AppState depends on the bean Users as it autowires it. The skeleton codes for the two beans are as follows. @Component @EnableScheduling public class Users { @Getter //…
Nik
  • 5,515
  • 14
  • 49
  • 75
2
votes
0 answers

JSF bean creates more than once

When I open jsf page then catalog bean creates two times. So why does it happen? jsf page:
rozerro
  • 5,787
  • 9
  • 46
  • 94
2
votes
1 answer

@PostConstruct in @ViewScoped bean invoked on every request

I'm using JSF2.2 and PrimeFaces 5.2 and I have a list of chackboxes which posts a request via Every time a post happens the @PostConstruct method of the been…
simonC
  • 4,101
  • 10
  • 50
  • 78
2
votes
1 answer

PostContruct annotation on superclass

I want to refactor a method annotated with @PostContruct in a common class of all my controller. public abstract class Controller { @PostConstruct protected void PostContruct() { ..} } public class AuthController extends Controller…
mathk
  • 7,973
  • 6
  • 45
  • 74
2
votes
1 answer

Call session scoped bean method on every view

Perhaps this is a question I should be able to find documentation on, but I'm unfamiliar with a lot of the jargon so I'm struggling. Basically, I'm using JSF2. I have a SessionScoped bean, and it uses a postconstruct init() method. I want the…
user1795370
  • 332
  • 2
  • 4
  • 18
2
votes
1 answer

@PostConstruct method called for no reason

For a project I am updating a Java web application that has some loose ends. I'm having problems with the init-method of a bean, that is called while it should not be. The page that causes the problems has three buttons to return to three different…
Century
  • 283
  • 1
  • 4
  • 22
2
votes
3 answers

Are the Spring @PostConstruct and @PreDestroy method's annotations annotations a form of AOP?

I have the following doubt related to the Spring @PostConstruct and @PreDestroy method's annotations. So the @PostConstruct annotation means that the annoted method is automatically performed after the object creation and after the dependency…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
2
votes
1 answer

JSF @managedproperty and @PostConstruct

I have a problem with JSF2 @ManagedProperty annotation. I have a managed bean that create a user, then i want to pass this user to another bean to display other informations relative to that user. So my code is below…
2
votes
1 answer

Exception during bean's @PostConstruct does not end up in right

My question is quite simple (to ask). How can I create and manage my Exceptions in a JSF application? First we have the separation from normal and Ajax requests. Problem solved by using FullAjaxExceptionHandler by Omnifaces. Ok, now my Ajax…
Ioannis Deligiannis
  • 2,679
  • 5
  • 25
  • 48
2
votes
1 answer

When writing a startupbean (@Singleton @Startup @PostConstruct) is there anyway for me to get the ServletContext?

So I am trying to create a task that fires off at regular intervals and I want it to get some things from the ServletContext: ... @Singleton @Startup public class InitTimers { @Resource private TimerService timerService; @PostConstruct …
Roberto Murphy
  • 456
  • 5
  • 15