Skip to main content
added 30 characters in body
Source Link
Sean Patrick Floyd
  • 300.6k
  • 72
  • 481
  • 598

Because Spring can't access any fields or methods before the object is created (which is done through the constructor). So Spring instantiates the object using the constructor and then injects the properties.

The only way around this is to use Constructor Injection (which is usually a bad ideacan be cumbersome if you have multiple dependencies). I think what you should do is move your code out of the constructor and into an initialization method using the @PostConstruct annotation:

@PostConstruct public void init(){ // do stuff with entitymanager here } 

Because Spring can't access any fields or methods before the object is created (which is done through the constructor). So Spring instantiates the object using the constructor and then injects the properties.

The only way around this is to use Constructor Injection (which is usually a bad idea). I think what you should do is move your code out of the constructor and into an initialization method using the @PostConstruct annotation:

@PostConstruct public void init(){ // do stuff with entitymanager here } 

Because Spring can't access any fields or methods before the object is created (which is done through the constructor). So Spring instantiates the object using the constructor and then injects the properties.

The only way around this is to use Constructor Injection (which can be cumbersome if you have multiple dependencies). I think what you should do is move your code out of the constructor and into an initialization method using the @PostConstruct annotation:

@PostConstruct public void init(){ // do stuff with entitymanager here } 
added 324 characters in body; deleted 3 characters in body
Source Link
Sean Patrick Floyd
  • 300.6k
  • 72
  • 481
  • 598

Because Spring can't access any fields or methods before the object is created (which is done through the constructor).

  So Spring instantiates the object using the constructor and then injects the properties.

The only way around this is to use Constructor injectionConstructor Injection (which is usually a bad idea). I think what you should do is move your code out of the constructor and into an initialization method using the @PostConstruct annotation:

@PostConstruct public void init(){ // do stuff with entitymanager here } 

Because Spring can't access any fields or methods before the object is created (which is done through the constructor).

  So Spring instantiates the object using the constructor and then injects the properties.

The only way around this is to use Constructor injection (which is usually a bad idea). I think what you should do is move your code out of the constructor and into an initialization method:

@PostConstruct public void init(){ // do stuff with entitymanager here } 

Because Spring can't access any fields or methods before the object is created (which is done through the constructor). So Spring instantiates the object using the constructor and then injects the properties.

The only way around this is to use Constructor Injection (which is usually a bad idea). I think what you should do is move your code out of the constructor and into an initialization method using the @PostConstruct annotation:

@PostConstruct public void init(){ // do stuff with entitymanager here } 
Source Link
Sean Patrick Floyd
  • 300.6k
  • 72
  • 481
  • 598

Because Spring can't access any fields or methods before the object is created (which is done through the constructor).

So Spring instantiates the object using the constructor and then injects the properties.

The only way around this is to use Constructor injection (which is usually a bad idea). I think what you should do is move your code out of the constructor and into an initialization method:

@PostConstruct public void init(){ // do stuff with entitymanager here }