cagataygurturk / aws-lambda-java-boilerplate

AWS Lambda JAVA boilerplate code with Spring IoC container
53 stars 27 forks source link

Spring boot JPA not working #3

Open aloysiustany opened 4 years ago

aloysiustany commented 4 years ago

I am trying to use this boilerplate code and use spring JPA to read value from mysql. But the repository interface is not getting initialized.

Sensors.java

@Entity
@Table(name = "SENSOR")
public class Sensors {
    @Id
    private String sensorName;
    private String email;
}

MyRepository.java

@Repository
public interface MyRepository extends CrudRepository<Sensors, Long> {
    Optional<Sensors> findBySensorName(String sensorName);
}

MyService.java

@Service
public class MyService {
     @Autowired
     private MyRepository myRepo;   // THIS IS ALWAYS NULL

     public ResponseDTO handleRequest(RequestDto req) {
          .....
     }
}

Can you help me debug why the repository is not getting autowired ?

yuyuchen09 commented 1 year ago

Hello, I am facing the same issue, have you got this issue resolved yet? I am currently migrating some of our existing DB services (JPA base) running inside a Spring MVC web app as Lambda microservices. I am prototyping loading services beans and JPA jars as dependencies into lambda.