sirin05137 / CSE364_Project

2 stars 0 forks source link

MongoDB not working (Bean 문제?) #40

Closed yuujinleee closed 3 years ago

yuujinleee commented 3 years ago

ERROR 1 - java.net.ConnectException

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-16 05:17:18.359 ERROR 64562 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'movieDataController' defined in file [/Users/yujinlee/IdeaProjects/CSE364_Project/target/classes/group11/restservice/controller/MovieDataController.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [group11.restservice.controller.MovieDataController]: Constructor threw exception; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]

ulimit -c unlimited https://www.unix.com/hp-ux/106623-ulimit-c-unlimited.html

yuujinleee commented 3 years ago

brew install mongodb-community

image https://stackoverflow.com/questions/57856809/installing-mongodb-with-homebrew

yuujinleee commented 3 years ago

Annotations

@Component Spring에서 관리되는 객체임을 표시하기 위해 사용하는 가장 기본적인 annotation이다. 즉, scan-auto-detection과 dependency injection을 사용하기 위해서 사용되는 가장 기본 어노테이션이다.

@Controller Web MVC 코드에 사용되는 어노테이션이다. @RequestMapping 어노테이션을 해당 어노테이션 밑에서만 사용할 수 있다.

@Repository 다 알고 있듯이 data repository를 나타내는 어노테이션이다. @Repository는 플랫폼 특정 exception을 잡아 Spring의 unchecked exception으로 뱉어내준다. ( PersistenceExceptionTranslationPostProcessor )

@Service 비즈니스 로직이나 respository layer 호출하는 함수에 사용된다. 다른 어노테이션과 다르게 @Component에 추가된 기능은 없다. 하지만 나중에 Spring 측에서 추가적인 exception handling을 해줄 수도 있으니 비즈니스 로직에는 해당 어노테이션을 사용하자.

yuujinleee commented 3 years ago

recoRepository.save(recoData);에서 NullPointerException / BeanInstantiationException

Application yml setting 수정 필요한 것으로 보임

image

Caused by: java.lang.NullPointerException: null Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [group11.restservice.controller.MovieDataController]: Constructor threw exception; nested exception is java.lang.NullPointerException Caused by: java.lang.NullPointerException

image image

yuujinleee commented 3 years ago

왜인지는 모르겠으나, DataSeeder.java 를 분리해서 만들어줬더니 잘 됌 ;; ^^ 해결