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

Unable to invoke method annotated with @PostConstruct when mocked using Mockito

I am trying to write unit tests for Repository layer classes with Junit and Mockito. I have mocked the base class that supplies NamedParameterJdbcOperations and tried to inject into the repo class. In the repo class, we are loading sql queries from…
Baru
  • 1
  • 2
0
votes
1 answer

Spring, instance variable visibility in new thread started from @PostConstruct

Does spring garantee visibility of 'sleepInterval' and 'businessLogic' instance variables in case below? import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import…
Yurii Bondarenko
  • 3,460
  • 6
  • 28
  • 47
0
votes
2 answers

Mvvmfx: initialize-method causes NoClassDefFoundError: javax/annotation/PostConstruct

i'm trying to implement a mvvm-pattern with JavaFx. To do so i'm using the mvvmfx-framework. To use data from a model i've tried to use the NotificationCenter. When inserting an initialize-method in my viewModel to subscribe to messages i get an…
Piepette
  • 21
  • 3
0
votes
1 answer

Spring Boot class cast exception in PostConstruct method

I am running a Spring Boot application with a PostConstruct method to populate a POJO before application initialization. This is to ensure that the database isn't hit by multiple requests to get the POJO content after it starts running. I'm able to…
Mano
  • 1
  • 3
0
votes
0 answers

Shutting down after task completion

I have spring application written in the following way - @SpringBootApplication @Import({ ApplicationLoader.class }) public class MyApplication { @Bean public Clock clock() { return Clock.systemDefaultZone(); } …
comiventor
  • 3,922
  • 5
  • 50
  • 77
0
votes
0 answers

@PostConstruction tries to initilize scoped service - not autowired in the method

I have a method with @PostConstruct annotation which uses autowired service @Service public ServiceWithPostConstruct{ private AutowiredService autowiredService; @Autowired public ServiceWithPostConstruct(AutowiredService autowiredService)…
majki
  • 33
  • 1
  • 8
0
votes
0 answers

java.lang.reflect.InvocationTargetException in PostConstruct method

I am trying to validate the values returned by a list of methods using java reflection and @PostConstruct spring annotation as it is depicted in the following code snippet : @Service("appConfigService") public class AppConfigServiceImpl implements…
ecdhe
  • 421
  • 4
  • 17
0
votes
1 answer

PostConstruct method will not be called after login

In our application we have a dashboard, which will be loaded after login from an init() method with PostConstruct annotation. Everything works fine, until the session is expired. In this moment, if I click on a button in dashboard, this init method…
nolazem
  • 45
  • 5
0
votes
1 answer

@PostConstruct method not run during initialization

I have a weird problem regarding @PostConstruct. I have several classes, which are run during initialization to load background tasks into memory. I have written 3 of these classes. Only one of those classes PostConstruct method is run during…
DarkFeud
  • 181
  • 2
  • 16
0
votes
1 answer

EJB3 - method not a post-construct method of EJB interceptor

My @PostConstruct method meets all of the rules, but I still get the error that the method is not a post-construct method of EJB interceptor. It's return is void. It does not throw exceptions. It does not take arguments. Does anyone know of…
Tyrone
  • 41
  • 1
  • 4
0
votes
2 answers

How to load springboot properties?

I'm trying to load properties once in my springboot application. Actually, I have created a class to do that : @Configuration @PropertySource(value = { "classpath:parameters.properties", "classpath:iot.properties" }) public class PropertiesHelper { …
0
votes
1 answer

JEE6 - @ApplicationException - @Inject and @PostConstruct not called

I have a problem with @Inject and @PostConstruct method not called in a @ApplicationException annoted class. I'm using Glassfish 3.0.1 with JPA,CDI and EJBs in the service(=ejb)-layer and would like to throw an errorMessage that contains a text in…
0
votes
1 answer

Spring bean not getting injected

I have the following scenario where I am running into null pointer exception because bean not getting initialized and leading to failure in my server failing to boot. There is a newly introduced call in PostConstruct annotated method which is…
jetty
  • 859
  • 2
  • 17
  • 37
0
votes
0 answers

Singleton and PostConstruct in lib jar not called at startup?

I need to create a little Jar which could be added to other projects (we use maven). This Jar must have a class that is called at startup and must log some basic information. I've been hinted to use Singleton Startup and Postconstruct annotations to…
Magatsu
  • 5
  • 2
0
votes
0 answers

@Singleton @Startup @PostConstruct not waiting for external client calls

I have tested this behaviour in GlassFish 3.1 and Jboss AS 6.1. In my test, I've configured an application as follows: 1) a Singleton which has Postconstruct method which takes about 1.5 minutes to end (with thread.sleep()), 2) a Stateless Bean…
Annamaria
  • 81
  • 1
  • 4