cache = new HashMap<>();
11 |
12 | public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {
13 | Long num = (Long) joinPoint.getArgs()[0];
14 | if (cache.containsKey(num)) {
15 | System.out.printf("CacheAspect: Cache에서 구함[%d]\n", num);
16 | return cache.get(num);
17 | }
18 |
19 | Object result = joinPoint.proceed();
20 | cache.put(num, result);
21 | System.out.printf("CacheAspect: Cache에 추가[%d]\n", num);
22 | return result;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/sp4-chap03/src/main/java/spring/VersionPrinter.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class VersionPrinter {
4 |
5 | private int majorVersion;
6 | private int minorVersion;
7 |
8 | public VersionPrinter() {
9 | }
10 |
11 | public VersionPrinter(int majorVersion, int minorVersion) {
12 | this.majorVersion = majorVersion;
13 | this.minorVersion = minorVersion;
14 | }
15 |
16 | public void setMajorVersion(int majorVersion) {
17 | this.majorVersion = majorVersion;
18 | }
19 |
20 | public void setMinorVersion(int minorVersion) {
21 | this.minorVersion = minorVersion;
22 | }
23 |
24 | public void print() {
25 | System.out.printf("이 프로그램의 버전은 %d.%d입니다.\n\n",
26 | majorVersion, minorVersion);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/java/controller/LoginCommand.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | public class LoginCommand {
4 |
5 | private String email;
6 | private String password;
7 | private boolean rememberEmail;
8 |
9 | public String getEmail() {
10 | return email;
11 | }
12 |
13 | public void setEmail(String email) {
14 | this.email = email;
15 | }
16 |
17 | public String getPassword() {
18 | return password;
19 | }
20 |
21 | public void setPassword(String password) {
22 | this.password = password;
23 | }
24 |
25 | public boolean isRememberEmail() {
26 | return rememberEmail;
27 | }
28 |
29 | public void setRememberEmail(boolean rememberEmail) {
30 | this.rememberEmail = rememberEmail;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/java/controller/LoginCommand.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | public class LoginCommand {
4 |
5 | private String email;
6 | private String password;
7 | private boolean rememberEmail;
8 |
9 | public String getEmail() {
10 | return email;
11 | }
12 |
13 | public void setEmail(String email) {
14 | this.email = email;
15 | }
16 |
17 | public String getPassword() {
18 | return password;
19 | }
20 |
21 | public void setPassword(String password) {
22 | this.password = password;
23 | }
24 |
25 | public boolean isRememberEmail() {
26 | return rememberEmail;
27 | }
28 |
29 | public void setRememberEmail(boolean rememberEmail) {
30 | this.rememberEmail = rememberEmail;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/java/controller/LoginCommand.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | public class LoginCommand {
4 |
5 | private String email;
6 | private String password;
7 | private boolean rememberEmail;
8 |
9 | public String getEmail() {
10 | return email;
11 | }
12 |
13 | public void setEmail(String email) {
14 | this.email = email;
15 | }
16 |
17 | public String getPassword() {
18 | return password;
19 | }
20 |
21 | public void setPassword(String password) {
22 | this.password = password;
23 | }
24 |
25 | public boolean isRememberEmail() {
26 | return rememberEmail;
27 | }
28 |
29 | public void setRememberEmail(boolean rememberEmail) {
30 | this.rememberEmail = rememberEmail;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/controller/LoginCommand.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | public class LoginCommand {
4 |
5 | private String email;
6 | private String password;
7 | private boolean rememberEmail;
8 |
9 | public String getEmail() {
10 | return email;
11 | }
12 |
13 | public void setEmail(String email) {
14 | this.email = email;
15 | }
16 |
17 | public String getPassword() {
18 | return password;
19 | }
20 |
21 | public void setPassword(String password) {
22 | this.password = password;
23 | }
24 |
25 | public boolean isRememberEmail() {
26 | return rememberEmail;
27 | }
28 |
29 | public void setRememberEmail(boolean rememberEmail) {
30 | this.rememberEmail = rememberEmail;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/sp4-chap07/src/main/java/main/MainXmlPojo.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.support.GenericXmlApplicationContext;
4 |
5 | import chap07.Calculator;
6 |
7 | public class MainXmlPojo {
8 |
9 | public static void main(String[] args) {
10 | GenericXmlApplicationContext ctx =
11 | new GenericXmlApplicationContext("classpath:aopPojo.xml");
12 |
13 | Calculator impeCal = ctx.getBean("impeCal", Calculator.class);
14 | long fiveFact1 = impeCal.factorial(5);
15 | System.out.println("impeCal.factorial(5) = " + fiveFact1);
16 |
17 | Calculator recCal = ctx.getBean("recCal", Calculator.class);
18 | long fiveFact2 = recCal.factorial(5);
19 | System.out.println("recCal.factorial(5) = " + fiveFact2);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/main/MainDevXmlProfile2.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.support.GenericXmlApplicationContext;
4 |
5 | import spring.Member;
6 | import spring.MemberDao;
7 |
8 | public class MainDevXmlProfile2 {
9 |
10 | public static void main(String[] args) {
11 | GenericXmlApplicationContext context = new GenericXmlApplicationContext();
12 | context.getEnvironment().setActiveProfiles("dev");
13 | context.load("classpath:spring-nested-beans.xml");
14 | context.refresh();
15 |
16 | MemberDao memberDao = context.getBean("memberDao", MemberDao.class);
17 |
18 | for (Member m : memberDao.selectAll()) {
19 | System.out.println(m.getEmail());
20 | }
21 |
22 | context.close();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/sp4-chap07/src/main/java/aspect/ExeTimeAspect.java:
--------------------------------------------------------------------------------
1 | package aspect;
2 |
3 | import java.util.Arrays;
4 |
5 | import org.aspectj.lang.ProceedingJoinPoint;
6 | import org.aspectj.lang.Signature;
7 |
8 | public class ExeTimeAspect {
9 |
10 | public Object measure(ProceedingJoinPoint joinPoint) throws Throwable {
11 | long start = System.nanoTime();
12 | try {
13 | Object result = joinPoint.proceed();
14 | return result;
15 | } finally {
16 | long finish = System.nanoTime();
17 | Signature sig = joinPoint.getSignature();
18 | System.out.printf("%s.%s(%s) 실행 시간 : %d ns\n",
19 | joinPoint.getTarget().getClass().getSimpleName(),
20 | sig.getName(), Arrays.toString(joinPoint.getArgs()),
21 | (finish - start));
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/webapp/WEB-INF/view/main.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 |
4 |
5 |
6 | 메인
7 |
8 |
9 |
10 | 환영합니다.
11 |
12 | ">[회원 가입하기]
13 | ">[로그인]
14 |
15 |
16 |
17 |
18 | ${authInfo.name}님, 환영합니다.
19 |
20 | ">[비밀번호 변경]
21 | ">[로그아웃]
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/webapp/WEB-INF/view/main.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 |
4 |
5 |
6 | 메인
7 |
8 |
9 |
10 | 환영합니다.
11 |
12 | ">[회원 가입하기]
13 | ">[로그인]
14 |
15 |
16 |
17 |
18 | ${authInfo.name}님, 환영합니다.
19 |
20 | ">[비밀번호 변경]
21 | ">[로그아웃]
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/webapp/WEB-INF/view/main.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 |
4 |
5 |
6 | 메인
7 |
8 |
9 |
10 | 환영합니다.
11 |
12 | ">[회원 가입하기]
13 | ">[로그인]
14 |
15 |
16 |
17 |
18 | ${authInfo.name}님, 환영합니다.
19 |
20 | ">[비밀번호 변경]
21 | ">[로그아웃]
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/webapp/WEB-INF/view/main.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 |
4 |
5 |
6 | 메인
7 |
8 |
9 |
10 | 환영합니다.
11 |
12 | ">[회원 가입하기]
13 | ">[로그인]
14 |
15 |
16 |
17 |
18 | ${authInfo.name}님, 환영합니다.
19 |
20 | ">[비밀번호 변경]
21 | ">[로그아웃]
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/resources/spring-ds-dev.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/resources/spring-ds-real.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sp4-chap07/src/main/resources/aopAspect.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sp4-chap08/src/main/java/spring/MemberRegisterService.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | public class MemberRegisterService {
8 | private MemberDao memberDao;
9 |
10 | public MemberRegisterService(MemberDao memberDao) {
11 | this.memberDao = memberDao;
12 | }
13 |
14 | @Transactional
15 | public void regist(RegisterRequest req) {
16 | Member member = memberDao.selectByEmail(req.getEmail());
17 | if (member != null) {
18 | throw new AlreadyExistingMemberException("dup email " + req.getEmail());
19 | }
20 | Member newMember = new Member(
21 | req.getEmail(), req.getPassword(), req.getName(),
22 | new Date());
23 | memberDao.insert(newMember);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap11/src/main/java/spring/MemberRegisterService.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | public class MemberRegisterService {
8 | private MemberDao memberDao;
9 |
10 | public MemberRegisterService(MemberDao memberDao) {
11 | this.memberDao = memberDao;
12 | }
13 |
14 | @Transactional
15 | public void regist(RegisterRequest req) {
16 | Member member = memberDao.selectByEmail(req.getEmail());
17 | if (member != null) {
18 | throw new AlreadyExistingMemberException("dup email " + req.getEmail());
19 | }
20 | Member newMember = new Member(
21 | req.getEmail(), req.getPassword(), req.getName(),
22 | new Date());
23 | memberDao.insert(newMember);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/java/spring/MemberRegisterService.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | public class MemberRegisterService {
8 | private MemberDao memberDao;
9 |
10 | public MemberRegisterService(MemberDao memberDao) {
11 | this.memberDao = memberDao;
12 | }
13 |
14 | @Transactional
15 | public void regist(RegisterRequest req) {
16 | Member member = memberDao.selectByEmail(req.getEmail());
17 | if (member != null) {
18 | throw new AlreadyExistingMemberException("dup email " + req.getEmail());
19 | }
20 | Member newMember = new Member(
21 | req.getEmail(), req.getPassword(), req.getName(),
22 | new Date());
23 | memberDao.insert(newMember);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/java/spring/MemberRegisterService.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | public class MemberRegisterService {
8 | private MemberDao memberDao;
9 |
10 | public MemberRegisterService(MemberDao memberDao) {
11 | this.memberDao = memberDao;
12 | }
13 |
14 | @Transactional
15 | public void regist(RegisterRequest req) {
16 | Member member = memberDao.selectByEmail(req.getEmail());
17 | if (member != null) {
18 | throw new AlreadyExistingMemberException("dup email " + req.getEmail());
19 | }
20 | Member newMember = new Member(
21 | req.getEmail(), req.getPassword(), req.getName(),
22 | new Date());
23 | memberDao.insert(newMember);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/java/spring/MemberRegisterService.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | public class MemberRegisterService {
8 | private MemberDao memberDao;
9 |
10 | public MemberRegisterService(MemberDao memberDao) {
11 | this.memberDao = memberDao;
12 | }
13 |
14 | @Transactional
15 | public void regist(RegisterRequest req) {
16 | Member member = memberDao.selectByEmail(req.getEmail());
17 | if (member != null) {
18 | throw new AlreadyExistingMemberException("dup email " + req.getEmail());
19 | }
20 | Member newMember = new Member(
21 | req.getEmail(), req.getPassword(), req.getName(),
22 | new Date());
23 | memberDao.insert(newMember);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/spring/MemberRegisterService.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.transaction.annotation.Transactional;
6 |
7 | public class MemberRegisterService {
8 | private MemberDao memberDao;
9 |
10 | public MemberRegisterService(MemberDao memberDao) {
11 | this.memberDao = memberDao;
12 | }
13 |
14 | @Transactional
15 | public void regist(RegisterRequest req) {
16 | Member member = memberDao.selectByEmail(req.getEmail());
17 | if (member != null) {
18 | throw new AlreadyExistingMemberException("dup email " + req.getEmail());
19 | }
20 | Member newMember = new Member(
21 | req.getEmail(), req.getPassword(), req.getName(),
22 | new Date());
23 | memberDao.insert(newMember);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap11/src/main/resources/spring-controller.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sp4-chap06/src/main/java/spring/Client.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import org.springframework.beans.factory.DisposableBean;
4 | import org.springframework.beans.factory.InitializingBean;
5 |
6 | public class Client implements InitializingBean, DisposableBean {
7 |
8 | private String host;
9 |
10 | public void setHost(String host) {
11 | this.host = host;
12 | System.out.println("Client.setHost() 실행");
13 | }
14 |
15 | @Override
16 | public void afterPropertiesSet() throws Exception {
17 | System.out.println("Client.afterPropertiesSet() 실행");
18 | }
19 |
20 | public void send() {
21 | System.out.println("Client.send() to " + host);
22 | }
23 |
24 | @Override
25 | public void destroy() throws Exception {
26 | System.out.println("Client.destroy() 실행");
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/main/MainDevJavaProfile2.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4 |
5 | import spring.Member;
6 | import spring.MemberDao;
7 | import config.NestedProfileConfig;
8 |
9 | public class MainDevJavaProfile2 {
10 |
11 | public static void main(String[] args) {
12 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
13 | context.getEnvironment().setActiveProfiles("dev");
14 | context.register(NestedProfileConfig.class);
15 | context.refresh();
16 |
17 | MemberDao memberDao = context.getBean("memberDao", MemberDao.class);
18 |
19 | for (Member m : memberDao.selectAll()) {
20 | System.out.println(m.getEmail());
21 | }
22 |
23 | context.close();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/main/MainXmlPropertyFile.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.support.GenericXmlApplicationContext;
4 |
5 | import spring.Member;
6 | import spring.MemberDao;
7 |
8 | public class MainXmlPropertyFile {
9 |
10 | public static void main(String[] args) {
11 | GenericXmlApplicationContext context = new GenericXmlApplicationContext();
12 | context.getEnvironment().setActiveProfiles("dev");
13 | context.load("classpath:spring-member.xml",
14 | "classpath:spring-ds-prop.xml"
15 | );
16 | context.refresh();
17 |
18 | MemberDao memberDao = context.getBean("memberDao", MemberDao.class);
19 |
20 | for (Member m : memberDao.selectAll()) {
21 | System.out.println(m.getEmail());
22 | }
23 |
24 | context.close();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sp4-chap03/src/main/java/assembler/Assembler.java:
--------------------------------------------------------------------------------
1 | package assembler;
2 |
3 | import spring.ChangePasswordService;
4 | import spring.MemberDao;
5 | import spring.MemberRegisterService;
6 |
7 | public class Assembler {
8 |
9 | private MemberDao memberDao;
10 | private MemberRegisterService regSvc;
11 | private ChangePasswordService pwdSvc;
12 |
13 | public Assembler() {
14 | memberDao = new MemberDao();
15 | regSvc = new MemberRegisterService(memberDao);
16 | pwdSvc = new ChangePasswordService(memberDao);
17 | }
18 |
19 | public MemberDao getMemberDao() {
20 | return memberDao;
21 | }
22 |
23 | public MemberRegisterService getMemberRegisterService() {
24 | return regSvc;
25 | }
26 |
27 | public ChangePasswordService getChangePasswordService() {
28 | return pwdSvc;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/resources/message/label.properties:
--------------------------------------------------------------------------------
1 | member.register=회원가입
2 |
3 | term=약관
4 | term.agree=약관동의
5 | next.btn=다음단계
6 |
7 | member.info=회원정보
8 | email=이메일
9 | name=이름
10 | password=비밀번호
11 | password.confirm=비밀번호 확인
12 | register.btn=가입 완료
13 |
14 | register.done={0}님, 회원 가입을 완료했습니다.
15 |
16 | go.main=메인으로 이동
17 |
18 | required=필수항목입니다.
19 | bad.email=이메일이 올바르지 않습니다.
20 | duplicate.email=중복된 이메일입니다.
21 | nomatch.confirmPassword=비밀번호와 확인이 일치하지 않습니다.
22 |
23 | login.title=로그인
24 | login.btn=로그인하기
25 | idPasswordNotMatching=아이디와 비밀번호가 일치하지 않습니다.
26 | login.done=로그인에 성공했습니다.
27 | rememberEmail=이메일 기억하기
28 |
29 | change.pwd.title=비밀번호 변경
30 | currentPassword=현재 비밀번호
31 | newPassword=새 비밀번호
32 | change.btn=변경하기
33 | notMatching.currentPassword=비밀번호를 잘못 입력했습니다.
34 | change.pwd.done=비밀번호를 변경했습니다.
35 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/config/ConfigPartSub.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | import spring.MemberDao;
8 | import spring.MemberInfoPrinter;
9 | import spring.MemberPrinter;
10 |
11 | @Configuration
12 | public class ConfigPartSub {
13 |
14 | @Autowired
15 | private MemberDao memberDao;
16 |
17 | @Bean
18 | public MemberPrinter printer() {
19 | return new MemberPrinter();
20 | }
21 |
22 | @Bean
23 | public MemberInfoPrinter infoPrinter() {
24 | MemberInfoPrinter infoPrinter = new MemberInfoPrinter();
25 | infoPrinter.setMemberDao(memberDao);
26 | infoPrinter.setPrinter(printer());
27 | return infoPrinter;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/config/JavaMainConf.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.context.annotation.ImportResource;
7 |
8 | import spring.MemberDao;
9 | import spring.MemberPrinter;
10 | import spring.MemberRegisterService;
11 |
12 | @Configuration
13 | @ImportResource("classpath:sub-conf.xml")
14 | public class JavaMainConf {
15 |
16 | @Autowired
17 | private MemberDao memberDao;
18 |
19 | @Bean
20 | public MemberPrinter memberPrinter() {
21 | return new MemberPrinter();
22 | }
23 |
24 | @Bean
25 | public MemberRegisterService memberRegSvc() {
26 | return new MemberRegisterService(memberDao);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/main/MainDevXmlProfile1.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.support.GenericXmlApplicationContext;
4 |
5 | import spring.Member;
6 | import spring.MemberDao;
7 |
8 | public class MainDevXmlProfile1 {
9 |
10 | public static void main(String[] args) {
11 | GenericXmlApplicationContext context = new GenericXmlApplicationContext();
12 | context.getEnvironment().setActiveProfiles("dev");
13 | context.load("classpath:spring-member.xml",
14 | "classpath:spring-ds-dev.xml",
15 | "classpath:spring-ds-real.xml"
16 | );
17 | context.refresh();
18 |
19 | MemberDao memberDao = context.getBean("memberDao", MemberDao.class);
20 |
21 | for (Member m : memberDao.selectAll()) {
22 | System.out.println(m.getEmail());
23 | }
24 |
25 | context.close();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/main/MainJavaPropertyFile.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4 |
5 | import spring.Member;
6 | import spring.MemberDao;
7 | import config.DsPropConfig;
8 | import config.MemberConfig;
9 |
10 | public class MainJavaPropertyFile {
11 |
12 | public static void main(String[] args) {
13 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
14 | context.getEnvironment().setActiveProfiles("dev");
15 | context.register(MemberConfig.class, DsPropConfig.class);
16 | context.refresh();
17 |
18 | MemberDao memberDao = context.getBean("memberDao", MemberDao.class);
19 |
20 | for (Member m : memberDao.selectAll()) {
21 | System.out.println(m.getEmail());
22 | }
23 |
24 | context.close();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/java/interceptor/AuthCheckInterceptor.java:
--------------------------------------------------------------------------------
1 | package interceptor;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 | import javax.servlet.http.HttpSession;
6 |
7 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
8 |
9 | public class AuthCheckInterceptor extends HandlerInterceptorAdapter {
10 |
11 | @Override
12 | public boolean preHandle(HttpServletRequest request,
13 | HttpServletResponse response, Object handler) throws Exception {
14 | HttpSession session = request.getSession(false);
15 | if (session != null) {
16 | Object authInfo = session.getAttribute("authInfo");
17 | if (authInfo != null) {
18 | return true;
19 | }
20 | }
21 | response.sendRedirect(request.getContextPath()+"/login");
22 | return false;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/java/interceptor/AuthCheckInterceptor.java:
--------------------------------------------------------------------------------
1 | package interceptor;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 | import javax.servlet.http.HttpSession;
6 |
7 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
8 |
9 | public class AuthCheckInterceptor extends HandlerInterceptorAdapter {
10 |
11 | @Override
12 | public boolean preHandle(HttpServletRequest request,
13 | HttpServletResponse response, Object handler) throws Exception {
14 | HttpSession session = request.getSession(false);
15 | if (session != null) {
16 | Object authInfo = session.getAttribute("authInfo");
17 | if (authInfo != null) {
18 | return true;
19 | }
20 | }
21 | response.sendRedirect(request.getContextPath()+"/login");
22 | return false;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/java/interceptor/AuthCheckInterceptor.java:
--------------------------------------------------------------------------------
1 | package interceptor;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 | import javax.servlet.http.HttpSession;
6 |
7 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
8 |
9 | public class AuthCheckInterceptor extends HandlerInterceptorAdapter {
10 |
11 | @Override
12 | public boolean preHandle(HttpServletRequest request,
13 | HttpServletResponse response, Object handler) throws Exception {
14 | HttpSession session = request.getSession(false);
15 | if (session != null) {
16 | Object authInfo = session.getAttribute("authInfo");
17 | if (authInfo != null) {
18 | return true;
19 | }
20 | }
21 | response.sendRedirect(request.getContextPath()+"/login");
22 | return false;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/interceptor/AuthCheckInterceptor.java:
--------------------------------------------------------------------------------
1 | package interceptor;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 | import javax.servlet.http.HttpSession;
6 |
7 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
8 |
9 | public class AuthCheckInterceptor extends HandlerInterceptorAdapter {
10 |
11 | @Override
12 | public boolean preHandle(HttpServletRequest request,
13 | HttpServletResponse response, Object handler) throws Exception {
14 | HttpSession session = request.getSession(false);
15 | if (session != null) {
16 | Object authInfo = session.getAttribute("authInfo");
17 | if (authInfo != null) {
18 | return true;
19 | }
20 | }
21 | response.sendRedirect(request.getContextPath()+"/login");
22 | return false;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/resources/message/label.properties:
--------------------------------------------------------------------------------
1 | member.register=회원가입
2 |
3 | term=약관
4 | term.agree=약관동의
5 | next.btn=다음단계
6 |
7 | member.info=회원정보
8 | email=이메일
9 | name=이름
10 | password=비밀번호
11 | password.confirm=비밀번호 확인
12 | register.btn=가입 완료
13 |
14 | register.done={0}님, 회원 가입을 완료했습니다.
15 |
16 | go.main=메인으로 이동
17 |
18 | required=필수항목입니다.
19 | bad.email=이메일이 올바르지 않습니다.
20 | duplicate.email=중복된 이메일입니다.
21 | nomatch.confirmPassword=비밀번호와 확인이 일치하지 않습니다.
22 |
23 | login.title=로그인
24 | login.btn=로그인하기
25 | idPasswordNotMatching=아이디와 비밀번호가 일치하지 않습니다.
26 | login.done=로그인에 성공했습니다.
27 | rememberEmail=이메일 기억하기
28 |
29 | change.pwd.title=비밀번호 변경
30 | currentPassword=현재 비밀번호
31 | newPassword=새 비밀번호
32 | change.btn=변경하기
33 | notMatching.currentPassword=비밀번호를 잘못 입력했습니다.
34 | change.pwd.done=비밀번호를 변경했습니다.
35 |
36 | typeMismatch.java.util.Date=잘못된 형식
37 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/resources/message/label.properties:
--------------------------------------------------------------------------------
1 | member.register=회원가입
2 |
3 | term=약관
4 | term.agree=약관동의
5 | next.btn=다음단계
6 |
7 | member.info=회원정보
8 | email=이메일
9 | name=이름
10 | password=비밀번호
11 | password.confirm=비밀번호 확인
12 | register.btn=가입 완료
13 |
14 | register.done={0}님, 회원 가입을 완료했습니다.
15 |
16 | go.main=메인으로 이동
17 |
18 | required=필수항목입니다.
19 | bad.email=이메일이 올바르지 않습니다.
20 | duplicate.email=중복된 이메일입니다.
21 | nomatch.confirmPassword=비밀번호와 확인이 일치하지 않습니다.
22 |
23 | login.title=로그인
24 | login.btn=로그인하기
25 | idPasswordNotMatching=아이디와 비밀번호가 일치하지 않습니다.
26 | login.done=로그인에 성공했습니다.
27 | rememberEmail=이메일 기억하기
28 |
29 | change.pwd.title=비밀번호 변경
30 | currentPassword=현재 비밀번호
31 | newPassword=새 비밀번호
32 | change.btn=변경하기
33 | notMatching.currentPassword=비밀번호를 잘못 입력했습니다.
34 | change.pwd.done=비밀번호를 변경했습니다.
35 |
36 | typeMismatch.java.util.Date=잘못된 형식
37 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/resources/message/label.properties:
--------------------------------------------------------------------------------
1 | member.register=회원가입
2 |
3 | term=약관
4 | term.agree=약관동의
5 | next.btn=다음단계
6 |
7 | member.info=회원정보
8 | email=이메일
9 | name=이름
10 | password=비밀번호
11 | password.confirm=비밀번호 확인
12 | register.btn=가입 완료
13 |
14 | register.done={0}님, 회원 가입을 완료했습니다.
15 |
16 | go.main=메인으로 이동
17 |
18 | required=필수항목입니다.
19 | bad.email=이메일이 올바르지 않습니다.
20 | duplicate.email=중복된 이메일입니다.
21 | nomatch.confirmPassword=비밀번호와 확인이 일치하지 않습니다.
22 |
23 | login.title=로그인
24 | login.btn=로그인하기
25 | idPasswordNotMatching=아이디와 비밀번호가 일치하지 않습니다.
26 | login.done=로그인에 성공했습니다.
27 | rememberEmail=이메일 기억하기
28 |
29 | change.pwd.title=비밀번호 변경
30 | currentPassword=현재 비밀번호
31 | newPassword=새 비밀번호
32 | change.btn=변경하기
33 | notMatching.currentPassword=비밀번호를 잘못 입력했습니다.
34 | change.pwd.done=비밀번호를 변경했습니다.
35 |
36 | typeMismatch.java.util.Date=잘못된 형식
37 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/spring/MemberRegisterService.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | import javax.annotation.Resource;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 |
9 | public class MemberRegisterService {
10 | private MemberDao memberDao;
11 |
12 | @Autowired
13 | public MemberRegisterService(MemberDao memberDao) {
14 | this.memberDao = memberDao;
15 | }
16 |
17 | public MemberRegisterService() {
18 | }
19 |
20 | public void regist(RegisterRequest req) {
21 | Member member = memberDao.selectByEmail(req.getEmail());
22 | if (member != null) {
23 | throw new AlreadyExistingMemberException("dup email " + req.getEmail());
24 | }
25 | Member newMember = new Member(
26 | req.getEmail(), req.getPassword(), req.getName(),
27 | new Date());
28 | memberDao.insert(newMember);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/config/JavaConfig2.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import spring.MemberDao;
7 | import spring.MemberInfoPrinter;
8 | import spring.MemberPrinter;
9 | import spring.MemberRegisterService;
10 |
11 | @Configuration
12 | public class JavaConfig2 {
13 |
14 | @Bean
15 | public MemberDao memberDao() {
16 | return new MemberDao();
17 | }
18 |
19 | @Bean
20 | public MemberRegisterService memberRegSvc() {
21 | return new MemberRegisterService(memberDao());
22 | }
23 |
24 | @Bean
25 | public MemberPrinter printer() {
26 | return new MemberPrinter();
27 | }
28 |
29 | @Bean
30 | public MemberInfoPrinter infoPrinter() {
31 | MemberInfoPrinter infoPrinter = new MemberInfoPrinter();
32 | return infoPrinter;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/resources/main-conf.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/webapp/WEB-INF/view/edit/changePwdForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
22 |
23 | ">
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/webapp/WEB-INF/view/edit/changePwdForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
22 |
23 | ">
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/webapp/WEB-INF/view/edit/changePwdForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
22 |
23 | ">
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/webapp/WEB-INF/view/edit/changePwdForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
16 |
17 |
18 |
22 |
23 | ">
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/main/MainDevJavaProfile1.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4 |
5 | import spring.Member;
6 | import spring.MemberDao;
7 | import config.DsDevConfig;
8 | import config.DsRealConfig;
9 | import config.MemberConfig;
10 |
11 | public class MainDevJavaProfile1 {
12 |
13 | public static void main(String[] args) {
14 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
15 | context.getEnvironment().setActiveProfiles("dev");
16 | context.register(MemberConfig.class, DsDevConfig.class, DsRealConfig.class);
17 | context.refresh();
18 |
19 | MemberDao memberDao = context.getBean("memberDao", MemberDao.class);
20 |
21 | for (Member m : memberDao.selectAll()) {
22 | System.out.println(m.getEmail());
23 | }
24 |
25 | context.close();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/resources/appCtx1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/config/DsDevConfig.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import java.beans.PropertyVetoException;
4 |
5 | import javax.sql.DataSource;
6 |
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.context.annotation.Profile;
10 |
11 | import com.mchange.v2.c3p0.ComboPooledDataSource;
12 |
13 | @Configuration
14 | @Profile("dev")
15 | public class DsDevConfig {
16 |
17 | @Bean
18 | public DataSource dataSource() {
19 | ComboPooledDataSource ds = new ComboPooledDataSource();
20 | try {
21 | ds.setDriverClass("com.mysql.jdbc.Driver");
22 | } catch (PropertyVetoException e) {
23 | throw new RuntimeException(e);
24 | }
25 | ds.setJdbcUrl("jdbc:mysql://localhost/spring4fs?characterEncoding=utf8");
26 | ds.setUser("spring4");
27 | ds.setPassword("spring4");
28 | return ds;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/config/DsRealConfig.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import java.beans.PropertyVetoException;
4 |
5 | import javax.sql.DataSource;
6 |
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.context.annotation.Profile;
10 |
11 | import com.mchange.v2.c3p0.ComboPooledDataSource;
12 |
13 | @Configuration
14 | @Profile("real")
15 | public class DsRealConfig {
16 |
17 | @Bean
18 | public DataSource dataSource() {
19 | ComboPooledDataSource ds = new ComboPooledDataSource();
20 | try {
21 | ds.setDriverClass("com.mysql.jdbc.Driver");
22 | } catch (PropertyVetoException e) {
23 | throw new RuntimeException(e);
24 | }
25 | ds.setJdbcUrl("jdbc:mysql://realhost/realdb?characterEncoding=utf8");
26 | ds.setUser("realuser");
27 | ds.setPassword("realpw");
28 | return ds;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/main/Main4.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.GenericXmlApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 |
9 | public class Main4 {
10 |
11 | public static void main(String[] args) {
12 | // MemberRegisterService가 정상 동작하려면 다음의 세 가지 필요
13 | // 1. MemberRegisterService 생성자의 @Autowired의 required 값을 false로 지정
14 | // 2. MemberInfoPrinter의 memDao 필드의 @Autowired의 required 값을 false로 지정
15 | // 3. MemberInfoPrinter 클래스의 setPrinter() 메서드에 추가한 @Qualifier("sysout") 코드 삭제
16 | ApplicationContext ctx = new GenericXmlApplicationContext("classpath:appCtx4.xml");
17 | MemberRegisterService regSvc = ctx.getBean("memberRegSvc", MemberRegisterService.class);
18 | MemberInfoPrinter infoPrinter = ctx.getBean("infoPrinter", MemberInfoPrinter.class);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/spring/MemberInfoPrinter.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import javax.annotation.Resource;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.beans.factory.annotation.Qualifier;
7 |
8 | public class MemberInfoPrinter {
9 |
10 | @Autowired
11 | private MemberDao memDao;
12 | private MemberPrinter printer;
13 |
14 | public void setMemberDao(MemberDao memberDao) {
15 | this.memDao = memberDao;
16 | }
17 |
18 | @Autowired
19 | //@Qualifier("sysout")
20 | public void setPrinter(MemberPrinter printer) {
21 | System.out.println("setPrinter: " + printer);
22 | this.printer = printer;
23 | }
24 |
25 | public void printMemberInfo(String email) {
26 | Member member = memDao.selectByEmail(email);
27 | if (member == null) {
28 | System.out.println("데이터 없음\n");
29 | return;
30 | }
31 | printer.print(member);
32 | System.out.println();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/resources/appCtx5.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/config/ConfigPart2.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | import spring.MemberDao;
8 | import spring.MemberInfoPrinter;
9 | import spring.MemberPrinter;
10 |
11 | @Configuration
12 | public class ConfigPart2 {
13 |
14 | @Autowired
15 | private MemberDao memberDao;
16 |
17 | // @Autowired
18 | // private ConfigPart1 configPart1;
19 |
20 | @Bean
21 | public MemberPrinter printer() {
22 | return new MemberPrinter();
23 | }
24 |
25 | @Bean
26 | public MemberInfoPrinter infoPrinter() {
27 | MemberInfoPrinter infoPrinter = new MemberInfoPrinter();
28 | infoPrinter.setMemberDao(memberDao);
29 | //infoPrinter.setMemberDao(configPart1.memberDao());
30 | infoPrinter.setPrinter(printer());
31 | return infoPrinter;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/config/JavaConfig.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import spring.MemberDao;
7 | import spring.MemberInfoPrinter;
8 | import spring.MemberPrinter;
9 | import spring.MemberRegisterService;
10 |
11 | @Configuration
12 | public class JavaConfig {
13 |
14 | @Bean
15 | public MemberDao memberDao() {
16 | return new MemberDao();
17 | }
18 |
19 | @Bean
20 | public MemberRegisterService memberRegSvc() {
21 | return new MemberRegisterService(memberDao());
22 | }
23 |
24 | @Bean
25 | public MemberPrinter printer() {
26 | return new MemberPrinter();
27 | }
28 |
29 | @Bean
30 | public MemberInfoPrinter infoPrinter() {
31 | MemberInfoPrinter infoPrinter = new MemberInfoPrinter();
32 | infoPrinter.setMemberDao(memberDao());
33 | infoPrinter.setPrinter(printer());
34 | return infoPrinter;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/resources/appCtx2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/resources/spring-ds-prop.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/main/Main.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.GenericXmlApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 |
10 | public class Main {
11 |
12 | public static void main(String[] args) {
13 | ApplicationContext ctx = new GenericXmlApplicationContext("classpath:appCtx1.xml");
14 | MemberRegisterService regSvc = ctx.getBean("memberRegSvc", MemberRegisterService.class);
15 | MemberInfoPrinter infoPrinter = ctx.getBean("infoPrinter", MemberInfoPrinter.class);
16 |
17 | RegisterRequest regReq = new RegisterRequest();
18 | regReq.setEmail("madvirus@madvirus.net");
19 | regReq.setName("최범균");
20 | regReq.setPassword("1234");
21 | regReq.setConfirmPassword("1234");
22 | regSvc.regist(regReq);
23 |
24 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sp4-chap02/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 | sp4
8 | sp4-chap02
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 |
13 | org.springframework
14 | spring-context
15 | 4.1.0.RELEASE
16 |
17 |
18 |
19 |
20 |
21 |
22 | maven-compiler-plugin
23 | 3.1
24 |
25 | 1.7
26 | 1.7
27 | utf-8
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/sp4-chap03/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 | sp4
8 | sp4-chap03
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 |
13 | org.springframework
14 | spring-context
15 | 4.1.0.RELEASE
16 |
17 |
18 |
19 |
20 |
21 |
22 | maven-compiler-plugin
23 | 3.1
24 |
25 | 1.7
26 | 1.7
27 | utf-8
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/sp4-chap04/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 | sp4
8 | sp4-chap04
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 |
13 | org.springframework
14 | spring-context
15 | 4.1.0.RELEASE
16 |
17 |
18 |
19 |
20 |
21 |
22 | maven-compiler-plugin
23 | 3.1
24 |
25 | 1.7
26 | 1.7
27 | utf-8
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/resources/appCtx3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/resources/appCtx4.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
20 |
21 |
--------------------------------------------------------------------------------
/sp4-chap05/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 | sp4
8 | sp4-chap05
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 |
13 | org.springframework
14 | spring-context
15 | 4.1.0.RELEASE
16 |
17 |
18 |
19 |
20 |
21 |
22 | maven-compiler-plugin
23 | 3.1
24 |
25 | 1.7
26 | 1.7
27 | utf-8
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/sp4-chap06/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | 4.0.0
7 | sp4
8 | sp4-chap06
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 |
13 | org.springframework
14 | spring-context
15 | 4.1.0.RELEASE
16 |
17 |
18 |
19 |
20 |
21 |
22 | maven-compiler-plugin
23 | 3.1
24 |
25 | 1.7
26 | 1.7
27 | utf-8
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/config/JavaConfig3.java:
--------------------------------------------------------------------------------
1 | package config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import spring.MemberDao;
7 | import spring.MemberInfoPrinter;
8 | import spring.MemberPrinter;
9 | import spring.MemberRegisterService;
10 |
11 | @Configuration
12 | public class JavaConfig3 {
13 |
14 | @Bean
15 | public MemberDao memberDao() {
16 | return new MemberDao();
17 | }
18 |
19 | @Bean
20 | public MemberRegisterService memberRegSvc(MemberDao memDao) {
21 | return new MemberRegisterService(memDao);
22 | }
23 |
24 | @Bean
25 | public MemberPrinter printer() {
26 | return new MemberPrinter();
27 | }
28 |
29 | @Bean
30 | public MemberInfoPrinter infoPrinter(MemberDao memDao, MemberPrinter memPrinter) {
31 | MemberInfoPrinter infoPrinter = new MemberInfoPrinter();
32 | infoPrinter.setMemberDao(memDao);
33 | infoPrinter.setPrinter(memPrinter);
34 | return infoPrinter;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/sp4-chap08/src/main/java/main/MainForCPS.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.support.AbstractApplicationContext;
4 | import org.springframework.context.support.GenericXmlApplicationContext;
5 |
6 | import spring.ChangePasswordService;
7 | import spring.IdPasswordNotMatchingException;
8 | import spring.MemberNotFoundException;
9 |
10 | public class MainForCPS {
11 |
12 | public static void main(String[] args) {
13 | AbstractApplicationContext ctx =
14 | new GenericXmlApplicationContext("classpath:appCtx.xml");
15 |
16 | ChangePasswordService cps =
17 | ctx.getBean("changePwdSvc", ChangePasswordService.class);
18 | try {
19 | cps.changePassword("madvirus@madvirus.net", "1234", "1111");
20 | System.out.println("암호를 변경했습니다.");
21 | } catch (MemberNotFoundException e) {
22 | System.out.println("회원 데이터가 존재하지 않습니다.");
23 | } catch (IdPasswordNotMatchingException e) {
24 | System.out.println("암호가 올바르지 않습니다.");
25 | }
26 |
27 | ctx.close();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/resources/spring-mvc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 | message.label
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/webapp/WEB-INF/view/login/loginForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
19 |
23 |
24 |
25 |
28 |
29 | ">
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/resources/spring-mvc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 | message.label
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/webapp/WEB-INF/view/login/loginForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
19 |
23 |
24 |
25 |
28 |
29 | ">
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/webapp/WEB-INF/view/login/loginForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
19 |
23 |
24 |
25 |
28 |
29 | ">
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/resources/spring-mvc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 | message.label
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/webapp/WEB-INF/view/login/loginForm.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
19 |
23 |
24 |
25 |
28 |
29 | ">
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sp4-chap03/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap08/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap11/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/spring/RegisterRequest.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | public class RegisterRequest {
4 |
5 | private String email;
6 | private String password;
7 | private String confirmPassword;
8 | private String name;
9 |
10 | public String getEmail() {
11 | return email;
12 | }
13 |
14 | public void setEmail(String email) {
15 | this.email = email;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | public String getConfirmPassword() {
27 | return confirmPassword;
28 | }
29 |
30 | public void setConfirmPassword(String confirmPassword) {
31 | this.confirmPassword = confirmPassword;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isPasswordEqualToConfirmPassword() {
43 | return password.equals(confirmPassword);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/main/Main.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 | import config.JavaConfig;
10 |
11 | public class Main {
12 |
13 | public static void main(String[] args) {
14 | ApplicationContext ctx =
15 | new AnnotationConfigApplicationContext(JavaConfig.class);
16 | MemberRegisterService regSvc =
17 | ctx.getBean("memberRegSvc", MemberRegisterService.class);
18 | MemberInfoPrinter infoPrinter =
19 | ctx.getBean("infoPrinter", MemberInfoPrinter.class);
20 |
21 | RegisterRequest regReq = new RegisterRequest();
22 | regReq.setEmail("madvirus@madvirus.net");
23 | regReq.setName("최범균");
24 | regReq.setPassword("1234");
25 | regReq.setConfirmPassword("1234");
26 | regSvc.regist(regReq);
27 |
28 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap07/src/main/java/aspect/ExeTimeAspect2.java:
--------------------------------------------------------------------------------
1 | package aspect;
2 |
3 | import java.util.Arrays;
4 |
5 | import org.aspectj.lang.ProceedingJoinPoint;
6 | import org.aspectj.lang.Signature;
7 | import org.aspectj.lang.annotation.Around;
8 | import org.aspectj.lang.annotation.Aspect;
9 | import org.aspectj.lang.annotation.Pointcut;
10 |
11 | @Aspect
12 | public class ExeTimeAspect2 {
13 |
14 | @Pointcut("execution(public * chap07..*(..))")
15 | private void publicTarget() {
16 | }
17 |
18 | @Around("publicTarget()")
19 | public Object measure(ProceedingJoinPoint joinPoint) throws Throwable {
20 | long start = System.nanoTime();
21 | try {
22 | Object result = joinPoint.proceed();
23 | return result;
24 | } finally {
25 | long finish = System.nanoTime();
26 | Signature sig = joinPoint.getSignature();
27 | System.out.printf("%s.%s(%s) 실행 시간 : %d ns\n",
28 | joinPoint.getTarget().getClass().getSimpleName(),
29 | sig.getName(), Arrays.toString(joinPoint.getArgs()),
30 | (finish - start));
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/sp4-chap08/src/main/java/main/MainForJC.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4 | import org.springframework.context.support.AbstractApplicationContext;
5 |
6 | import spring.ChangePasswordService;
7 | import spring.IdPasswordNotMatchingException;
8 | import spring.MemberNotFoundException;
9 | import config.AppConfig;
10 |
11 | public class MainForJC {
12 |
13 | public static void main(String[] args) {
14 | AbstractApplicationContext ctx =
15 | new AnnotationConfigApplicationContext(AppConfig.class);
16 |
17 | ChangePasswordService cps =
18 | ctx.getBean("changePwdSvc", ChangePasswordService.class);
19 | try {
20 | cps.changePassword("madvirus@madvirus.net", "1234", "1111");
21 | System.out.println("암호를 변경했습니다.");
22 | } catch (MemberNotFoundException e) {
23 | System.out.println("회원 데이터가 존재하지 않습니다.");
24 | } catch (IdPasswordNotMatchingException e) {
25 | System.out.println("암호가 올바르지 않습니다.");
26 | }
27 |
28 | ctx.close();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/main/Main3.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 | import config.JavaConfig3;
10 |
11 | public class Main3 {
12 |
13 | public static void main(String[] args) {
14 | ApplicationContext ctx =
15 | new AnnotationConfigApplicationContext(JavaConfig3.class);
16 | MemberRegisterService regSvc =
17 | ctx.getBean("memberRegSvc", MemberRegisterService.class);
18 | MemberInfoPrinter infoPrinter =
19 | ctx.getBean("infoPrinter", MemberInfoPrinter.class);
20 |
21 | RegisterRequest regReq = new RegisterRequest();
22 | regReq.setEmail("madvirus@madvirus.net");
23 | regReq.setName("최범균");
24 | regReq.setPassword("1234");
25 | regReq.setConfirmPassword("1234");
26 | regSvc.regist(regReq);
27 |
28 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/main/MainJavaXml.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 | import config.JavaMainConf;
10 |
11 | public class MainJavaXml {
12 |
13 | public static void main(String[] args) {
14 | ApplicationContext ctx =
15 | new AnnotationConfigApplicationContext(JavaMainConf.class);
16 | MemberRegisterService regSvc =
17 | ctx.getBean("memberRegSvc", MemberRegisterService.class);
18 | MemberInfoPrinter infoPrinter =
19 | ctx.getBean("infoPrinter", MemberInfoPrinter.class);
20 |
21 | RegisterRequest regReq = new RegisterRequest();
22 | regReq.setEmail("madvirus@madvirus.net");
23 | regReq.setName("최범균");
24 | regReq.setPassword("1234");
25 | regReq.setConfirmPassword("1234");
26 | regSvc.regist(regReq);
27 |
28 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/main/MainTwoConfs2.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 | import config.ConfigPartMain;
10 |
11 | public class MainTwoConfs2 {
12 |
13 | public static void main(String[] args) {
14 | ApplicationContext ctx =
15 | new AnnotationConfigApplicationContext(ConfigPartMain.class);
16 | MemberRegisterService regSvc =
17 | ctx.getBean("memberRegSvc", MemberRegisterService.class);
18 | MemberInfoPrinter infoPrinter =
19 | ctx.getBean("infoPrinter", MemberInfoPrinter.class);
20 |
21 | RegisterRequest regReq = new RegisterRequest();
22 | regReq.setEmail("madvirus@madvirus.net");
23 | regReq.setName("최범균");
24 | regReq.setPassword("1234");
25 | regReq.setConfirmPassword("1234");
26 | regSvc.regist(regReq);
27 |
28 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/main/Main3.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.GenericXmlApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 |
10 | public class Main3 {
11 |
12 | public static void main(String[] args) {
13 | // 이 코드를 정상적으로 실행하면 다음의 코드 변경 필요
14 | // 1. MemberInfoPrinter 클래스의 setPrinter() 메서드에 @Qualifier("sysout") 코드 추가
15 | ApplicationContext ctx = new GenericXmlApplicationContext("classpath:appCtx3.xml");
16 | MemberRegisterService regSvc = ctx.getBean("memberRegSvc", MemberRegisterService.class);
17 | MemberInfoPrinter infoPrinter = ctx.getBean("infoPrinter", MemberInfoPrinter.class);
18 |
19 | RegisterRequest regReq = new RegisterRequest();
20 | regReq.setEmail("madvirus@madvirus.net");
21 | regReq.setName("최범균");
22 | regReq.setPassword("1234");
23 | regReq.setConfirmPassword("1234");
24 | regSvc.regist(regReq);
25 |
26 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sp4-chap03/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/main/Main2.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 | import config.JavaConfig2;
10 |
11 | public class Main2 {
12 | // MemberInfoPrinter의 set 메서드에 @Autowired 적용해야 정상 동작
13 | public static void main(String[] args) {
14 | ApplicationContext ctx =
15 | new AnnotationConfigApplicationContext(JavaConfig2.class);
16 | MemberRegisterService regSvc =
17 | ctx.getBean("memberRegSvc", MemberRegisterService.class);
18 | MemberInfoPrinter infoPrinter =
19 | ctx.getBean("infoPrinter", MemberInfoPrinter.class);
20 |
21 | RegisterRequest regReq = new RegisterRequest();
22 | regReq.setEmail("madvirus@madvirus.net");
23 | regReq.setName("최범균");
24 | regReq.setPassword("1234");
25 | regReq.setConfirmPassword("1234");
26 | regSvc.regist(regReq);
27 |
28 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/sp4-chap07/src/main/resources/aopPojo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/sp4-chap08/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/sp4-chap11/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/main/Main5.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.GenericXmlApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 |
10 | public class Main5 {
11 |
12 | public static void main(String[] args) {
13 | ApplicationContext ctx = new GenericXmlApplicationContext("classpath:appCtx5.xml");
14 | MemberRegisterService regSvc = ctx.getBean("memberRegSvc", MemberRegisterService.class);
15 | MemberInfoPrinter infoPrinter = ctx.getBean("infoPrinter", MemberInfoPrinter.class);
16 |
17 | RegisterRequest regReq = new RegisterRequest();
18 | regReq.setEmail("madvirus@madvirus.net");
19 | regReq.setName("최범균");
20 | regReq.setPassword("1234");
21 | regReq.setConfirmPassword("1234");
22 | regSvc.regist(regReq);
23 |
24 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
25 |
26 | System.out.println("printer = " + ctx.getBean("printer"));
27 | System.out.println("printer2 = " + ctx.getBean("printer2"));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/main/MainTwoConfs.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 | import config.ConfigPart1;
10 | import config.ConfigPart2;
11 |
12 | public class MainTwoConfs {
13 |
14 | public static void main(String[] args) {
15 | ApplicationContext ctx =
16 | new AnnotationConfigApplicationContext(
17 | ConfigPart1.class, ConfigPart2.class);
18 | MemberRegisterService regSvc =
19 | ctx.getBean("memberRegSvc", MemberRegisterService.class);
20 | MemberInfoPrinter infoPrinter =
21 | ctx.getBean("infoPrinter", MemberInfoPrinter.class);
22 |
23 | RegisterRequest regReq = new RegisterRequest();
24 | regReq.setEmail("madvirus@madvirus.net");
25 | regReq.setName("최범균");
26 | regReq.setPassword("1234");
27 | regReq.setConfirmPassword("1234");
28 | regSvc.regist(regReq);
29 |
30 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/sp4-chap04/src/main/java/main/Main2.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.GenericXmlApplicationContext;
5 |
6 | import spring.MemberInfoPrinter;
7 | import spring.MemberRegisterService;
8 | import spring.RegisterRequest;
9 |
10 | public class Main2 {
11 |
12 | public static void main(String[] args) {
13 | // 이 코드를 실행하면, MemberInfoPrinter 클래스의 @Autowired가 적용된 setPrinter() 메서드에
14 | // MemberPrinter 타입의 두 빈 객체 중 어떤 객체를 주입해야 할지 모르기 때문에 익셉션이 발생한다.
15 | ApplicationContext ctx = new GenericXmlApplicationContext("classpath:appCtx2.xml");
16 | MemberRegisterService regSvc = ctx.getBean("memberRegSvc", MemberRegisterService.class);
17 | MemberInfoPrinter infoPrinter = ctx.getBean("infoPrinter", MemberInfoPrinter.class);
18 |
19 | RegisterRequest regReq = new RegisterRequest();
20 | regReq.setEmail("madvirus@madvirus.net");
21 | regReq.setName("최범균");
22 | regReq.setPassword("1234");
23 | regReq.setConfirmPassword("1234");
24 | regSvc.regist(regReq);
25 |
26 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sp4-chap03/src/main/resources/conf2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/sp4-chap05/src/main/java/main/MainXmlJava.java:
--------------------------------------------------------------------------------
1 | package main;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 | import org.springframework.context.support.GenericXmlApplicationContext;
6 |
7 | import spring.MemberInfoPrinter;
8 | import spring.MemberRegisterService;
9 | import spring.RegisterRequest;
10 | import config.JavaMainConf;
11 |
12 | public class MainXmlJava {
13 |
14 | public static void main(String[] args) {
15 | ApplicationContext ctx =
16 | new GenericXmlApplicationContext("classpath:main-conf.xml");
17 | MemberRegisterService regSvc =
18 | ctx.getBean("memberRegSvc", MemberRegisterService.class);
19 | MemberInfoPrinter infoPrinter =
20 | ctx.getBean("infoPrinter", MemberInfoPrinter.class);
21 |
22 | RegisterRequest regReq = new RegisterRequest();
23 | regReq.setEmail("madvirus@madvirus.net");
24 | regReq.setName("최범균");
25 | regReq.setPassword("1234");
26 | regReq.setConfirmPassword("1234");
27 | regSvc.regist(regReq);
28 |
29 | infoPrinter.printMemberInfo("madvirus@madvirus.net");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/sp4-chap07/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | sp4
7 | sp4-chap07
8 | 0.0.1-SNAPSHOT
9 |
10 |
11 |
12 | org.springframework
13 | spring-context
14 | 4.1.0.RELEASE
15 |
16 |
17 | org.aspectj
18 | aspectjweaver
19 | 1.8.2
20 |
21 |
22 |
23 |
24 |
25 |
26 | maven-compiler-plugin
27 | 3.1
28 |
29 | 1.7
30 | 1.7
31 | utf-8
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/java/controller/MemberListController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.ui.Model;
7 | import org.springframework.validation.Errors;
8 | import org.springframework.web.bind.annotation.ModelAttribute;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 |
11 | import spring.Member;
12 | import spring.MemberDao;
13 |
14 | @Controller
15 | public class MemberListController {
16 |
17 | private MemberDao memberDao;
18 |
19 | public void setMemberDao(MemberDao memberDao) {
20 | this.memberDao = memberDao;
21 | }
22 |
23 | @RequestMapping("/member/list")
24 | public String list(
25 | @ModelAttribute("cmd") ListCommand listCommand,
26 | Errors errors, Model model) {
27 | if (errors.hasErrors()) {
28 | return "member/memberList";
29 | }
30 | if (listCommand.getFrom() != null && listCommand.getTo() != null) {
31 | List members = memberDao.selectByRegdate(
32 | listCommand.getFrom(), listCommand.getTo());
33 | model.addAttribute("members", members);
34 | }
35 | return "member/memberList";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/java/controller/MemberListController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.ui.Model;
7 | import org.springframework.validation.Errors;
8 | import org.springframework.web.bind.annotation.ModelAttribute;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 |
11 | import spring.Member;
12 | import spring.MemberDao;
13 |
14 | @Controller
15 | public class MemberListController {
16 |
17 | private MemberDao memberDao;
18 |
19 | public void setMemberDao(MemberDao memberDao) {
20 | this.memberDao = memberDao;
21 | }
22 |
23 | @RequestMapping("/member/list")
24 | public String list(
25 | @ModelAttribute("cmd") ListCommand listCommand,
26 | Errors errors, Model model) {
27 | if (errors.hasErrors()) {
28 | return "member/memberList";
29 | }
30 | if (listCommand.getFrom() != null && listCommand.getTo() != null) {
31 | List members = memberDao.selectByRegdate(
32 | listCommand.getFrom(), listCommand.getTo());
33 | model.addAttribute("members", members);
34 | }
35 | return "member/memberList";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/controller/MemberListController.java:
--------------------------------------------------------------------------------
1 | package controller;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.ui.Model;
7 | import org.springframework.validation.Errors;
8 | import org.springframework.web.bind.annotation.ModelAttribute;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 |
11 | import spring.Member;
12 | import spring.MemberDao;
13 |
14 | @Controller
15 | public class MemberListController {
16 |
17 | private MemberDao memberDao;
18 |
19 | public void setMemberDao(MemberDao memberDao) {
20 | this.memberDao = memberDao;
21 | }
22 |
23 | @RequestMapping("/member/list")
24 | public String list(
25 | @ModelAttribute("cmd") ListCommand listCommand,
26 | Errors errors, Model model) {
27 | if (errors.hasErrors()) {
28 | return "member/memberList";
29 | }
30 | if (listCommand.getFrom() != null && listCommand.getTo() != null) {
31 | List members = memberDao.selectByRegdate(
32 | listCommand.getFrom(), listCommand.getTo());
33 | model.addAttribute("members", members);
34 | }
35 | return "member/memberList";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sp4-chap12/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | public boolean matchPassword(String pwd) {
51 | return this.password.equals(pwd);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | public boolean matchPassword(String pwd) {
51 | return this.password.equals(pwd);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | public boolean matchPassword(String pwd) {
51 | return this.password.equals(pwd);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/sp4-chap16/src/main/java/spring/Member.java:
--------------------------------------------------------------------------------
1 | package spring;
2 |
3 | import java.util.Date;
4 |
5 | public class Member {
6 |
7 | private Long id;
8 | private String email;
9 | private String password;
10 | private String name;
11 | private Date registerDate;
12 |
13 | public Member(String email, String password, String name, Date registerDate) {
14 | this.email = email;
15 | this.password = password;
16 | this.name = name;
17 | this.registerDate = registerDate;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public String getEmail() {
29 | return email;
30 | }
31 |
32 | public String getPassword() {
33 | return password;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public Date getRegisterDate() {
41 | return registerDate;
42 | }
43 |
44 | public void changePassword(String oldPassword, String newPassword) {
45 | if (!password.equals(oldPassword))
46 | throw new IdPasswordNotMatchingException();
47 | this.password = newPassword;
48 | }
49 |
50 | public boolean matchPassword(String pwd) {
51 | return this.password.equals(pwd);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 스프링4 입문 예제 코드
2 | =======
3 |
4 | # 소스 코드 다운로드
5 |
6 | * **메이븐 프로젝트** 다운로드: 이 화면의 우측에 있는 [Download Zip](https://github.com/madvirus/spring4fs/archive/master.zip) 링크를 누르면 소스 코드를 다운로드 받는다.
7 | * **이클립스 프로젝트** 다운로드: [소스 다운로드](https://drive.google.com/file/d/0B2WFL4DD6ByEdWZELXRhLWNkMW8/view?usp=sharing)로 이동한 뒤, 상단의 다운로드 아이콘을 클릭해서 다운로드 받는다.
8 |
9 | # 사전 준비
10 | ## 이클립스 설정
11 | 제공되는 소스는 메이븐 프로젝트이며 다음을 기준으로 작성되었다.
12 |
13 | - **자바7** 또는 **자바8**
14 | -- Window > Preferences > Java/Installed JREs 에서 추가
15 | - **UTF-8**
16 | -- Window > Preferences > General/Workspace 에서 Text file encoding을 UTF-8로 변경
17 | -- 프로젝트를 임포트 한 뒤, 프로젝트 별로 Project > Properties > Resource 에서 Text file encoding을 UTF-8로 변경해도 됨
18 | - **톰캣 7**
19 | -- Window > Preferences > Servers/Runtime Environments 에서 톰캣 7 설정 추가
20 |
21 | ## 메이븐 설정
22 | 명령 프롬프트에서 메이븐을 이용해서 웹 프로젝트를 실행하려면 메이븐이 설치되어 있어야 한다. 메이븐에 대한 기초 지식이 필요하면 http://javacan.tistory.com/entry/MavenBasic 글을 읽어보기 바란다.
23 |
24 | # 프로젝트 임포트
25 | ## 메이븐 프로젝트 임포트
26 | 이 화면의 우측에 있는 [Download Zip](https://github.com/madvirus/spring4fs/archive/master.zip) 링크를 누르면 소스 코드를 다운로드 받는다.
27 | 이 파일의 압축을 풀면 sp4-chapxx 형식의 메이븐 프로젝트가 존재한다.
28 |
29 | File > Import ... > Maven/Existing Maven Projects 메뉴를 이용해서 메이븐 프로젝트를 임포트 한다.
30 |
31 |
--------------------------------------------------------------------------------
/sp4-chap13/src/main/webapp/WEB-INF/view/member/memberList.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
5 |
6 |
7 |
8 | 회원 조회
9 |
10 |
11 |
12 |
13 |
14 |
15 | ~
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | | 아이디 | 이메일 |
26 | 이름 | 가입일 |
27 |
28 |
29 |
30 | | ${mem.id} |
31 | ">
32 | ${mem.email} |
33 | ${mem.name} |
34 | |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/sp4-chap14/src/main/webapp/WEB-INF/view/member/memberList.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html; charset=utf-8" %>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
5 |
6 |
7 |
8 | 회원 조회
9 |
10 |
11 |
12 |
13 |
14 |
15 | ~
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | | 아이디 | 이메일 |
26 | 이름 | 가입일 |
27 |
28 |
29 |
30 | | ${mem.id} |
31 | ">
32 | ${mem.email} |
33 | ${mem.name} |
34 | |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------