<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.4.2</version>
</dependency>
(src/main/webapp/WEB-INF/spring/appServlet)
에서 우클릭 후 New - Spring Bean Configuration File 클릭 후 security-context’ 이름의 파일을 ‘benas’와 ‘security’ namespaces를 추가 해준 뒤 생성.<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<bean id="bcryptPasswordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"></bean>
</beans>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/servlet-context.xml
/WEB-INF/spring/appServlet/security-context.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
@Autowired
어노테이션을 이용해서 의존성 주입을 한다. 변수는 자신이 원하는 이름을 작성하면 된다.MemberVO
클래스 타입의 member를 통해 데이터를 받아온다. 회원의 정보가 담긴 member를 매개변수로 한 memberJoin() 메서드를 호출하게 되고 이를 통해 BOOK_MEMBER 테이블에 데이터를 insert하는 쿼리문이 실행된다.회원정보가 담긴 member => memberJoin()을 호출하여 회원가입 쿼리 실행
회원정보가 담긴 member => member에 저장된 비밀번호를 꺼냄 => encode() 메서드를 통해 꺼낸 비밀번호 인코딩 => 인코딩 된 비밀번호를 member 객체에 다시 저장 => memberJoin()을 호출하여 회원가입 쿼리 실행
// 회원가입
@RequestMapping(value = "/join", method = RequestMethod.POST)
public String joinPost(MemberVO member) throws Exception {
logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> join 진입");
String rawPw = ""; // 인코딩 전 비밀번호
String encodePw = ""; // 인코딩 후 비밀번호
return "redirect:/main";
}
String rawPw = ""; // 인코딩 전 비밀번호
String encodePw = ""; // 인코딩 후 비밀번호
rawPw = member.getMemberPw(); // 비밀번호 데이터 얻음
encodePw = pwEncoder.encode(rawPw); // 비밀번호 인코딩
member.setMemberPw(encodePw); // 인코딩된 비밀번호 member객체에 다시 저장
String rawPw = ""; // 인코딩 전 비밀번호
String encodePw = ""; // 인코딩 후 비밀번호
rawPw = member.getMemberPw(); // 비밀번호 데이터 얻음
encodePw = pwEncoder.encode(rawPw); // 비밀번호 인코딩
member.setMemberPw(encodePw); // 인코딩된 비밀번호 member객체에 다시 저장
/* 회원가입 쿼리 실행 */
memberService.memberJoin(member);