@PostConstruct不适用于特定类名的springboot

时间:2018-11-06 08:01:21

标签: java spring spring-boot postconstruct

对于特定的类名DeviceServiceImpl,springboot @Service不能通过@PostConstruct方法进行访问吗?

这是我已经开始发生的超级简化类:

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

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

}

对于此特定名称:DeviceServiceImpl代码没有通过我的@PostConstruct方法。

但是,方法是将任何其他怪异的名称更改为:无论DeviceServiceImpl2DeviceServiceImpServiceImpAa。 ..无论如何,它有效 !!!!

我完全发疯了:

即:

@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());
  }

}

这是此内容的输出,例如:

  

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

附加说明:

  • 我只更改了类名(显然,在Java中,.java文件名)。
  • 我什至都没有更改包裹
  • Springboot已配置为扫描该软件包(否则,将无法使用新名称)

0 个答案:

没有答案