Java/Spring Framework
-
[Spring Security] invalid csrf token 'null' was found on the request parameter '_csrf' or header 'x-csrf-token'Java/Spring Framework 2016. 12. 26. 22:52
Spring Security를 이용하여 로그인을 구현하는데 다음과 같은 에러가 발생했다. CSRF Token이 널이라는거 같은데... 토큰을 넘겨줘야 하나? (참고로 CSRF는 Cross Site Request Forgery의 약자로, 해커가 피해자의 권한으로 누군가 악성 코드를 실행하게 하는 해킹 기법이란다.) 구글링을 해보니 2가지의 방법이 나온다. 첫째. CSRF 기능을 꺼버린다.@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { .... ht..
-
[Spring Boot] A file path that is implicitly relative to the current working directory is not allowed in the database URLJava/Spring Framework 2016. 12. 25. 13:27
Flyway를 사용하기 위해 application.yml을 수정 중,h2 db의 경로 설정 문제로 다음과 같은 에러가 발생 A file path that is implicitly relative to the current working directory is not allowed in the database URL 설정 했던 경로는 spring: datasource: driverClassName: org.h2.Driver url: jdbc:h2:file:/tmp/customer username: sa password: 구글링을 해보니 /로 시작하면 안되고, ~/나 ./로 하라고 한다.~/ 와 ./로 하니 프로젝트 path 바로 하위에 tmp폴더가 생성되고 아래 customer.mv.db가 잘 생성된다. ..
-
[Spring Boot] POST method 한글 깨짐Java/Spring Framework 2016. 12. 25. 00:17
책을 따라 하던 중 웹페이지에서 post로 한글을 작성하면 한글이 깨지는 문제에 다다랐다. 심지어 책에서 한글이 깨질 수 있으니 이렇게 조치 하라고 한 것을 했는데도 한글이 깨졌다. 구글링 중 비슷한 문제를 봤으나 책의 해결책과 크게 다르지 않음 그래서 실험. 1. @Order(Ordered.HIGHEST_PRECEDENCE) 차이 2. 리턴값의 Filter와 CharacterEncodingFilter의 차이 정답은 2번 리턴값이었다. CharacterEncodingFilter로 하면 안되고, Filter로 하니까 깨지지 않고 잘 됨 import javax.servlet.Filter; import org.springframework.context.annotation.Bean; import org.spri..
-
[Spring Boot] java.lang.NoClassDefFoundError: org/unbescape/html/HtmlEscapeJava/Spring Framework 2016. 12. 24. 14:12
책의 예제대로 따라 했으나 다음 화면과, 다음 로그와 같은 에러가 발생 Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.Sat Dec 24 14:08:54 KST 2016There was an unexpected error (type=Internal Server Error, status=500).org/unbescape/html/HtmlEscape java.lang.NoClassDefFoundError: org/unbescape/html/HtmlEscapeat org.thymeleaf.dom.AbstractTextNode.getContent(Abstract..
-
[Spring Boot] Thymeleaf 템플릿 캐시 설정Java/Spring Framework 2016. 12. 24. 13:43
스프링부트의 Thymeleaf 템플릿 결과는 캐싱하는 것이 디폴트 값이다.즉, 개발할 때 Thymeleaf를 수정하고 브라우저를 새로고침하면 바로 반영이 되지 않는다.따라서 개발을 할 때에는 false로 해 주는 것이 재시작 없이 새로고침만으로 반영되게 하는 것이 편하다. application.yml spring: thymeleaf: cache: false application.properties spring.thymeleaf.cache=false
-
org.apache.tomcat.websocket.WsWebSocketContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainerJava/Spring Framework 2016. 7. 25. 23:02
스프링부트책으로 따라하던 중 REST API 서버 실행시 에러가 났다. Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.ClassCastException: org.apache.tomcat.websocket.WsWebSocketContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer 구글링을 해보니 2가지 정도 방법이 있다. 1) pom.xml에서 undertow 제거 기본 maven 프로젝트 생성시 추가..
-
[Spring]Annotation: @Autowired와 @ResourceJava/Spring Framework 2016. 7. 3. 18:37
@Autowired와 @Resource는같은 기능을 하는 어노테이션이다. 하지만 둘에는 차이점이 존재한다. 1. @Autowired는 스프링 프레임워크 어노테이션이다. 그렇기 때문에 스프링을 사용하지 않는 환경에서는 @Resource를 사용해야 한다. 2. @Autowired의 경우 type과 id 가운데 매칭 우선순위는 type이 높다. @Resource는 그 반대. 표로 정리하면 다음과 같다. @Autowired @Resourece 출처(스펙) 스프링 프레임워크 표준 자바 소속 패키지 org.springframework.beans.factory.annotation.Autowired javax.annotation.Resource 빈 검색 방식 byType 먼저. 못 찾으면 byName byName 먼저..