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
4
votes
1 answer

Init method gets called twice in @Viewscoped bean

I am using schedule component of Primefaces. I am filling it with values from database and when the user selects sth from the selectonemenu an ajax event is triggered (I tried to put just the related code, if there is sth missing pls remind…
lamostreta
  • 2,359
  • 7
  • 44
  • 61
4
votes
1 answer

CDI postconstruct initializing field

Does anyone know whether the initialization of instance fields within a method annotated with PostConstruct is considered to be thread safe? I am not quite sure if i have to make my fields of my ApplicationScoped bean volatile or not so other…
Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
3
votes
1 answer

ViewScoped bean getting constructed on every request... part 99

ARGH... This seems to have a hundred answers and I haven't found one that works for me, so I guess I will actually ask it again. Here is my scenario: My site technically has a single page whose contents get swapped out rather than having multiple…
Lucas
  • 14,227
  • 9
  • 74
  • 124
3
votes
1 answer

JSF PostConstruct Exception Handling - Redirect

I'd like to handle a JSF @PostConstruct exception by redirecting to another page. I'm using FacesContext.getCurrentInstance().getExternalContext().dispatch("page.jsf"); which works great but since the page uses 2 backing beans it continues to load…
monkey-wrench
  • 1,556
  • 2
  • 14
  • 16
3
votes
1 answer

Deserializing polymorphic JSON with transient variables using Gson-extras

I have some polymorphic java classes which I am serializing/deserializing. I'm using RuntimeTypeAdapterFactory from Gson-extras to ensure the classes serialize and deserialize correctly with "type" field set to the name of the derived class. It's…
johndoe
  • 45
  • 4
3
votes
2 answers

Is @PreDestroy method call granted if we get an Exception in @PostConstract

I have SpringBoot application which is load some configuration and runs a longtime processing in method annotated with @PostConstract. There are some resources which should be released if application completed successfully or with an Error. The…
Alexey Usharovski
  • 1,404
  • 13
  • 31
3
votes
0 answers

PostConstruct in inner Spring configuration not getting invoked

Im trying to setup multiple filter chains as follows in Spring Security and running into a weird issue. @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) public class SecurityConfiguration { …
nixgadget
  • 6,983
  • 16
  • 70
  • 103
3
votes
1 answer

Accessing to Spring beans in Hibernate managed entity method marked by @PostLoad

I would like to enrich entity with additional data on load from DB inside @PostLoad. How can I access to Spring managed beans inside @PostLoad method? I use ugly solution with static accessor: @Service public class StaticApplicationContext…
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
3
votes
1 answer

@PostConstruct method called all the time on Jersey service

Hi I'm using GigaSpaces XAP which basically uses Spring and ApplicationContext to do all it's init and config etc... At some point in time during the loading of the web application a "cache" or what they call a space proxy is instantiated and is…
user432024
  • 4,392
  • 8
  • 49
  • 85
3
votes
3 answers

@PostConstruct on JPA entity not called in Spring Boot

I'm using Spring Boot and I added @PostConstrcut annotation to my JPA Entity as shown , but When the entity is instantiated this interceptor is never called . @Entity public class MyTableName implements java.io.Serializable { // all attributes …
Yassine Abainou
  • 145
  • 2
  • 13
3
votes
1 answer

Using Spring @Lazy and @PostConstruct annotations

I have following classes: @Repository class A { public void method1() { ... } } @Component class B implements C { @Autowired @Lazy private A a; public void method2() { a.method1(); …
3
votes
1 answer

ActiveMQ-Core 5.7.0 API causes "The lifecycle method [start] must not throw a checked exception"

I have a EJB module, it use ActiveMQ-Core 5.7.0 as its dependency. When I deploy EJB Module alone to Glassfish server 4.1, it can be deployed successfully. But when I include this EJB module in an Enterprise Application and deploy this EAR to…
hieund
  • 356
  • 1
  • 6
  • 16
3
votes
2 answers

@PostConstruct called twice on simple @Singleton @Startup bean

my problem is that the @PostConstruct is called twice even though it shouldn't. I searched a lot and found similiar problems with jersey https://java.net/jira/browse/JERSEY-1883?filter=-3. However I tried to make a small example which apparently…
Dr4gon
  • 421
  • 8
  • 17
3
votes
2 answers

@Configurable doesn't work for objects initialized in @PostConstruct methods

I'm using Spring with AspectJ via compile-time weaving to use @Configurable spring annotation for objects non-managed by container. Here is an example @Configurable-annotated object: @Configurable(autowire = Autowire.BY_TYPE) public class…
3
votes
1 answer

FacesContext instance is null in ApplicationScoped Managedbean

I created a ApplicationScoped bean that have a PostConstruct method named start. Whenever i want to get instance of FacesContext in the start method and it returns null: @ManagedBean @ApplicationScoped public class RemoveOldFilesScheduler implements…
Hosein Masbough
  • 431
  • 1
  • 4
  • 19