본문 바로가기

트러블 슈팅

웹소켓 프론트랑 연결중 cors 오류 트러블 슈팅 + bean 에러

일단 쓰기전에 욕한번 하고 가겠다.

씨 발

 

1. cors 오류가 떴습니다 

정말 권한을 전부 주었는데도 불구하고 이런에러가 떠서 진짜 고생을했습니다

 

 

해결방법 - 

https://hi0seon.tistory.com/entry/SpringBoot-CORS-%EC%97%90%EB%9F%AC

https://stackoverflow.com/questions/54237851/cors-problems-with-spring-security-and-websocket

첫번째 블로그 글이랑 두번째 stackoverflow가 정말 도움이 많이 되었습니다

이 부분에서 configueration.addAllowedOrigin("*")로 설정을 해주었으나  구글링을 하다가 "allowed-origin 헤더 값을 내 애플리케이션의 URL로 설정해야 한다는 것이었습니다. 자격 증명을 보내는 경우 와일드카드 값(*)은 허용되지 않습니다." 

이 문장을 보고 저 부분을 하나는 제 URL 다른하나는 프론트분 URL로 해서 뚫었더니 cors 연결은 성공하였습니다 .

 

추가)

이거 설정한후에 

이 코드로 (cors 설정을 시큐리티에 맞춘다 ) 이런 느낌의 코드라고 해서 쓰니 바로 성공

 


추가 적으로 

 

 에러내용은 아래와 같다.

Description:​The bean 'createQueryProvider', defined in class path resource [com/example/batch/seokhun/processor/ProcessorConvertJobConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/example/batch/seokhun/Reader/JdbcPagingItemReaderJobConfiguration.class] and overriding is disabled.​Action:​Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true​

 

에러 원인

다른곳에서 이미 해당 bean을 생성해서 중복이 되는현상

 

해결

스프링부트 2.1 부터는 overriding 옵션이 false로 default 설정이 된다고한다. 그래서

Bean Overriding을 활성화 하기 위해 application.properties에 spring.main.allow-bean-definition-overriding: true 옵션 추가하면 정상작동을 하게됩니다.