Create a docker image from a spring boot project

In order to create a docker image from a spring boot project, First, your pom.xml has to be configured. <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- Cofiguration for creating a docker image --> <image> <name>chamow01/${project.artifactId}</name> </image> </configuration> </plugin> </plugins> </build> Then, the next maven command needs to be applied, so spring boot uses paketo-buildpacks in order to create a docker image based on you Java code mvn spring-boot:build-image ... [INFO] > Running creator [INFO] [creator] ===> DETECTING [INFO] [creator] 6 of 24 buildpacks participating [INFO] [creator] paketo-buildpacks/ca-certificates 3.2.0 [INFO] [creator] paketo-buildpacks/bellsoft-liberica 9.3.2 [INFO]

JPA Infinite recursion (StackOverflowError); nested exception spring boot

Parea evitar que un par de entidades JPA (padre, hijo) genere una recursión infinita al ser utilizadas en un servicio REST, se debe usar las siguientes anotaciones: 

  • @JsonManagedReference 
  • @JsonBackReference annotations.

Entidad Padre


  @Entity
  @Table
  public class User extends CommonBean implements Serializable{
      private static final long serialVersionUID = 1L;

      @Id
      @GeneratedValue
      private long id;

      private String name;

      @Column(name = "lastname")
      private String lastName;

      private String cellphone;
      private String email;
      private String password;

      @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
      @JsonManagedReference
      private List listHouses;

  }

Entidad Hija


	@Entity
	public class House extends CommonBean implements Serializable {

      /**
       * 
       */
      private static final long serialVersionUID = 1L;

      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY  )
      private Long id;

      private String name;
      private String direction;
      private String description;

      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "userId")
      @JsonBackReference
      private User user;
    
  }

Comentarios

Entradas populares de este blog

Create a docker image from a spring boot project

Comandos docker

Kubernetes -Tipos de objetos