0

How do I make my pojo classes as components, so that I can autowire wherever I want? What will be the steps to do? Is this the right way for a spring boot application?

In my application iam using lombok for getters and setters. Here is my pojo:

        @Accessors(chain = true)
        @NoArgsConstructor
        @Getter
        @Setter
        @ToString
        @JsonIgnoreProperties(ignoreUnknown = true)
        @SuppressWarnings("all")
        public class Qei implements Serializable {
            private static final long serialVersionUID = 2902444063726917000L;
            private Integer qeiMasterId;
            private String qeiId;
            @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = NMTCConstants.DATEFORMAT)
            private Date originalDate;
            private BigDecimal amount;
            @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = NMTCConstants.DATEFORMAT)
            private Date complianceEndDate;
            private BigDecimal perAllocAgreementPercent;
            private BigDecimal minRequiredPercent;
            private Integer allocationYear;
            private DealDetail dealDetail;// other class
            private List<Qlici> qliciInfo;//other class
        } 

In order to use this class, can it be spring component?

Robert
  • 7,394
  • 40
  • 45
  • 64
Raj
  • 1
  • 2
  • 3
    No that's not a good idea. You should start with learning Spring https://www.baeldung.com/spring-tutorial – Simon Martinelli Apr 16 '20 at 16:49
  • You can do so by adding Component annotation. It also seems that you need a new object every time, so you should also add Prototype annotation. You should read more about Prototype annotation and how to use it. –  Apr 16 '20 at 17:57
  • @AmanGarg Iam using Lombok in my application for creating pojo . and even had DTO's for that classes . How does it work if i make a POJO class has component – Raj Apr 16 '20 at 18:11
  • https://stackoverflow.com/questions/12517905/what-is-java-pojo-class-java-bean-normal-class look at this – GolamMazid Sajib Apr 16 '20 at 18:17

0 Answers0