Я использую библиотеку третьей части, использую jar в своем весеннем загрузочном приложении и создал синглтон-бин класса, который мне нужно использовать.Однако, когда я автоматически подключаю этот bean-компонент, он всегда возвращает null
Созданный синглтон класса из библиотеки и автоматическое подключение bean-компонента
@Configuration
public class IdGenConfig {
private static final Instant baseTime = ZonedDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")).toInstant();
@Bean//this too 3rd party lib class
public MachineId concreteMachineId(){
return new ConcreteMachineId();
}
@Bean(name = "camflakeIdGen")//this is 3rd party library
public Camflake camflake(final MachineId machineId){
return new Camflake(machineId, baseTime);
}}
@Service
@Log4j2
public class IdGenerator implements IdentifierGenerator {
@Autowired
@Qualifier("camflakeIdGen")
Camflake camflake;//here null
@Override
public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
try {
log.debug("generate(): action=generate; state=start; message=\"generating id\";");
Long id = camflake.next();
log.debug("generate(): action=generate; state=finish; message=\"generating id\";id={};",id);
return id;
} catch (Exception ex) {
log.fatal("generate(): action=generate; state=error; message=\"generating id\"; error=\"{}\";", ex.getMessage(), ex);
throw new Exception(ErrorType.SYSTEM_ERROR);
}
}
}