spring-project 32

maven could not initialize class org.codehaus.plexus.archiver.jar.jararchiver 발생

기존에 STS에서 정상적으로 실행 되던 Spring boot 프로젝트를 다시 import 하여 실행 하려 하였는데 다음과 같은 오류가 발생하면서 메이븐 빌드가 실패하였다. org.codehaus.plexus.archiver.jar.jararchiver org.codehaus.plexus.archiver.jar.jararchiver java : 11 spring boot : 1.5.8.RELEASE Spring Tool Suite : 4.8.1.RELEASE Spring boot 버전을 2.2.6.RELEASE 로 올려서 해결.

spring-project 2020.11.20

RestTemplate으로 basic auth 를 통한 rest api 사용

Basic auth를 인증으로 사용하고 있는 rest api에 접근 할 때는 아래와 같이 하면 된다. 하지만 BasicAuthenticationInterceptor가 스프링 5.1.1 부터 Deprecated 되었기 때문에 지양하고 org.springframework.http.HttpHeaders#setBasicAuth 를 사용하도록 한다. [AS-IS] RestTemplate restTemplate = new RestTemplate(); String url = "http://domain:port/test"; restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor("id", "pw")); ResponseEntity response = r..

spring-project 2020.01.19

Spring Security Multiple HttpSecurity(Form Login & Http Login)

하나의 프로젝트에서 폼로그인도 되고 Http Login도 되도록 설정을 하려면 다음과 같이 설정을 변경해 주면 된다. Reference 참조 https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#multiple-httpsecurity Spring Security Reference The authenticator is also responsible for retrieving any required user attributes. This is because the permissions on the attributes may depend on the type of authentication being used. For ex..

spring-project 2020.01.19

스프링에서 form submit 으로 가변(멀티) 데이터 받기

form submit으로 정해지지 않은 수의 데이터를 받아야 할 경우가 있다. 간단하게 말하면 화면에서는 같은 name으로 값들을 전달하고 서버에서는 배열로 받는다. 아래와 같은 경우. item1 item2 item3 ...... ...... 화면 체크리스트 항목 체크리스트 항목 체크리스트 항목 서버 @RequestMapping(value = "/checkListRegister", method = RequestMethod.POST) public String checkListRegister(Locale locale, Model mode, CheckList checkList) { log.debug(checkList.toString()); return "/checklist/checkList"; } public..

spring-project 2020.01.10

lombok (롬복) 설치하기.

롬복을 설치해보자. https://projectlombok.org/ 에서 lombok.jar 다운로드 예전에는 java가 path에 잡혀있어서 더블클릭하면 바로 실행. 안잡혀 있다면 CMD 를 실행 한 뒤, java -jar lombok.jar 명령어 입력. (당연히 lombok.jar 다운받은 디렉토리 이동 후 입력) Specify location 선택 후 eclipse or STS 실행 파일 선택 (eclipse.exe or sts.exe) Install / Update 로 설치 eclipse or STS 재시작

spring-project 2020.01.05

spring security 로그인 username 가져오기

첫번째 방법은 SecurityContextHolder를 사용하는 방법 Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String username = authentication.getName(); logger.debug("current username : {}", username); 두번째 방법은 Method 선언에서 Principal 이나 Authentication 에 자동으로 할당 되는 값을 사용하는 방법 @RequestMapping(value = "/list") public String list(Principal principal, ...) { ... } @RequestMapping(valu..

spring-project 2020.01.03

Spring MVC Request 객체는 매번 새로 생성 됨.

스프링 MVC Request 요청이 오면 매번 새로운 객체가 생성 됨. Request 를 2번 요청하여 각각의 객체의 hash값을 보면 다른 걸 확인 할 수 있다. toString() 으로 객체의 hash 값을 보면 다르다. @RequestMapping(value = "/register", method = RequestMethod.POST) public String register(Locale locale, Model model, @ModelAttribute TestRegisterRequest testRegisterRequest) { logger.debug(informationRegisterRequest.toString()); return "redirect:/test/list"; DEBUG 18048 -..

spring-project 2020.01.02