목록Spring (19)
hrming
@Value 어노테이션 사용 이유: 외부에 노출해서는 안되는 값들을 사용할 때, application.properties와 같은 파일에 보안이 필요한 값들을 넣어두고 .gitignore로 등록하여 외부에 노출되지 않도록 한다.: 이와 같이, application.properties 파일등에 입력된 값을 코드로 가져와서 사용하기 위해 @Value 어노테이션을 사용. 사용 방법 및 주의사항@Value ( "$ { } " ) @Value 어노테이션은 스프링 빈으로 등록을 하고 의존 관계를 주입할 때 동작함. → 해당 객체를 스프링 빈으로 등록해야 함. 참고 및 출처 :https://velog.io/@shawnhansh/SpringBoot-Value-%EC%96%B4%EB%85%B8%ED%85%8C%EC%9..
Spring Security로 로그인한 유저 정보를 가져올 수 있는 방법은 3가지 정도가 있는 것 같다. (하단 출처 참고) 나는 아래와 같이, 전역에 선언된 SecurityContextHolder를 이용해서 로그인 유저 정보를 가져왔다. 😎 Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); UserDetails userDetails = (UserDetails)principal; String username = principal.getUsername(); String password = principal.getPassword(); @GetMapping("/write") public String ..
Spring Security를 Form login 처리 시, ① 화면단에서는 아래처럼 form 태그에 action에 아래와 같이 url을 설정하고 method를 "post"로 설정함 ② 하지만 UserCtrl에는 아래와 같이 GetMapping만 있음 @Controller @RequestMapping("/user") public class UserCtrl { @Autowired private UserService userService; @GetMapping("/login") public String userLogin() { return "login"; } ③ 그럼 위의 form 태그에 있는 'post' 는 어떻게 작동하는거지??? 😡 😡 😡 라는 의문이 생겼다. 구글링해보니, Spring Security..
1. pom.xml - dependencies 추가 With Maven, you need to add two extra entries (one for the application and one for testing) to the element in pom.xml, as the following listing shows: org.springframework.boot spring-boot-starter-security org.thymeleaf.extras thymeleaf-extras-springsecurity6 3.1.1.RELEASE org.springframework.security spring-security-test test 2. WebSecurityConfig Class 생성 The followi..
① Validator 클래스를 작성한 후, ② Controller단에서 BindingResult를 사용해 에러 체크 & 그에 따른 처리 Validation by Using Spring’s Validator Interface The next example provides validation behavior for the Person class by implementing the following two methods of the org.springframework.validation.Validator interface: - supports(Class): Can this Validator validate instances of the supplied Class? - validate(Object, org.sp..
@Component @Component is an annotation that allows Spring to detect our custom beans automatically. In other words, without having to write any explicit code, Spring will: Scan our application for classes annotated with @Component Instantiate them and inject any specified dependencies into them Inject them wherever needed However, most developers prefer to use more specialized stereotype annotat..
예전에 공부할 때, DTO랑 VO의 차이점이 이해가 잘 안갔었는데 아래 블로그에 내용이 잘 정리되어 있는 것 같다. 메모메모 ✏ https://tecoble.techcourse.co.kr/post/2020-06-11-value-object/ VO(Value Ojbect)란 무엇일까? 프로그래밍을 하다 보면 VO라는 이야기를 종종 듣게 된다. VO와 함께 언급되는 개념으로는 Entity, DTO등이 있다. 그리고 더 나아가서는 도메인 주도 설계까지도 함께 언급된다. 이 글에서는 우선 다 tecoble.techcourse.co.kr
Bean : Spring Container가 관리하는 객체 (XML문서를 만들고 그 안에 빈 태그를 사용해서 빈을 정의하면, Spring Container가 이를 읽어들여서 빈에 정의된 클래스 객체를 만듦) : 자바의 객체, Spring container에 의해 자바 객체가 만들어 지게 되면서 이 객체를 스프링 빈이라고 부르게 된것이지만 스프링 빈과 일반 객체와의 차이점은 별다르게 없음. Spring container 에서 만들어지는 객체를 스프링 빈이라고 부를 뿐이다. Spring Bean을 사용하는 이유 자주 사용하는 객체를 singleton으로 만들어 놓고 어디서든 불러쓸 수 있도록 하기 위함. 의존성 주입은 간단히 말해 모듈간의 결합도를 낮추어 클래스를 수정해야하는 상황을 줄여주며 이 과정에서 S..