Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Spring Boot not picking up properties

I have a Spring Boot application and I'm trying to pass a property from application.properties as a parameter annotation within Entity class like that:

@Entity
public class Entity{

    @Id
    @SequenceGenerator(name = "entity_id_seq", sequenceName = "entity_id_seq", initialValue = "${start-seq}")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "dish_id_seq")
    private int id;

And my application.properties have:

start-seq=100000

But it doesn't compile saying "incompatible types: java.lang.String cannot be converted to int" not recognizing expression. Also I tried to pass this property with @Value annotation to a variable like that:

@Value("${start-seq}")
private int startSeq;

But the variable is always 0. I do have following annotations before my config class, but it still doesn't work:

@Configuration
@EnableConfigurationProperties
@PropertySources({
        @PropertySource("classpath:application.properties")
})

Am I missing something?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

@SequenceGenerator is not an Spring annotation. Thus spring does not evaluate this during the processing of the entity creation.

You can not use spring expression language (SpEl) here.

If you want to configure these, you have to use JPA oder Hibernate configuration for this.

Eg. write or extend the current SequenceGenerator. See here for details:

https://thorben-janssen.com/custom-sequence-based-idgenerator/

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda