일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Eureka
- reference
- override
- object
- garbagecollection
- Polymorphism
- start()
- 생성자
- string
- concreteclass
- methodArea
- arguments
- value
- 추상클래스
- MSA
- overload
- class
- abstractclass
- hamobee
- hashCode
- super
- constantnumber
- Vector
- eclipse
- ALTER
- Hashtable
- run()
- fuction
- 객체형변환
- 콘크리트클래스
- Today
- Total
뇌운동일지
[ 오늘의 오리발질 ] 오늘도 rest api를 해보려고 했다. 본문
오늘도 시작한다.
이쯤 해보니 왜 책 사서 보는지 알겠다.
사실 나도 책 있음
http://ojc.asia/bbs/board.php?bo_table=LecJpa&wr_id=317
스프링부트(Spring Boot) REST CRUD 이론 및 실습(JPA, MariaDB)
스프링부트(Spring Boot) REST CRUD 이론 및실습(JPA, MariaDB)아래 이미지 깨지는 부분은 PDF 파일 참조 부탁드립니다.감사합니다~6-20-4. Spring Boot REST CRUD 실습(JPA, MariaDB) GitHub : https://github.com/leejongcheol/sprin
ojc.asia
나는 현재 IDE는 vscode
java + gradle + mysql
뭐 이런 환경에서 구현하려고 하고 있다.
mybatis 나 jpa 는 아무거나 되는대로 쓸거임.
책이든 블로그 포스팅이든 내가 원하는 환경과 정확하게 일치하는 예제는 없다.
그래서 적당히 바꿔가면서 하고 있다.
아 그런데 지금은 아침인데 너무 배가 고프다.
따라하고 있음
이번에는 dependency 들을 처음 project 생성시 클릭해서 다 설정했는데
그래서 그런지 인식이 잘 되었다. ㅠㅠ
여기까지도 많은 수확이었다고 생각한다.
예제 코드에서 생성자 주입 안함.
그래서 나는 하기로 함. --> 일단 돌아가는 코드에서 결국 안함. 권장하는 방법 찾아보고 그때가서 내키는대로 결정할 것
생성자 주입 왜 해야하는지 학부때 뭐 배웠던거 같은데 잘 기억이 안난다.
나중에 찾아봐야지.
https://yaboong.github.io/spring/2019/08/29/why-field-injection-is-bad/
스프링 - 생성자 주입을 사용해야 하는 이유, 필드인젝션이 좋지 않은 이유
개요 Dependency Injection (의존관계 주입) 이란 Setter Based Injection (수정자를 통한 주입) Constructor based Injection (생성자를 통한 주입) 스프링에서 사용할 수 있는 DI 방법 세가지 생성자 주입을 이용한 순
yaboong.github.io
예제 코드에서 문제없는 라이브러리 method가 인식이 안될때는 이름이 같은 메소드를 잘못된 경로에서 import 한 것은 아닌지 생각해보자.
코드 작성까지는 문제가 없다.
하지만 실행을 해보면 에러가 뜨지.
이런 에러가 뜬다.
예제에서 MariaDB를 사용했으나, 나는 MySQL 을 사용하고 있기 때문
application.properties 를 수정하러 가자.
spring.datasource.url=jdbc:mysql://localhost:3306/test_crud?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
# 응용프로그램 시작시 마다 새로 테이블 생성
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
이게 원래 application.properties
혹시 나중에 쓸지도 모르니까 일단 적어둠.
https://steemit.com/kr-dev/@igna84/spring-boot-jpa-hibernate-1
Spring boot로 JPA-Hibernate 셋팅(1편) — Steemit
이제 프로젝트를 진행하기 위해 수행하는 작업중에서 절반 정도 마쳤다. 이제 Backend 프로그래밍에서 가장 중요한 DB에서 데이터를 긁어오는 작업이 필요한 시점에 왔다. 기존에 DB에서 데이터를
steemit.com
위의 글을 참고하여
application.properties 다시 작성
그 결과 발생한 에러
이제 그 에러를 해결하러 감.
https://caileb.tistory.com/175
Failed to bind properties under 'spring.datasource.type' to java.lang.Class
에러 Failed to bind properties under 'spring.datasource.type' to java.lang.Class 에러 상세 Description: Failed to bind properties under 'spring.datasource.type' to java.lang.Class : Property..
caileb.tistory.com
현재 spring-boot-starter-data-jpa를 사용하고 있으므로, hikariCP가 자동으로 설정된 상태
application.properties 에서 spring.datasource.type 제거
그러고 실행했더니 이제 그 뭔가 많이 나오는 에러가 생김
하튼 뭔가 더 맞는 방향으로 가고 있다는 뜻
대부분 hibernate, jpa 와 관련된 에러
java — 데이터 소스를 자동 구성하지 못했습니다 : 'spring.datasource.url'이 지정되지 않았습니다.
Mongodb, web, jpa와 같은 종속성을 추가하십시오. 나머지를 삭제/삭제하십시오. org.springframework.boot spring-boot-starter-data-mongodb org.springframework.boot spring-boot-starter-web
www.it-swarm-ko.tech
이거 더 써 넣음 --> 과거의 나야 이거하면 안돼
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
bean 생성안됨.
그래도 어제보단 해결하기 쉬운 문제 같다.
의존성 자동 주입이 안되고 있음.
private EmpRepository empRepository;
@Autowired
public DemoApplication(EmpRepository empRepository ){
this.empRepository = empRepository;
}
@Override
public void run(String... args) throws Exception {
empRepository.save(new Emp(1, "이종철", 9000000));
empRepository.save(new Emp(2, "연개소문", 3000000));
empRepository.save(new Emp(3, "강감찬", 6000000));
empRepository.save(new Emp(4, "이순신", 7000000));
empRepository.save(new Emp(5, "김유신", 2000000));
}
I excluded these code from DemoApplication.class
but there wasn't any difference in result.
메인 메소드에서 빼고 실행했을 때의 결과
설마 내가 생성자 만들겠다고 해서 이러한 오류가 생기고 있는것일까
생성자 다 없애러 가봄
변화 ㄴㄴ 그 문제가 아님.
스프링 빈 설정 오류
오늘도 나는 한번에 안될것을 알고 있었다.
https://bravesuccess.tistory.com/239
Consider defining a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' in your configuration.
오류 메세지 Consider defining a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' in your configuration. 'org.springframework.security.core.userdetails.UserDetailsServi..
bravesuccess.tistory.com
https://jeong-pro.tistory.com/167
Spring boot Bean 생성 순서 정하는 방법, 생성되지 않은 Bean을 주입받으려고 하다가 실패했을 때 해��
Spring boot에서 bean 등록 순서를 결정하는 방법 스프링/스프링부트에서 bean을 등록하는 방법은 여러가지가 있다. 스프링부트에서는 Bean을 등록할 때 자바코드(Annotation)로 등록하는 것을 권장한다.
jeong-pro.tistory.com
또 찾은 괜찮아보이는 아이디어
지금 main 실행했을 때, 가장 먼저 @Autowired 되어있는 EmpRepository 부터 못찾고 있다.
너는 아까 auto configure를 exclude 해서는 안되었다.
친구 dependencies 에 hibernate 관련된게 없어서 그런게 아닐까
creating bean with name entityManagerFactory --
이렇게 내가 정의한 적 없는 bean 부터 생성이 안되는 것은
설정에서부터 오류가 있다는 뜻이다.
I am groot....
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ClassCastException: class org.hibernate.cfg.ImprovedNamingStrategy cannot be cast to class org.hibernate.boot.model.naming.ImplicitNamingStrategy (org.hibernate.cfg.ImprovedNamingStrategy and org.hibernate.boot.model.naming.ImplicitNamingStrategy are in unnamed module of loader 'app')
Caused by: java.lang.ClassCastException: class org.hibernate.cfg.ImprovedNamingStrategy cannot be cast to class org.hibernate.boot.model.naming.ImplicitNamingStrategy (org.hibernate.cfg.ImprovedNamingStrategy and org.hibernate.boot.model.naming.ImplicitNamingStrategy are in unnamed module of loader 'app')
오류는 크게 두가지
욕하고 싶다.
오늘도 나는 그저 restAPI 를 만들어보려고 했었다.
왜 맨날 이런식일까.
# spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.cfg.ImprovedNamingStrategy
# spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
이걸 주석처리해서 위의 문제는 해결함
이제 새로운 문제를 만남.
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
위의 문제는
spring.datasource.url=jdbc:mysql://localhost:3306/test_crud?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
이렇게 바꾸어서 해결
이제 새로운 문제
야 너 그래도 많이 해결함.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoApplication': Unsatisfied dependency expressed through field 'empRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.springbootrest.repository.EmpRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
이러한 문제
bean 생성 순서에 대한 문제가 아닐지 생각하는중
이제는 table creation까지 잘된다.
DemoApplication에서 run 하려니까 될일도 안되는 것 같다.
실행방법을 바꿔보자.
bean 생성 순서 정하겠다고 @Order() 썼는데 해결된거 없음.
DemoApplication.java 처음 프로젝트 기본생성할때 모습으로 바꾸니까
start됨.
그럼 제대로 되었는지 확인해보러 감.
그냥 DemoApplication.java 에서 insert 하려는 시도를 안하니까 잘됨.
아 뭐 해서 되니까 다행이다. 끝
그리고 이것에 대한 실행결과는 여기에
[오리너구리의 오리발질] - [ 비가 그친 오리 ] rest api 실행결과
[ 비가 그친 오리 ] rest api 실행결과
get --> 맨 처음 실행했을때 --> 데이터 몇 개 넣어서 실행했을 때 post update --> update 이전의 데이터 ---> update 실행 후의 데이터 delete --> 존재하지 않는 row를 삭제하려고 하면 이렇게 된다. -..
earlgreybutter.tistory.com
여기서 적당히 error 처리하고 그래야하는거 알고있음.
이러한 크롬 확장프로그램 쓰는게 사실 나는 더 좋음
많이 헤매기는 해도 저는 top-down 방식으로 공부하는 게 좋아요.
bottom-up 으로 기초부터 차근차근 익혀가는 것은 약간 방향성을 못잡겠는 느낌?? 이 있어서.
목적의식 뚜렷하게 가지고 필요한 지식 위주로 습득하는게 그래도 좋음.
'오리너구리의 오리발질' 카테고리의 다른 글
[ 뭐할지 고민하는 오리 ] 책보고 따라하기 (0) | 2020.07.24 |
---|---|
[ 비가 그친 오리 ] rest api 실행결과 (0) | 2020.07.24 |
[ 오늘의 오리 ] 나는 원래 rest api 를 공부하려고 했다. (0) | 2020.07.23 |
[ 오리는 둥둥 ] postman 실행결과 - get (0) | 2020.07.23 |
[ 오리는 둥둥 ]springboot+gradle+vscode (0) | 2020.07.23 |