1

Is there any reasonable reason why for the particular class name DeviceServiceImpl a springboot @Service does not go through @PostConstruct method?

This is my super simplified class where it already happens:

@Service
public class DeviceServiceImpl { // Not working due to the "DeviceServiceImpl" name

  @PostConstruct
  public void init() {
    System.out.println("-----------> PostConstructed " + this.getClass().getSimpleName());
  }

}

For this particular name: DeviceServiceImpl code does not go through my @PostConstruct method.

However, by changing the name for any freaking other name: No matter if DeviceServiceImpl2, DeviceServiceImp, ServiceImp, Aa.... whatever, it works!!!!

I am getting totally mad:

ie:

@Service
public class DevicServiceImpl { // Working by only changing the name (Supressed "e" from Device"

  @PostConstruct
  public void init() {
    System.out.println("-----------> PostConstructed " + this.getClass().getSimpleName());
  }

}

Here is the output for this one, for example:

-----------> PostConstructed DevicServiceImpl

Extra notes:

  • I only changed the class name (and obviously in java, the .java file name).
  • I did not even change package
  • Springboot has been configured to scan in that package (otherwise, wouldn't work for new name)
Mayday
  • 4,680
  • 5
  • 24
  • 58
  • 4
    Search for `DeviceServiceImpl` and `deviceServiceImpl ` and see if something is overriding your bean with something else. I suspect that instead of renaming your class `@Service("some-name")` would also work. You can check the trace/debug logs (after enabling it) to see if your bean gets overriden with another one. – M. Deinum Nov 06 '18 at 08:04
  • @M.Deinum what classes should i enable the log for? org.springframework.web? which one would show me these cases? – Mayday Nov 06 '18 at 08:10
  • Just enable debug or trace logging globally ( I guess debug is enough). – M. Deinum Nov 06 '18 at 08:11
  • 2
    @M.Deinum You are a genius!! I just needed to clean all binary files. For some reason, old .class files were not being deleted, and it was taking another DeviceServiceImpl.class in runtime. Found it when debugging with logs!! Thank you very much!!! – Mayday Nov 06 '18 at 08:15

0 Answers0