Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Spring Boot no recoge propiedades

Tengo una aplicación Spring Boot y estoy tratando de pasar una propiedad de application.properties como una anotación de parámetro dentro de la clase Entity así:

 @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;

Y mi application.properties tiene:

 start-seq=100000

Pero no compila diciendo "tipos incompatibles: java.lang.String no se puede convertir a int" sin reconocer la expresión. También traté de pasar esta propiedad con la anotación @Value a una variable como esa:

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

Pero la variable siempre es 0. Tengo las siguientes anotaciones antes de mi clase de configuración, pero aún no funciona:

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

¿Me estoy perdiendo de algo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

@SequenceGenerator no es una anotación de Spring. Por lo tanto, Spring no evalúa esto durante el procesamiento de la creación de la entidad.

No puede usar el lenguaje de expresión de primavera (SpEl) aquí.

Si desea configurarlos, debe usar JPA o la configuración de Hibernate para esto.

P.ej. escribir o extender el SequenceGenerator actual. Ver aquí para más detalles:

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!