Spring
-
[Spring Boot] 가장 쉽게 시작하기 1Java/Spring Framework 2017. 5. 25. 01:22
스프링5.0.0 RC1도 나왔고, 스프링부트2.0.0 M1도 나왔다. 기념으로 spring.io에서 제공하는 방법으로 쉽게 스프링부트 프로젝트를 띄워보자. > 스프링부트 홈페이지 접속 > Quick Start 문단의 start.spring.io 클릭 > Project 종류 (Maven or Gradle), 언어 (Java, Kotlin, Groovy), 스프링부트 버전(현재 1.5.3)를 선택Group, Artifact 이름을 정하고 Dependencies들을 추가해준다. (간단하게 Web만 선택)그리고 Generate Poject 버튼을 클릭 (혹은 Alt + Enter) > 다운 받아진 압축파일을 해제한 뒤, Intellij로 불러와서, DemoApplication의 main 메소드를 실행한다. (단..
-
스프링 입문을 위한 자바 객체지향의 원리와 이해후기/Book Review 2017. 1. 23. 22:26
토비의 스프링 3.1의 1권 1장을 읽고 나서, 내가 아직도 부족하다는 것을 느끼고, 잠들어 있던 이 책을 다시 꺼냈다.자바는 배웠지만 C처럼 쓰는 초보, 스프링을 사용하여 개발은 하지만 정작 자바의 기본은 부족한 개발자 등 많은 이들에게 유용한 것 같다.예전에 이미 한번 읽은터라 훑어가며 다시 읽었다. 필요한 부분만 읽으려고 2장, 4장 이런식으로 띄엄띄엄 읽다가 결국은 완독하고 말았다. 책에서 좋았던 점은 1) T메모리 구조를 보여주면서 static, stack, heap 영역들의 역할과 구조 등을 알려 주는 점2) 상속 부분에서 is a 가 아닌 is a kind of로 설명하는 점3) SOLID, 디자인패턴 등을 간략하고 쉽게 설명하는 점4) 스프링의 삼각형(IoC/DI, AOP, PSA)를 간략..
-
[JUnit] @RunWith, @ContextConfiguration 그리고 @SpringApplicationConfigurationJava/JUnit 2017. 1. 8. 20:59
스프링 JUnit 테스트를 할 때 테스트 클래스 상단에 @RunWith(SpringJUnit4ClassRunner.class)와 @Contextconfiguration({applicationContext 경로})나 @SpringApplicationConfiguration({Config 경로})를 설정해준다. 그냥 따라하면 되긴하지만 왜 그렇게 되는지 궁금하여 찾아봤다. 1. @RunWith javacWhen a class is annotated with @RunWith or extends a class annotated with @RunWith, JUnit will invoke the class it references to run the tests in that class instead of the r..
-
[Spring Boot] Welcome Page 설정Java/Spring Framework 2016. 12. 30. 00:00
Request Mapping으로 최상단 주소 ("/", Welcome Page)로 입력해도 메인 컨트롤러로 forward해주는 방법을 검색해봤다. WebMvcConfigurerAdapter 클래스를 상속한 뒤, addViewControllers 메소드를 오버라이드하여 특정 입력으로 들어오는 URL에 대하여 원하는 URL로 forward 해준다. 이 때 HIGHEST_PRECEDENCE는 내부적으로 Integer.MIN_VALUE인데, 값이 작을수록 우선순위가 높다. @Configuration class DefaultView extends WebMvcConfigurerAdapter{ @Override public void addViewControllers(ViewControllerRegistry regis..
-
[Spring Boot]1.4.2.RELEASE is missing, no dependency information availableJava/Spring Framework 2016. 12. 26. 23:50
책을 따라하던 중 Boot 1.4.2.RELEASE로 한답시고, springloaded의 버전까지 1.4.2로 설정.mvn package를 하는데 다음과 같은 에러가 발생 1.4.2.RELEASE의 dependency를 resolve할 수 없다?? MVN REPOSITORY에서 Springloaded를 검색해보니 최신 버전이 1.2.6.RELEASE!그래서 1.4.2.RELEASE로 되있던 것을 1.2.6.RELEASE로 바꾸니 package 성공! org.springframework springloaded 1.2.6.RELEASE
-
[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..