├── .gitignore
├── JPub-JavaWebService.iml
├── README.md
├── ch02
├── .gitignore
├── build.gradle
├── build
│ └── tmp
│ │ └── war
│ │ └── MANIFEST.MF
├── ch02.iml
├── gradle
│ └── tomcat.gradle
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── info.thecodinglive
│ ├── InitParamServlet.java
│ ├── InitServlet
│ ├── basic
│ │ ├── Hello.java
│ │ └── Hi.java
│ ├── listenerExample
│ │ ├── Admin.java
│ │ ├── AdminContextListener.java
│ │ ├── AdminServlet.java
│ │ └── SessionListener.java
│ └── loaderExample
│ │ ├── BasicClassLoader.java
│ │ ├── JpServlet.java
│ │ ├── JpubClassLoader.java
│ │ ├── Test11.java
│ │ └── Testa.java
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── basic
│ │ ├── HeaderServlet.java
│ │ ├── HelloServlet.java
│ │ ├── HelloServlet2.java
│ │ ├── InitServlet.java
│ │ └── LoginServlet.java
│ │ ├── cookie
│ │ ├── CookieCreateServlet.java
│ │ ├── CookieDeleteServlet.java
│ │ ├── CookieModifyServlet.java
│ │ ├── CookieReadServlet.java
│ │ └── CookieWriteServlet.java
│ │ ├── filter
│ │ ├── EncodingFilter.java
│ │ └── FilterEx.java
│ │ ├── pattern
│ │ ├── Command.java
│ │ ├── FrontController.java
│ │ ├── HomeView.java
│ │ ├── ListView.java
│ │ └── WriteView.java
│ │ ├── session
│ │ ├── CreateSessionValueServlet.java
│ │ ├── DefaultSessionServlet.java
│ │ └── ReadSessionValueServlet.java
│ │ └── upload
│ │ └── UploadServlet.java
│ └── webapp
│ ├── WEB-INF
│ └── command.properties
│ ├── home.jsp
│ ├── index.jsp
│ ├── list.jsp
│ ├── login.html
│ ├── login.jsp
│ ├── simple.jsp
│ ├── style.css
│ ├── upload.html
│ └── write.jsp
├── ch03-web
├── .gitignore
├── build.gradle
├── gradle
│ ├── lib.gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── controller
│ │ └── IndexController.java
│ │ └── interceptor
│ │ ├── ExecuteTimeInterceptor.java
│ │ └── JpubInterceptor.java
│ └── webapp
│ └── WEB-INF
│ ├── applicationContext.xml
│ ├── dispatcher-servlet.xml
│ ├── views
│ ├── home.jsp
│ └── list.jsp
│ └── web.xml
├── ch03
├── .gitignore
├── .gradle
│ └── 2.3
│ │ └── taskArtifacts
│ │ ├── cache.properties
│ │ ├── cache.properties.lock
│ │ ├── fileHashes.bin
│ │ ├── fileSnapshots.bin
│ │ ├── outputFileStates.bin
│ │ └── taskArtifacts.bin
├── build.gradle
├── gradle
│ ├── lib.gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ ├── main
│ ├── java
│ │ ├── Library.java
│ │ ├── basic
│ │ │ ├── BasicApp.java
│ │ │ ├── Boss.java
│ │ │ ├── Employee.java
│ │ │ ├── WorkManager.java
│ │ │ └── WorkService.java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ ├── javaConfig
│ │ │ ├── BeanConfig.java
│ │ │ ├── Boss.java
│ │ │ ├── Company.java
│ │ │ ├── CompanyConfig.java
│ │ │ ├── ConfigImportSpringApp.java
│ │ │ ├── Employee.java
│ │ │ ├── JavaConfigSpringApp.java
│ │ │ ├── WorkManager.java
│ │ │ └── WorkService.java
│ │ │ └── xmlConfig
│ │ │ └── XmlSpringApp.java
│ └── resources
│ │ └── applicationContext.xml
│ └── test
│ └── java
│ └── LibraryTest.java
├── ch04
├── .gitignore
├── basic
│ └── src
│ │ └── main
│ │ └── java
│ │ └── info
│ │ └── thecodinglive
│ │ └── controller
│ │ └── NotRequiredController.java
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── SpringLoadBeans.java
│ │ ├── UIMain.java
│ │ ├── config
│ │ └── WebConfig.java
│ │ ├── controller
│ │ ├── ExecuteTimeInterceptor.java
│ │ ├── HomeController.java
│ │ ├── JsonPControllerAdvice.java
│ │ ├── ResourceAdvice.java
│ │ └── UIController.java
│ │ ├── model
│ │ └── Product.java
│ │ ├── service
│ │ └── InMemoryProductService.java
│ │ └── util
│ │ └── PastLocalDate.java
│ └── resources
│ ├── application.yml
│ ├── assets
│ ├── css
│ │ └── style.css
│ └── style.css
│ ├── static
│ ├── css
│ │ └── style.css
│ └── images
│ │ └── icon-spring-framework.svg
│ └── templates
│ ├── chjoin.html
│ ├── hello.html
│ ├── home.html
│ ├── layout
│ └── default.html
│ ├── th.html
│ ├── th2.html
│ └── th3.html
├── ch05
├── .gitignore
├── build.gradle
├── gradlew
├── gradlew.bat
└── src
│ ├── main
│ ├── java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ ├── RestApp.java
│ │ │ ├── config
│ │ │ └── SwaggerConfig.java
│ │ │ ├── controller
│ │ │ ├── BasicController.java
│ │ │ ├── CORSController.java
│ │ │ └── UserController.java
│ │ │ └── model
│ │ │ ├── Todo.java
│ │ │ ├── TodoResource.java
│ │ │ └── User.java
│ └── resources
│ │ ├── application-dev.properties
│ │ ├── application-prod.properties
│ │ └── application.properties
│ └── test
│ └── java
│ ├── RestAPITest.java
│ └── RestClient.java
├── ch06-mariadb
├── .gitignore
├── build.gradle
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── ForEachMain.java
│ │ ├── FreeBoardApp.java
│ │ ├── MariaDBMain.java
│ │ ├── config
│ │ ├── MariaDBConnectionConfig.java
│ │ └── MyBatisConfig.java
│ │ ├── model
│ │ ├── FreeBoardVO.java
│ │ └── UserVO.java
│ │ └── repository
│ │ ├── FreeBoardRepository.java
│ │ └── UserRepository.java
│ └── resources
│ ├── application.properties
│ ├── data-mariadb.sql
│ ├── mybatis-config.xml
│ ├── sample
│ └── mapper
│ │ ├── freeBoardMapper.xml
│ │ └── userMapper.xml
│ └── schema-mariadb.sql
├── ch06-mybatis
├── .gitignore
├── build.gradle
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── MybatisMain.java
│ │ ├── config
│ │ └── MyBatisConfig.java
│ │ ├── model
│ │ └── UserVO.java
│ │ └── repository
│ │ └── UserRepository.java
│ └── resources
│ ├── application.properties
│ ├── data-hsqldb.sql
│ ├── mybatis-config.xml
│ ├── sample
│ └── mapper
│ │ └── userMapper.xml
│ └── schema-hsqldb.sql
├── ch06-querydsl
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ ├── main
│ ├── java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ └── querydsl
│ │ │ ├── MinMaxApplication.java
│ │ │ ├── QuerydslApplication.java
│ │ │ ├── UserEntity.java
│ │ │ ├── UserRepository.java
│ │ │ ├── UserRepositoryCustom.java
│ │ │ ├── UserRepositoryImpl.java
│ │ │ └── UserRole.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── example
│ └── querydsl
│ └── QuerydslApplicationTests.java
├── ch06
├── .gitignore
├── build.gradle
├── gradle
│ └── querydsl.gradle
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── JPAMain.java
│ │ ├── ManyToOneRun.java
│ │ ├── OneToManyRun.java
│ │ ├── model
│ │ ├── Address.java
│ │ ├── School.java
│ │ ├── Student.java
│ │ ├── UserEntity.java
│ │ └── UserRole.java
│ │ ├── repository
│ │ ├── SchoolRepository.java
│ │ ├── StudentRepository.java
│ │ └── UserRepository.java
│ │ └── service
│ │ └── SchoolService.java
│ └── resources
│ └── application.properties
├── ch07
├── CustombootStarter
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ ├── config
│ │ │ └── HelloServiceAutoConfiguration.java
│ │ │ └── service
│ │ │ ├── ConsoleHello.java
│ │ │ └── HelloService.java
│ │ └── resources
│ │ └── META-INF
│ │ └── spring.factories
├── UseCustomStarter
│ ├── build.gradle
│ ├── gradlew
│ ├── gradlew.bat
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ ├── AnnotationApp.java
│ │ │ ├── UseCustomStarterApp.java
│ │ │ ├── autopackage
│ │ │ └── AutoPackageMain.java
│ │ │ ├── conditional
│ │ │ ├── ConditionApp.java
│ │ │ ├── ConditionalMainConfig.java
│ │ │ ├── MsgBean.java
│ │ │ ├── SiteABean.java
│ │ │ ├── SiteAConfigCondition.java
│ │ │ ├── SiteBBean.java
│ │ │ └── SiteBConfigCondition.java
│ │ │ ├── config
│ │ │ └── MyAnnotation.java
│ │ │ ├── importSelect
│ │ │ ├── AConfig.java
│ │ │ ├── BConfig.java
│ │ │ ├── EnableAutoMyModule.java
│ │ │ ├── ImportSelectApp.java
│ │ │ ├── MainConfig.java
│ │ │ ├── MyBean.java
│ │ │ ├── MyImportSelector.java
│ │ │ └── UseMyBean.java
│ │ │ ├── prop
│ │ │ ├── MyProperties.java
│ │ │ └── PropApp.java
│ │ │ └── service
│ │ │ └── MyService.java
│ │ └── resources
│ │ └── application.properties
├── gradlew
└── gradlew.bat
├── ch08
├── .gitignore
├── build.gradle
├── gradlew
├── gradlew.bat
└── src
│ ├── integrationtest
│ └── java
│ │ └── info
│ │ └── thecodinglive
│ │ └── controller
│ │ └── UserControllerIntegrationTest.java
│ ├── main
│ ├── java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ ├── Ch8Main.java
│ │ │ ├── config
│ │ │ ├── DBConfig.java
│ │ │ ├── MessageConfig.java
│ │ │ ├── MyBatisConfig.java
│ │ │ └── ServiceConfig.java
│ │ │ ├── controller
│ │ │ ├── ApiExceptionHandler.java
│ │ │ └── UserController.java
│ │ │ ├── exception
│ │ │ ├── ThrowExample.java
│ │ │ ├── ThrowsExample.java
│ │ │ └── UserNotFoundException.java
│ │ │ ├── model
│ │ │ ├── ApiErrorDetail.java
│ │ │ └── UserVO.java
│ │ │ ├── repository
│ │ │ └── UserRepository.java
│ │ │ └── service
│ │ │ └── UserService.java
│ └── resources
│ │ ├── application.properties
│ │ ├── data-h2.sql
│ │ ├── messages.properties
│ │ ├── mybatis
│ │ └── mybatis-config.xml
│ │ ├── schema-h2.sql
│ │ └── user
│ │ └── mapper
│ │ └── userMapper.xml
│ └── test
│ ├── java
│ ├── controllerTest
│ │ └── UserControllerTest.java
│ ├── daoTest
│ │ ├── MybatisTestConfig.java
│ │ └── UserDaoTest.java
│ └── serviceTest
│ │ ├── ServiceTestConfig.java
│ │ └── UserServiceTest.java
│ └── resources
│ ├── application.properties
│ ├── data-h2.sql
│ └── schema-h2.sql
├── ch09
├── .gitignore
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ ├── docker
│ └── Dockerfile
│ ├── main
│ ├── java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ ├── Chapter9Main.java
│ │ │ ├── aspect
│ │ │ ├── Aspect1.java
│ │ │ ├── Logging.java
│ │ │ └── LoggingConsole.java
│ │ │ ├── controller
│ │ │ └── UserController.java
│ │ │ └── model
│ │ │ └── UserVO.java
│ └── resources
│ │ ├── application-dev.properties
│ │ ├── application-prod.properties
│ │ ├── application.properties
│ │ ├── data-h2.sql
│ │ ├── data-mariadb.sql
│ │ ├── schema-h2.sql
│ │ └── schema-mariadb.sql
│ └── test
│ ├── java
│ ├── daoTest
│ │ └── UserDaoTest.java
│ └── serviceTest
│ │ └── UserServiceTest.java
│ └── resources
│ ├── application.properties
│ ├── data-h2.sql
│ └── schema-h2.sql
├── ch10
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── SpringApp.java
│ │ └── controller
│ │ └── IndexController.java
│ └── resources
│ └── application.properties
├── ch11-a
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── Car.java
│ │ ├── NonDbRepository.java
│ │ └── SpringCachingApp.java
│ └── resources
│ ├── application.properties
│ └── ehcache.xml
├── ch11-b
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── CachingApp.java
│ │ └── Car.java
│ └── resources
│ └── application.properties
├── ch11-c
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── java
│ └── info
│ │ └── thecodinglive
│ │ ├── CacheConfig.java
│ │ ├── Car.java
│ │ ├── EhCacheApp.java
│ │ └── NonDbRepository.java
│ └── resources
│ ├── application.properties
│ └── ehcache.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── memberApp
├── .gitignore
├── README.md
├── build.gradle
├── gradle
│ ├── querydsl.gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
│ ├── main
│ ├── java
│ │ └── info
│ │ │ └── thecodinglive
│ │ │ └── member
│ │ │ ├── MemberApp.java
│ │ │ ├── config
│ │ │ ├── AuditConfig.java
│ │ │ └── SecurityConfig.java
│ │ │ ├── controller
│ │ │ └── MemberController.java
│ │ │ ├── model
│ │ │ ├── AbstractEntityModel.java
│ │ │ ├── Member.java
│ │ │ ├── MemberRole.java
│ │ │ └── RememberMeToken.java
│ │ │ ├── repository
│ │ │ ├── MemberRepository.java
│ │ │ └── RememberMeTokenRepository.java
│ │ │ ├── service
│ │ │ ├── MemberAccessDeniedHandler.java
│ │ │ ├── MemberService.java
│ │ │ ├── MemberServiceImpl.java
│ │ │ ├── MyUserService.java
│ │ │ └── RememberMeTokenService.java
│ │ │ └── support
│ │ │ ├── MemberValidator.java
│ │ │ └── PasswordEncoderUtil.java
│ └── resources
│ │ ├── application.properties
│ │ ├── sql
│ │ └── data-H2.sql
│ │ ├── static
│ │ └── css
│ │ │ ├── home.css
│ │ │ └── normalize.css
│ │ ├── templates
│ │ ├── admin.html
│ │ ├── error
│ │ │ └── 403.html
│ │ ├── fragments
│ │ │ ├── config.html
│ │ │ ├── footer.html
│ │ │ └── header.html
│ │ ├── home.html
│ │ ├── layout
│ │ │ └── base.html
│ │ ├── login.html
│ │ ├── signup.html
│ │ └── welcome.html
│ │ └── validation.properties
│ └── test
│ └── java
│ └── PasswordEncodeTest.java
└── settings.gradle
/JPub-JavaWebService.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 스프링부트로 배우는 자바 웹 서비스
2 | here is book example
3 |
4 |
5 |
6 | ## download
7 | [zip파일로 소스코드 전체 다운로드](https://github.com/thecodinglive/JPub-JavaWebService/archive/master.zip)
8 |
9 | 목차
10 | CHAPTER 1 개발 환경의 변화와 자바 · 1
11 |
12 | CHAPTER 2 서블릿 · 11
13 |
14 |
15 | CHAPTER 3 스프링 프레임워크 · 49
16 |
17 |
18 | CHAPTER 4 스프링 부트 웹 개발 · 81
19 |
20 |
21 | CHAPTER 5 REST API 서버 만들기 · 117
22 |
23 |
24 | CHAPTER 6 스프링 부트와 데이터 · 149
25 |
26 |
27 | CHAPTER 7 커스텀 스프링 부트 스타터 · 221
28 |
29 | CHAPTER 8 예외 처리 및 테스트 · 249
30 |
31 |
32 | CHAPTER 9 배포 · 281
33 |
34 |
35 | CHAPTER 10 모니터링 · 299
36 |
37 |
38 | CHAPTER 11 캐시 · 311
39 |
40 |
41 | CHAPTER 12 회원 관리 · 341
--------------------------------------------------------------------------------
/ch02/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript{
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'org.akhikhl.gretty:gretty:+'
7 | }
8 | }
9 | apply plugin: 'java'
10 | apply plugin: 'war'
11 |
12 | apply plugin: 'org.akhikhl.gretty'
13 |
14 | apply plugin: 'eclipse'
15 | apply plugin: 'idea'
16 |
17 | sourceCompatibility = 1.8
18 | targetCompatibility = 1.8
19 |
20 | repositories {
21 | jcenter()
22 | }
23 |
24 | compileJava.options.encoding = 'UTF-8'
25 |
26 | dependencies {
27 | compile 'org.slf4j:slf4j-api:1.7.7'
28 | testCompile 'junit:junit:4.12'
29 | providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
30 | }
31 |
32 | gretty{
33 | httpPort = 8080
34 | contextPath = '/'
35 | servletContainer = 'jetty9'
36 | }
37 |
38 |
39 | def webappDir = "$rootDir/src/main/webapp"
40 |
41 | eclipse{
42 | classpath{
43 | downloadSources = true
44 | defaultOutputDir = file("${buildDir}/classes/main")
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ch02/build/tmp/war/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 |
3 |
--------------------------------------------------------------------------------
/ch02/ch02.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/ch02/gradle/tomcat.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'tomcat'
2 |
3 | dependencies {
4 |
5 | /*
6 | tomcat setting
7 | */
8 | String tomcatVersion = '7.0.47'
9 | tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}"
10 | tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
11 | tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
12 | exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
13 | }
14 | providedCompile "org.apache.tomcat:tomcat-servlet-api:${tomcatVersion}"
15 |
16 | }
17 |
18 | /*
19 | task generateClassOutPutFolder{
20 | println sourceSets.main.output.classesDir
21 | boolean success = sourceSets.main.output.classesDir.mkdirs()
22 | if(!success){
23 | throw new GradleException('Failed to create classes directory!')
24 | }
25 | }
26 | */
27 |
28 | tomcatRun {
29 | contextPath = "/"
30 | URIEncoding = 'UTF-8'
31 | dependsOn war
32 | }
33 |
34 | tomcatRunWar{
35 | contextPath = "/"
36 | }
37 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/InitParamServlet.java:
--------------------------------------------------------------------------------
1 | import javax.servlet.ServletConfig;
2 | import javax.servlet.ServletException;
3 | import javax.servlet.annotation.WebInitParam;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 |
7 | @WebServlet(name="Init", urlPatterns={"/init"},
8 | initParams={ @WebInitParam(name="siteName", value="jpub") } )
9 | public class InitParamServlet extends HttpServlet{
10 | private String myParam = "";
11 | @Override
12 | public void init(ServletConfig servletConfig) throws ServletException {
13 | this.myParam = servletConfig.getInitParameter("siteName ");
14 | System.out.println("입력받은 사이트명은" + myParam + "입니다.");
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/InitServlet:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch02/src/main/info.thecodinglive/InitServlet
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/basic/Hello.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 |
4 | import javax.servlet.ServletException;
5 | import javax.servlet.annotation.WebServlet;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 |
12 | @WebServlet(name = "HelloServlet", urlPatterns ={"/helloget"} )
13 | public class Hello extends HttpServlet {
14 | @Override
15 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16 | System.out.println("doGet");
17 | resp.setCharacterEncoding("UTF-8");
18 | PrintWriter writer = resp.getWriter();
19 |
20 | resp.setContentType("text/html");
21 |
22 | writer.println("");
23 | writer.println("
");
24 | writer.println("get요청 예제");
25 | writer.println("");
26 | writer.println("");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/basic/Hi.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 | /*
4 | * classpath 확인용 더미 클래스
5 | * */
6 | public class Hi {
7 | public static void main(String ar[]){
8 | System.out.println("helo");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/listenerExample/Admin.java:
--------------------------------------------------------------------------------
1 | package listenerExample;
2 |
3 | public class Admin {
4 | private String name = "나관리";
5 | private String email = "admin@company.com";
6 |
7 | public Admin(String name, String email){
8 | this.name = name;
9 | this.email = email;
10 | }
11 |
12 | public String getName() {
13 | return name;
14 | }
15 |
16 | public void setName(String name) {
17 | this.name = name;
18 | }
19 |
20 | public String getEmail() {
21 | return email;
22 | }
23 |
24 | public void setEmail(String email) {
25 | this.email = email;
26 | }
27 |
28 |
29 |
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/listenerExample/AdminContextListener.java:
--------------------------------------------------------------------------------
1 | package listenerExample;
2 |
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.ServletContextEvent;
5 | import javax.servlet.ServletContextListener;
6 | import javax.servlet.annotation.WebListener;
7 |
8 | @WebListener
9 | public class AdminContextListener implements ServletContextListener{
10 | @Override
11 | public void contextInitialized(ServletContextEvent sce) {
12 | System.out.println("context 초기화");
13 | ServletContext context = sce.getServletContext();
14 | Admin admin1 = new Admin("나관리", "admin@company.com");
15 | Admin admin2 = new Admin("나땜빵", "tempy@company.com");
16 |
17 | context.setAttribute("admin", admin1);
18 | context.setAttribute("admin2", admin2);
19 | }
20 |
21 | @Override
22 | public void contextDestroyed(ServletContextEvent sce) {
23 | System.out.println("context가 종료되엇습니다.");
24 | }
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/listenerExample/AdminServlet.java:
--------------------------------------------------------------------------------
1 | package listenerExample;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 | import java.io.PrintWriter;
10 |
11 | /**
12 | * Created by Administrator on 2015-07-16.
13 | */
14 | @WebServlet("/admin")
15 | public class AdminServlet extends HttpServlet {
16 |
17 | @Override
18 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
19 | resp.setCharacterEncoding("UTF-8");
20 | resp.setContentType("text/html");
21 | PrintWriter out = resp.getWriter();
22 |
23 | Admin admin1 = (Admin)getServletContext().getAttribute("admin1");
24 | Admin admin2 = (Admin)getServletContext().getAttribute("admin2");
25 |
26 | out.println("관리자1" + admin1.getName() + "," + admin1.getEmail());
27 |
28 | out.println("관리자2" + admin2.getName() + "," + admin2.getEmail());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/listenerExample/SessionListener.java:
--------------------------------------------------------------------------------
1 | package listenerExample;
2 |
3 | import javax.servlet.annotation.WebListener;
4 | import javax.servlet.http.HttpSessionAttributeListener;
5 | import javax.servlet.http.HttpSessionBindingEvent;
6 | import javax.servlet.http.HttpSessionEvent;
7 | import javax.servlet.http.HttpSessionListener;
8 |
9 | @WebListener
10 | public class SessionListener implements HttpSessionListener, HttpSessionAttributeListener{
11 | @Override
12 | public void attributeAdded(HttpSessionBindingEvent event) {
13 | System.out.println("session removed");
14 | }
15 |
16 | @Override
17 | public void attributeRemoved(HttpSessionBindingEvent sessionEvent) {
18 | System.out.println("세션 ID값" + sessionEvent.getName());
19 | System.out.println("세션ID의 지정된 값" + (String)sessionEvent.getSession()
20 | .getAttribute("user"));
21 | }
22 |
23 | @Override
24 | public void attributeReplaced(HttpSessionBindingEvent sessionEvent) {
25 |
26 | }
27 |
28 | @Override
29 | public void sessionCreated(HttpSessionEvent sessionEvent) {
30 | System.out.println("session creaTed " +
31 | sessionEvent.getSession().getId());
32 | }
33 |
34 | @Override
35 | public void sessionDestroyed(HttpSessionEvent sessionEvent) {
36 | System.out.println("session destroyed"
37 | + sessionEvent.getSession().getId());
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/loaderExample/BasicClassLoader.java:
--------------------------------------------------------------------------------
1 | package loaderExample;
2 |
3 | import java.io.Closeable;
4 |
5 | public interface BasicClassLoader extends Closeable {
6 | public void init();
7 | public Class> load(String name);
8 | public void run();
9 | public void unload();
10 | }
11 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/loaderExample/JpServlet.java:
--------------------------------------------------------------------------------
1 | package loaderExample;
2 |
3 | public class JpServlet {
4 | public String sayHello(String name){
5 | System.out.println("hello" + name);
6 |
7 | return JpServlet.class.getName();
8 | }
9 |
10 | public JpServlet() {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/loaderExample/Test11.java:
--------------------------------------------------------------------------------
1 | package loaderExample;
2 |
3 | import java.lang.reflect.InvocationTargetException;
4 | import java.lang.reflect.Method;
5 |
6 | public class Test11 {
7 | public static void main(String ar[]) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
8 | ClassLoader loader = ClassLoader.getSystemClassLoader();
9 | Class myclass = loader.loadClass("loaderExample.JpServlet");
10 | String invokeParameter = "nick";
11 |
12 | Object loadedInstance = myclass.newInstance();
13 |
14 | Method servletMethod = myclass.getMethod("sayHello", new Class[] { String.class });
15 |
16 | String result = (String)servletMethod.invoke(loadedInstance, new Object[] { invokeParameter });
17 |
18 | System.out.println(result);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ch02/src/main/info.thecodinglive/loaderExample/Testa.java:
--------------------------------------------------------------------------------
1 | package loaderExample;
2 |
3 | /**
4 | * Created by Administrator on 2015-07-16.
5 | */
6 | public class Testa {
7 | }
8 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/basic/HeaderServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.basic;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 | import java.io.PrintWriter;
10 | import java.util.Enumeration;
11 |
12 | @WebServlet(urlPatterns = "/header")
13 | public class HeaderServlet extends HttpServlet {
14 | @Override
15 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16 | resp.setCharacterEncoding("UTF-8");
17 | resp.setContentType("text/html");
18 | PrintWriter out = resp.getWriter();
19 | out.println(" header 예제");
20 | out.println("
");
21 | Enumeration headerNames = req.getHeaderNames();
22 | while (headerNames.hasMoreElements()) {
23 | String name = (String) headerNames.nextElement();
24 | String value = req.getHeader(name);
25 | out.println(name + ":" + value + "
");
26 | }
27 | out.println("");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/basic/HelloServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.basic;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 | import java.io.PrintWriter;
10 |
11 | @WebServlet(name = "HelloServlet", urlPatterns = {"/helloget"})
12 | public class HelloServlet extends HttpServlet {
13 | @Override
14 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
15 | System.out.println("doGet 메소드 호출");
16 | resp.setCharacterEncoding("UTF-8");
17 | PrintWriter writer = resp.getWriter();
18 |
19 | resp.setContentType("text/html");
20 | writer.println("");
21 | writer.println("jpub java webservice");
22 | writer.println(" get 요청 예제입니다. ");
23 | writer.println("");
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/basic/HelloServlet2.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.basic;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 |
10 | /**
11 | * Created by ysj on 2017-11-15.
12 | */
13 | @WebServlet(name = "HelloServlet2", urlPatterns = {"/hellopost"})
14 | public class HelloServlet2 extends HttpServlet {
15 | @Override
16 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
17 | System.out.println("doPost 호출");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/basic/InitServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.basic;
2 |
3 | import javax.servlet.ServletConfig;
4 | import javax.servlet.ServletException;
5 | import javax.servlet.annotation.WebInitParam;
6 | import javax.servlet.annotation.WebServlet;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 | import java.io.IOException;
11 |
12 | @WebServlet(
13 | name = "initServlet", urlPatterns = {"/init"},
14 | initParams = {@WebInitParam(name = "siteName", value = "jpub")}
15 | )
16 | public class InitServlet extends HttpServlet{
17 | private String myParam = "";
18 |
19 | public void init(ServletConfig servletConfig) throws ServletException{
20 | System.out.println("init call");
21 | this.myParam = servletConfig.getInitParameter("siteName");
22 | System.out.println("입력받은 사이트 명은" + myParam + "입니다.");
23 | }
24 |
25 | @Override
26 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
27 | resp.getWriter().println("hello");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/basic/LoginServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.basic;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 | import java.io.PrintWriter;
10 |
11 | @WebServlet(name = "LoginServlet", urlPatterns = {"/postsend"})
12 | public class LoginServlet extends HttpServlet {
13 | @Override
14 | protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
15 | System.out.println("doPost 메소드 호출");
16 | resp.setCharacterEncoding("UTF-8");
17 | req.setCharacterEncoding("UTF-8");
18 | PrintWriter writer = resp.getWriter();
19 |
20 | resp.setContentType("text/html");
21 |
22 | String user = req.getParameter("user");
23 | String pwd = req.getParameter("pwd");
24 | writer.println("");
25 | writer.println("Login Servlet");
26 | writer.println("");
27 | writer.println("전달받은 이름은" + user + "이고" + "
" + "비밀번호는" + pwd + "입니다.");
28 | writer.println("");
29 | writer.println("");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/cookie/CookieCreateServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.cookie;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.Cookie;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 |
12 | @WebServlet(urlPatterns = "/newcookie")
13 | public class CookieCreateServlet extends HttpServlet {
14 | @Override
15 | public void doGet(HttpServletRequest req,
16 | HttpServletResponse resp) throws ServletException,
17 | IOException {
18 | resp.setCharacterEncoding("UTF-8");
19 | resp.setContentType("text/html");
20 | PrintWriter out = resp.getWriter();
21 | out.println(" 쿠키 예제");
22 | out.println("
");
23 |
24 | Cookie jcookie = new Cookie("jpub", "books");
25 | jcookie.setMaxAge(3600);
26 | resp.addCookie(jcookie);
27 | out.println("readcookie");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/cookie/CookieDeleteServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.cookie;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.Cookie;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 |
12 | @WebServlet(urlPatterns = "/delcookie")
13 | public class CookieDeleteServlet extends HttpServlet{
14 | @Override
15 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16 | resp.setCharacterEncoding("UTF-8");
17 | resp.setContentType("text/html");
18 | PrintWriter out = resp.getWriter();
19 | out.println(" cookie 삭제 ");
20 | out.println("");
21 | Cookie[] cookies = req.getCookies();
22 | if (cookies != null) {
23 | for (Cookie cookie : cookies) {
24 | if (cookie.getName().equals("jpub")) {
25 | Cookie deletedCookie = new Cookie("jpub", "");
26 | deletedCookie.setMaxAge(0);
27 | resp.addCookie(deletedCookie);
28 | }
29 | }
30 | }
31 | out.println("readcookie");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/cookie/CookieModifyServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.cookie;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.Cookie;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 |
12 | @WebServlet(urlPatterns = "/modicookie")
13 | public class CookieModifyServlet extends HttpServlet{
14 | @Override
15 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16 | resp.setCharacterEncoding("UTF-8");
17 | resp.setContentType("text/html");
18 | PrintWriter out = resp.getWriter();
19 | out.println(" cookie 수정 ");
20 | out.println("");
21 | Cookie[] cookies = req.getCookies();
22 | if (cookies != null) {
23 | for (Cookie cookie : cookies) {
24 | if (cookie.getName().equals("jpub")) {
25 | Cookie modifiedCookie = new Cookie("jpub", "read");
26 | resp.addCookie(modifiedCookie);
27 | }
28 | }
29 | }
30 | out.println("readcookie");
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/cookie/CookieReadServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.cookie;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.Cookie;
9 | import javax.servlet.http.HttpServlet;
10 | import javax.servlet.http.HttpServletRequest;
11 | import javax.servlet.http.HttpServletResponse;
12 |
13 | @WebServlet(urlPatterns = "/readcookie")
14 | public class CookieReadServlet extends HttpServlet {
15 | @Override
16 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
17 | resp.setCharacterEncoding("UTF-8");
18 | resp.setContentType("text/html");
19 | PrintWriter out = resp.getWriter();
20 | out.println("쿠키 읽기");
21 | Cookie[] cookies = req.getCookies();
22 | if (cookies != null) {
23 | for (Cookie cookie : cookies) {
24 | if (cookie.getName().equals("jpub")) {
25 | out.println("cookie::" + cookie.getValue());
26 | }
27 | }
28 | }
29 | out.println("쿠키수정");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/cookie/CookieWriteServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.cookie;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.Cookie;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import java.io.IOException;
11 | import java.io.PrintWriter;
12 |
13 | @WebServlet(urlPatterns = "/cookiew")
14 | public class CookieWriteServlet extends HttpServlet {
15 | @Override
16 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
17 | resp.setContentType("text/html");
18 | PrintWriter writer = resp.getWriter();
19 |
20 | Cookie testCookie = new Cookie("test", "1234");
21 | testCookie.setMaxAge(60 * 60 * 24); // 1day
22 | resp.addCookie(testCookie);
23 |
24 | writer.println("cookie created");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/filter/EncodingFilter.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.filter;
2 |
3 |
4 | import javax.servlet.*;
5 | import java.io.IOException;
6 |
7 | public class EncodingFilter implements Filter {
8 |
9 | private String reqEncoding = "UTF-8";
10 |
11 | @Override
12 | public void init(FilterConfig filterConfig) throws ServletException {
13 | String encodingStr = filterConfig.getInitParameter("encoding");
14 | if (encodingStr != null) {
15 | reqEncoding = encodingStr;
16 | }
17 | }
18 |
19 | @Override
20 | public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
21 | req.setCharacterEncoding(reqEncoding);
22 | chain.doFilter(req, resp);
23 | }
24 |
25 | @Override
26 | public void destroy() {
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/filter/FilterEx.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.filter;
2 |
3 |
4 | import javax.servlet.*;
5 | import javax.servlet.annotation.WebFilter;
6 | import java.io.IOException;
7 | import java.io.PrintWriter;
8 |
9 | @WebFilter("*.jsp")
10 | public class FilterEx implements Filter {
11 | @Override
12 | public void init(FilterConfig filterConfig) throws ServletException {
13 |
14 | }
15 |
16 | @Override
17 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
18 | res.setContentType("text/html");
19 | res.setCharacterEncoding("UTF-8");
20 | PrintWriter out = res.getWriter();
21 | out.println("필터 동작 전");
22 | chain.doFilter(req, res);
23 | out.println("필터 동작 후");
24 | }
25 |
26 | @Override
27 | public void destroy() {
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/pattern/Command.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.pattern;
2 |
3 | import javax.servlet.RequestDispatcher;
4 | import javax.servlet.ServletContext;
5 | import javax.servlet.ServletException;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import java.io.IOException;
9 |
10 | public abstract class Command {
11 | private HttpServletRequest req;
12 | private HttpServletResponse res;
13 | private ServletContext servletContext;
14 |
15 | abstract public void execute();
16 |
17 | public void forward(String url){
18 | try{
19 | RequestDispatcher rd = req.getRequestDispatcher(url);
20 | rd.forward(getReq(), getRes());
21 | }catch (IOException ioe){
22 | servletContext.log("forward Error",ioe);
23 | }catch (ServletException servletEx){
24 | servletContext.log("servlet Error", servletEx);
25 | }
26 | }
27 |
28 | public HttpServletRequest getReq() {
29 | return req;
30 | }
31 |
32 | public void setReq(HttpServletRequest req) {
33 | this.req = req;
34 | }
35 |
36 | public HttpServletResponse getRes() {
37 | return res;
38 | }
39 |
40 | public void setRes(HttpServletResponse res) {
41 | this.res = res;
42 | }
43 |
44 | public ServletContext getServletContext() {
45 | return servletContext;
46 | }
47 |
48 | public void setServletContext(ServletContext servletContext) {
49 | this.servletContext = servletContext;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/pattern/HomeView.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.pattern;
2 |
3 | public class HomeView extends Command {
4 | @Override
5 | public void execute() {
6 | forward("/home.jsp");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/pattern/ListView.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.pattern;
2 |
3 | public class ListView extends Command {
4 | @Override
5 | public void execute() {
6 | forward("/list.jsp");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/pattern/WriteView.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.pattern;
2 |
3 | public class WriteView extends Command {
4 | @Override
5 | public void execute() {
6 | forward("/write.jsp");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/session/CreateSessionValueServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.session;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import javax.servlet.http.HttpSession;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 |
12 | @WebServlet(urlPatterns = "/createse")
13 | public class CreateSessionValueServlet extends HttpServlet {
14 | @Override
15 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16 | resp.setContentType("text/html");
17 | resp.setCharacterEncoding("UTF-8");
18 | PrintWriter out = resp.getWriter();
19 | out.println("세션");
20 |
21 | HttpSession session = req.getSession();
22 | session.setAttribute("jpub", "book");
23 | out.println("세션이 생성되었습니다.");
24 | out.println("세션 읽기");
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/session/DefaultSessionServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.session;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import javax.servlet.http.HttpSession;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 |
12 | @WebServlet("/session")
13 | public class DefaultSessionServlet extends HttpServlet {
14 | @Override
15 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16 | resp.setContentType("text/html");
17 | resp.setCharacterEncoding("UTF-8");
18 | PrintWriter out = resp.getWriter();
19 | out.println("세션");
20 | HttpSession session = req.getSession();
21 | out.println("sessionId::" + session.getId() + "
");
22 | out.println("session created::" + session.getCreationTime() + "
");
23 | out.println("session lastAccessTime" + session.getLastAccessedTime() + "
");
24 | out.println("");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ch02/src/main/java/info/thecodinglive/session/ReadSessionValueServlet.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.session;
2 |
3 | import javax.servlet.ServletException;
4 | import javax.servlet.annotation.WebServlet;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 | import javax.servlet.http.HttpSession;
9 | import java.io.IOException;
10 | import java.io.PrintWriter;
11 |
12 | @WebServlet(urlPatterns = "/readse")
13 | public class ReadSessionValueServlet extends HttpServlet {
14 | @Override
15 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16 | resp.setContentType("text/html");
17 | resp.setCharacterEncoding("UTF-8");
18 | PrintWriter out = resp.getWriter();
19 | out.println("세션");
20 |
21 | HttpSession session = req.getSession();
22 | String sessionValue = (String) session.getAttribute("jpub");
23 | out.println("생성된 세션 값:" + sessionValue);
24 | out.println("");
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/WEB-INF/command.properties:
--------------------------------------------------------------------------------
1 | home=info.thecodinglive.pattern.HomeView
2 | list=info.thecodinglive.pattern.ListView
3 | write=info.thecodinglive.pattern.WriteView
--------------------------------------------------------------------------------
/ch02/src/main/webapp/home.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
2 |
3 |
4 | Front Controller pattern
5 |
6 |
7 | home.jsp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 |
3 |
4 | hello chapter2
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/list.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
2 |
3 |
4 | Front Controller pattern
5 |
6 |
7 | list.jsp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 |
10 |
Log-in
11 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/login.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 |
3 |
4 | Login
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/simple.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
2 |
3 |
4 | filter
5 |
6 |
7 | filter test
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/upload.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | 업로드
9 |
17 |
18 |
--------------------------------------------------------------------------------
/ch02/src/main/webapp/write.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
2 |
3 |
4 | Front Controller pattern
5 |
6 |
7 | write.jsp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch03-web/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 |
6 | dependencies {
7 | classpath 'org.akhikhl.gretty:gretty:+'
8 | }
9 | }
10 |
11 | apply plugin: 'java'
12 | apply plugin: 'war'
13 | apply plugin: 'idea'
14 | apply plugin: 'eclipse'
15 | apply from : 'gradle/lib.gradle'
16 |
17 |
18 | apply plugin: 'org.akhikhl.gretty'
19 |
20 | gretty{
21 | contextPath = '/'
22 | servletContainer = 'jetty9'
23 | }
24 |
25 |
26 | group = 'thecodinglive'
27 | version = '1.0.0'
28 |
29 | task initProject << {
30 | sourceSets*.java.srcDirs*.each { it.mkdirs() }
31 | sourceSets*.resources.srcDirs*.each { it.mkdirs() }
32 |
33 | def webappDir = "$rootDir/src/main/webapp"
34 |
35 | file(webappDir + "/WEB-INF/views").mkdirs()
36 | file(webappDir + "/META-INF").mkdir()
37 | }
38 |
39 | compileJava {
40 | sourceCompatibility=1.8
41 | targetCompatibility=1.8
42 | }
43 |
44 | compileTestJava {
45 | sourceCompatibility=1.8
46 | targetCompatibility=1.8
47 | }
48 |
49 | compileJava.options.encoding = 'UTF-8'
50 | compileTestJava.options.encoding = 'UTF-8'
51 |
52 |
53 |
--------------------------------------------------------------------------------
/ch03-web/gradle/lib.gradle:
--------------------------------------------------------------------------------
1 |
2 | repositories {
3 | jcenter()
4 | }
5 | ext{
6 | javaVersion = '1.8'
7 | springVersion = '4.1.6.RELEASE'
8 | slf4jVersion = '1.7.5'
9 | logbackVersion = '1.0.13'
10 | }
11 |
12 | List springLib = [
13 | "org.springframework:spring-core:${springVersion}",
14 | "org.springframework:spring-webmvc:${springVersion}"
15 | ]
16 |
17 |
18 |
19 | dependencies {
20 | providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
21 | compile springLib
22 |
23 | compile 'org.slf4j:slf4j-api:1.7.7'
24 | testCompile 'junit:junit:4.12'
25 | }
26 |
--------------------------------------------------------------------------------
/ch03-web/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch03-web/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch03-web/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu May 28 15:39:55 KST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
7 |
--------------------------------------------------------------------------------
/ch03-web/src/main/java/info/thecodinglive/controller/IndexController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.servlet.ModelAndView;
6 |
7 | import java.util.Date;
8 |
9 | /**
10 | * Created by jins on 2017-06-06.
11 | */
12 | @Controller
13 | public class IndexController {
14 |
15 | @RequestMapping("/")
16 | public ModelAndView home(){
17 | // return new ModelAndView("home");
18 | ModelAndView mv=new ModelAndView("home");
19 | mv.addObject("title", "Jpub Spring WEB");
20 | mv.addObject("today", new Date().toString());
21 |
22 | return mv;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ch03-web/src/main/java/info/thecodinglive/interceptor/ExecuteTimeInterceptor.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.interceptor;
2 |
3 | import org.springframework.web.servlet.ModelAndView;
4 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 |
9 | /**
10 | * Created by ysj on 2017-12-04.
11 | */
12 | public class ExecuteTimeInterceptor extends HandlerInterceptorAdapter {
13 | @Override
14 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
15 | long startTime = System.currentTimeMillis();
16 | request.setAttribute("startTime", startTime);
17 |
18 | String reqUri = request.getRequestURI();
19 | System.out.println("reqUrl: " + reqUri);
20 |
21 | return true;
22 | }
23 |
24 | @Override
25 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
26 | super.postHandle(request, response, handler, modelAndView);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ch03-web/src/main/java/info/thecodinglive/interceptor/JpubInterceptor.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.interceptor;
2 |
3 | import org.springframework.web.servlet.ModelAndView;
4 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 |
9 | public class JpubInterceptor extends HandlerInterceptorAdapter {
10 | @Override
11 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
12 | System.out.println("preHandle 메소드 실행");
13 | return true;
14 | }
15 |
16 | @Override
17 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
18 | System.out.println("postHandle 메소드 실행");
19 | }
20 |
21 | @Override
22 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
23 | System.out.println("afterCompletion 메소드 실행");
24 | }
25 |
26 | @Override
27 | public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
28 | super.afterConcurrentHandlingStarted(request, response, handler);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ch03-web/src/main/webapp/WEB-INF/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/ch03-web/src/main/webapp/WEB-INF/dispatcher-servlet.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ch03-web/src/main/webapp/WEB-INF/views/home.jsp:
--------------------------------------------------------------------------------
1 | <%@ page contentType="text/html;charset=UTF-8" language="java" %>
2 |
3 |
4 | ${title}
5 |
6 |
7 | ${today}
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch03-web/src/main/webapp/WEB-INF/views/list.jsp:
--------------------------------------------------------------------------------
1 | <%--
2 | Created by IntelliJ IDEA.
3 | User: ysj
4 | Date: 2017-12-04
5 | Time: 오전 10:56
6 | To change this template use File | Settings | File Templates.
7 | --%>
8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %>
9 |
10 |
11 | Title
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/ch03-web/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 | contextConfigLocation
8 | /WEB-INF/applicationContext.xml
9 |
10 |
11 | org.springframework.web.context.ContextLoaderListener
12 |
13 |
14 | dispatcher
15 | org.springframework.web.servlet.DispatcherServlet
16 | 1
17 |
18 |
19 | dispatcher
20 | /
21 |
22 |
--------------------------------------------------------------------------------
/ch03/.gradle/2.3/taskArtifacts/cache.properties:
--------------------------------------------------------------------------------
1 | #Sat Jul 18 23:03:22 KST 2015
2 |
--------------------------------------------------------------------------------
/ch03/.gradle/2.3/taskArtifacts/cache.properties.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch03/.gradle/2.3/taskArtifacts/cache.properties.lock
--------------------------------------------------------------------------------
/ch03/.gradle/2.3/taskArtifacts/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch03/.gradle/2.3/taskArtifacts/fileHashes.bin
--------------------------------------------------------------------------------
/ch03/.gradle/2.3/taskArtifacts/fileSnapshots.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch03/.gradle/2.3/taskArtifacts/fileSnapshots.bin
--------------------------------------------------------------------------------
/ch03/.gradle/2.3/taskArtifacts/outputFileStates.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch03/.gradle/2.3/taskArtifacts/outputFileStates.bin
--------------------------------------------------------------------------------
/ch03/.gradle/2.3/taskArtifacts/taskArtifacts.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch03/.gradle/2.3/taskArtifacts/taskArtifacts.bin
--------------------------------------------------------------------------------
/ch03/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'application'
3 |
4 | apply plugin: 'idea'
5 | apply plugin: 'eclipse'
6 |
7 | apply from : 'gradle/lib.gradle'
8 |
9 | group = 'thecodinglive'
10 | version = '1.0.0'
11 |
12 | compileJava {
13 | sourceCompatibility=1.8
14 | targetCompatibility=1.8
15 | }
16 |
17 | compileTestJava {
18 | sourceCompatibility=1.8
19 | targetCompatibility=1.8
20 | }
21 |
22 | compileJava.options.encoding = 'UTF-8'
23 | compileTestJava.options.encoding = 'UTF-8'
24 |
25 |
26 |
--------------------------------------------------------------------------------
/ch03/gradle/lib.gradle:
--------------------------------------------------------------------------------
1 | repositories {
2 | jcenter()
3 | }
4 |
5 | ext{
6 | javaVersion = '1.8'
7 | springVersion = '4.1.6.RELEASE'
8 | slf4jVersion = '1.7.5'
9 | logbackVersion = '1.0.13'
10 | }
11 |
12 | List springLib = [
13 | "org.springframework:spring-core:${springVersion}",
14 | "org.springframework:spring-context:${springVersion}",
15 | ]
16 |
17 | dependencies {
18 | compile springLib
19 | compile 'org.slf4j:slf4j-api:1.7.7'
20 | testCompile 'junit:junit:4.12'
21 | }
22 |
--------------------------------------------------------------------------------
/ch03/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch03/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch03/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jul 18 23:03:22 KST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
7 |
--------------------------------------------------------------------------------
/ch03/src/main/java/Library.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This Java source file was auto generated by running 'gradle buildInit --type java-library'
3 | * by 'Administrator' at '15. 7. 18 오후 11:03' with Gradle 2.3
4 | *
5 | * @author Administrator, @date 15. 7. 18 오후 11:03
6 | */
7 | public class Library {
8 | public boolean someLibraryMethod() {
9 | return true;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ch03/src/main/java/basic/BasicApp.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 | public class BasicApp {
4 | public static void main(String ar[]){
5 | WorkService workService = new WorkService();
6 | WorkManager employee = new Employee();
7 | WorkManager boss = new Boss();
8 |
9 | workService.setWorkManager(employee);
10 | workService.askWork();
11 |
12 | workService.setWorkManager(boss);
13 | workService.askWork();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ch03/src/main/java/basic/Boss.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 | public class Boss implements WorkManager{
4 | @Override
5 | public String doIt() {
6 | return "do boss";
7 | }
8 |
9 | public void onCreated() {
10 | System.out.println("boss 생성");
11 | }
12 |
13 | public void onDestroyed() {
14 | System.out.println("Boss 소멸");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ch03/src/main/java/basic/Employee.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 | /**
4 | * Created by yun_dev1 on 2016-03-25.
5 | */
6 | public class Employee implements WorkManager{
7 | @Override
8 | public String doIt() {
9 | return "do work";
10 | }
11 |
12 | public void onCreated() {
13 | System.out.println("Employee 생성");
14 | }
15 |
16 | public void onDestroyed() {
17 | System.out.println("Employee 소멸");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ch03/src/main/java/basic/WorkManager.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 | public interface WorkManager {
4 | public String doIt();
5 | }
6 |
--------------------------------------------------------------------------------
/ch03/src/main/java/basic/WorkService.java:
--------------------------------------------------------------------------------
1 | package basic;
2 |
3 | import javax.annotation.PostConstruct;
4 | import javax.annotation.PreDestroy;
5 |
6 | public class WorkService {
7 | WorkManager workManager;
8 |
9 | public void setWorkManager(WorkManager workManager){
10 | this.workManager = workManager;
11 | }
12 |
13 | public void askWork(){
14 | System.out.println( workManager.doIt() );
15 | }
16 |
17 | @PostConstruct
18 | public void onCreated() {
19 | System.out.println("초기화 되었을 때");
20 | }
21 |
22 | @PreDestroy
23 | public void onDestroyed() {
24 | System.out.println("종료되었을 때");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/BeanConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.Import;
6 |
7 | @Configuration
8 | @Import(CompanyConfig.class)
9 | public class BeanConfig {
10 | @Bean
11 | public WorkManager employee() {
12 | return new Employee();
13 | }
14 |
15 | @Bean
16 | public WorkManager boss() {
17 | return new Boss();
18 | }
19 |
20 | @Bean
21 | public WorkService yourWorkService() {
22 | WorkService workService = new WorkService();
23 | workService.setWorkManager(employee());
24 | return workService;
25 | }
26 |
27 | @Bean
28 | public WorkService myWorkService() {
29 | WorkService workService = new WorkService();
30 | workService.setWorkManager(boss());
31 | return workService;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/Boss.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | import javax.annotation.PostConstruct;
4 | import javax.annotation.PreDestroy;
5 |
6 | public class Boss implements WorkManager {
7 | @Override
8 | public String doIt() {
9 | return "do boss";
10 | }
11 |
12 | @PostConstruct
13 | public void onCreated() {
14 | System.out.println("boss 초기화");
15 | }
16 |
17 | @PreDestroy
18 | public void onDestroyed() {
19 | System.out.println("boss 소멸");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/Company.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | public class Company {
4 | private String name;
5 |
6 | Company(String name) {
7 | this.name = name;
8 | }
9 |
10 | public String getName() {
11 | System.out.println(name);
12 | return name;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/CompanyConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 |
7 | @Configuration
8 | public class CompanyConfig {
9 | @Bean
10 | public Company company() {
11 | return new Company("jpub");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/ConfigImportSpringApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4 |
5 |
6 | public class ConfigImportSpringApp {
7 | public static void main(String ar[]) {
8 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
9 | BeanConfig.class
10 | );
11 |
12 | WorkService yourWorkService = context.getBean("yourWorkService", WorkService.class);
13 | yourWorkService.askWork();
14 |
15 | WorkService myWorkService = context.getBean("myWorkService", WorkService.class);
16 | myWorkService.askWork();
17 |
18 | Company company = context.getBean("company", Company.class);
19 | company.getName();
20 |
21 | context.close();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/Employee.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | import javax.annotation.PostConstruct;
4 | import javax.annotation.PreDestroy;
5 |
6 | public class Employee implements WorkManager {
7 | @Override
8 | public String doIt() {
9 | return "do work";
10 | }
11 |
12 | @PostConstruct
13 | public void onCreated() {
14 | System.out.println("employee 초기화");
15 | }
16 |
17 | @PreDestroy
18 | public void onDestroyed() {
19 | System.out.println("employee 소멸");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/JavaConfigSpringApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4 |
5 | public class JavaConfigSpringApp {
6 | public static void main(String ar[]){
7 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
8 | context.register(BeanConfig.class);
9 | context.refresh();
10 |
11 | WorkService yourWorkService = context.getBean("yourWorkService", WorkService.class);
12 | yourWorkService.askWork();
13 |
14 | WorkService myWorkService = context.getBean("myWorkService", WorkService.class);
15 | myWorkService.askWork();
16 |
17 | context.close();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/WorkManager.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | public interface WorkManager {
4 | public String doIt();
5 | }
6 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/javaConfig/WorkService.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.javaConfig;
2 |
3 | public class WorkService {
4 | WorkManager workManager;
5 |
6 | public void setWorkManager(WorkManager workManager) {
7 | this.workManager = workManager;
8 | }
9 |
10 | public void askWork() {
11 | System.out.println(workManager.doIt());
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ch03/src/main/java/info/thecodinglive/xmlConfig/XmlSpringApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.xmlConfig;
2 |
3 | import basic.WorkService;
4 | import org.springframework.context.support.GenericXmlApplicationContext;
5 |
6 | public class XmlSpringApp {
7 | public static void main(String ar[]){
8 | GenericXmlApplicationContext context = new GenericXmlApplicationContext(
9 | "classpath:applicationContext.xml"
10 | );
11 |
12 | WorkService myWorkService = context.getBean("myWorkService", WorkService.class);
13 | myWorkService.askWork();
14 |
15 | WorkService yourWorkService = context.getBean("yourWorkService", WorkService.class);
16 | yourWorkService.askWork();
17 |
18 | context.close();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ch03/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/ch03/src/test/java/LibraryTest.java:
--------------------------------------------------------------------------------
1 | import org.junit.Test;
2 | import static org.junit.Assert.*;
3 |
4 | /*
5 | * This Java source file was auto generated by running 'gradle init --type java-library'
6 | * by 'Administrator' at '15. 7. 18 오후 11:03' with Gradle 2.3
7 | *
8 | * @author Administrator, @date 15. 7. 18 오후 11:03
9 | */
10 | public class LibraryTest {
11 | @Test public void testSomeLibraryMethod() {
12 | Library classUnderTest = new Library();
13 | assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ch04/basic/src/main/java/info/thecodinglive/controller/NotRequiredController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.ui.Model;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestParam;
6 |
7 |
8 | public class NotRequiredController {
9 |
10 | @RequestMapping("/req")
11 | public String requreHi(@RequestParam String primary,
12 | @RequestParam(value ="sub", required=false ) String sub, Model model){
13 | System.out.println(primary);
14 | return "home";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ch04/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.springframework.boot' version '1.5.8.RELEASE'
4 | }
5 |
6 | ext{
7 | springBootVersion='1.5.8.RELEASE'
8 | }
9 |
10 | sourceCompatibility = 1.8
11 | targetCompatibility = 1.8
12 |
13 |
14 | sourceSets{
15 | main{
16 | java {
17 | srcDir 'src/main/java'
18 | }
19 | resources{
20 | srcDir 'src/resources'
21 | }
22 | }
23 | }
24 |
25 |
26 | repositories {
27 | jcenter()
28 | }
29 |
30 | dependencies {
31 | compile 'org.springframework.boot:spring-boot-starter-web'
32 | compile "org.springframework.boot:spring-boot-starter-thymeleaf"
33 | compile "org.springframework.boot:spring-boot-devtools"
34 |
35 | compile group: 'org.webjars', name: 'webjars-locator', version: '0.32'
36 |
37 | compile 'org.webjars:jquery:3.1.0'
38 | compile 'org.webjars:bootstrap:3.3.1'
39 | compile 'org.webjars:materializecss:0.96.0'
40 |
41 | compile 'org.slf4j:slf4j-api:1.7.7'
42 |
43 | testCompile 'junit:junit:4.12'
44 |
45 | //capcha
46 | compile group: 'com.google.code.maven-play-plugin.org.playframework', name: 'jj-imaging', version: '1.1'
47 | compile group: 'com.google.code.maven-play-plugin.org.playframework', name: 'jj-simplecaptcha', version: '1.1'
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/SpringLoadBeans.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.ApplicationContext;
6 |
7 | import java.util.Arrays;
8 |
9 | @SpringBootApplication
10 | public class SpringLoadBeans {
11 | public static void main(String ar[]) {
12 | ApplicationContext ctx = SpringApplication.run(SpringLoadBeans.class, ar);
13 | String[] beanNames = ctx.getBeanDefinitionNames();
14 | Arrays.sort(beanNames);
15 | for (String beanName : beanNames) {
16 | System.out.println(beanName);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/UIMain.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class UIMain {
8 | public static void main(String ar[]){
9 | SpringApplication.run(UIMain.class, ar);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/controller/ExecuteTimeInterceptor.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.web.servlet.ModelAndView;
4 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 |
9 | public class ExecuteTimeInterceptor extends HandlerInterceptorAdapter {
10 | @Override
11 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
12 | long startTime = System.currentTimeMillis();
13 | request.setAttribute("startTime", startTime);
14 |
15 | String reqUri = request.getRequestURI();
16 | System.out.println("reqUri: " + reqUri);
17 |
18 | return true;
19 | }
20 |
21 | @Override
22 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
23 | long startTime = (Long) request.getAttribute("startTime");
24 | long endTime = System.currentTimeMillis();
25 | long executeTime = endTime - startTime;
26 |
27 | request.setAttribute("executeTime", executeTime);
28 |
29 | System.out.println("[" + handler + "] executeTime: " + executeTime + "ms");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/controller/HomeController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | @RestController
7 | public class HomeController {
8 | @RequestMapping("/")
9 | public String hello() {
10 | return "hello";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/controller/JsonPControllerAdvice.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.web.bind.annotation.ControllerAdvice;
4 | import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;
5 |
6 | @ControllerAdvice
7 | public class JsonPControllerAdvice extends AbstractJsonpResponseBodyAdvice {
8 | /*
9 | public JsonPControllerAdvice(String... queryParamNames) {
10 | super(queryParamNames);
11 | }
12 | */
13 | public JsonPControllerAdvice() {
14 | super("bootCallback");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/controller/ResourceAdvice.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.ControllerAdvice;
5 | import org.springframework.web.bind.annotation.ModelAttribute;
6 | import org.springframework.web.servlet.resource.ResourceUrlProvider;
7 |
8 | @ControllerAdvice
9 | public class ResourceAdvice {
10 | @Autowired
11 | private ResourceUrlProvider resourceUrlProvider;
12 |
13 | @ModelAttribute("versionResourceResolver")
14 | public ResourceUrlProvider versionResourceResolver() {
15 | return this.resourceUrlProvider;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/controller/UIController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import info.thecodinglive.service.InMemoryProductService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.ui.Model;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 |
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | @Controller
13 | public class UIController {
14 | @Autowired
15 | InMemoryProductService inMemoryProductService;
16 |
17 | @RequestMapping(value = "/th")
18 | public String templatePage(Model model){
19 | model.addAttribute("message", "boot template");
20 | return "th";
21 | }
22 |
23 | @RequestMapping(value = "/th2")
24 | public String templatePage2(Model model) {
25 | Map pageMap = new HashMap<>();
26 | pageMap.put("color", "red");
27 | pageMap.put("name", "jam");
28 | pageMap.put("price", 3000);
29 | model.addAttribute("product", pageMap);
30 | return "th2";
31 | }
32 |
33 | @RequestMapping(value = "/th3")
34 | public String templatePage3(Model model) {
35 | model.addAttribute("products", inMemoryProductService.getProductList());
36 | return "th3";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/model/Product.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | public class Product {
4 | private String color;
5 | private String productName;
6 | private int price;
7 |
8 | public Product() {
9 | }
10 |
11 | public Product(String color, String productName, int price) {
12 | this.color = color;
13 | this.productName = productName;
14 | this.price = price;
15 | }
16 |
17 | public String getColor() {
18 | return color;
19 | }
20 |
21 | public void setColor(String color) {
22 | this.color = color;
23 | }
24 |
25 | public String getProductName() {
26 | return productName;
27 | }
28 |
29 | public void setProductName(String productName) {
30 | this.productName = productName;
31 | }
32 |
33 | public int getPrice() {
34 | return price;
35 | }
36 |
37 | public void setPrice(int price) {
38 | this.price = price;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/service/InMemoryProductService.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.service;
2 |
3 | import info.thecodinglive.model.Product;
4 | import org.springframework.stereotype.Service;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | @Service
10 | public class InMemoryProductService {
11 | public List getProductList() {
12 | Product prod1 = new Product("gray", "t-shirt", 5000);
13 | Product prod2 = new Product("black", "coffee", 700);
14 | Product prod3 = new Product("blue", "jam", 2500);
15 | Product prod4 = new Product("red", "pen", 1500);
16 |
17 | ArrayList products = new ArrayList();
18 | products.add(prod1);
19 | products.add(prod2);
20 | products.add(prod3);
21 | products.add(prod4);
22 |
23 | return products;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ch04/src/main/java/info/thecodinglive/util/PastLocalDate.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.util;
2 |
3 | import javax.validation.Constraint;
4 | import javax.validation.ConstraintValidator;
5 | import javax.validation.ConstraintValidatorContext;
6 | import javax.validation.Payload;
7 | import java.lang.annotation.ElementType;
8 | import java.lang.annotation.Retention;
9 | import java.lang.annotation.RetentionPolicy;
10 | import java.lang.annotation.Target;
11 | import java.time.LocalDate;
12 |
13 | @Target({ElementType.FIELD})
14 | @Retention(RetentionPolicy.RUNTIME)
15 | @Constraint(validatedBy = PastLocalDate.PastValidator.class)
16 | public @interface PastLocalDate {
17 | String message() default "{javax.validation.constraints.Past.message}";
18 |
19 | Class>[] groups() default {};
20 |
21 | Class extends Payload>[] payload() default {};
22 |
23 | class PastValidator implements ConstraintValidator {
24 | public void initialize(PastLocalDate past) {
25 |
26 | }
27 |
28 | public boolean isValid(LocalDate localDate, ConstraintValidatorContext context) {
29 | return localDate == null || localDate.isBefore(LocalDate.now());
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/ch04/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | devtools:
3 | livereolad:
4 | enabled: true
5 | thymeleaf:
6 | cache: false
--------------------------------------------------------------------------------
/ch04/src/main/resources/assets/css/style.css:
--------------------------------------------------------------------------------
1 | <<<<<<< HEAD
2 | h1 {
3 | font-size: 100px;
4 | =======
5 | .main {
6 | color: #ff0000;
7 | >>>>>>> 45e7a2f3ec707ccb42144b4e44b41895f795f330
8 | }
--------------------------------------------------------------------------------
/ch04/src/main/resources/assets/style.css:
--------------------------------------------------------------------------------
1 | .main {
2 | color: #ff0000;
3 | }
--------------------------------------------------------------------------------
/ch04/src/main/resources/static/css/style.css:
--------------------------------------------------------------------------------
1 | h1 {
2 | font-size: 100px;
3 | }
--------------------------------------------------------------------------------
/ch04/src/main/resources/templates/chjoin.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | captcha
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ch04/src/main/resources/templates/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello World!
5 |
6 |
7 | h1
8 |
9 |
--------------------------------------------------------------------------------
/ch04/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | webjar
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 | jquery222
20 |
21 |
22 |
23 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/ch04/src/main/resources/templates/layout/default.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Default title
8 |
9 |
10 |
11 |
12 | - English
13 | - French
14 |
15 |
23 |
24 |
25 | Page content goes here
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/ch04/src/main/resources/templates/th.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | thymeleaf
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ch04/src/main/resources/templates/th2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | thymeleaf
5 |
6 |
7 |
8 |
name:
9 |
color:
10 |
price:
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ch04/src/main/resources/templates/th3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | thymeleaf3
5 |
6 |
7 |
8 |
9 |
10 | color |
11 | name |
12 | price |
13 |
14 |
15 | |
16 | |
17 | |
18 |
19 |
20 |
23 |
24 |
--------------------------------------------------------------------------------
/ch05/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'idea'
4 | //id 'org.springframework.boot' version '1.4.3.RELEASE'
5 | id 'org.springframework.boot' version '1.5.4.RELEASE'
6 | }
7 |
8 | ext{
9 | springBootVersion='1.5.4.RELEASE'
10 | querydslVersion = "3.6.9"
11 | generatedSourcesDir = file("${buildDir}/generated-sources")
12 | }
13 |
14 | sourceCompatibility = 1.8
15 | targetCompatibility = 1.8
16 |
17 | repositories {
18 | jcenter()
19 | }
20 |
21 | dependencies {
22 | compile 'org.springframework.boot:spring-boot-starter-web'
23 | compile 'org.slf4j:slf4j-api:1.7.7'
24 |
25 | // Swagger
26 | compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.4.0'
27 | compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.4.0'
28 |
29 | compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
30 |
31 |
32 | compile("org.springframework.boot:spring-boot-starter-hateoas")
33 |
34 |
35 | testCompile("org.springframework.boot:spring-boot-starter-test")
36 | testCompile 'junit:junit:4.12'
37 | }
38 |
--------------------------------------------------------------------------------
/ch05/src/main/java/info/thecodinglive/RestApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.boot.CommandLineRunner;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | /*
8 | @ComponentScan(basePackages = "info.thecodinglive.controller")
9 | @Configuration
10 | @EnableAutoConfiguration
11 | */
12 | @SpringBootApplication
13 | public class RestApp implements CommandLineRunner {
14 | public static void main(String[] args) {
15 | SpringApplication.run(RestApp.class, args);
16 | }
17 |
18 | @Override
19 | public void run(String... args) throws Exception {
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ch05/src/main/java/info/thecodinglive/controller/CORSController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | import javax.servlet.*;
6 | import javax.servlet.http.HttpServletResponse;
7 | import java.io.IOException;
8 |
9 | @Component
10 | public class CORSController implements Filter {
11 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
12 | HttpServletResponse response = (HttpServletResponse) res;
13 | response.setHeader("Access-Control-Allow-Origin", "*");
14 | response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PATCH");
15 | response.setHeader("Access-Control-Max-Age", "3600");
16 | response.setHeader("Access-Control-Allow-Headers", "x-requested-with, origin, content-type, accept");
17 | chain.doFilter(req, res);
18 | }
19 |
20 | public void init(FilterConfig filterConfig) {}
21 |
22 | public void destroy() {}
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/ch05/src/main/java/info/thecodinglive/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import info.thecodinglive.model.User;
4 | import org.springframework.http.ResponseEntity;
5 | import org.springframework.web.bind.annotation.PathVariable;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Date;
11 | import java.util.HashMap;
12 | import java.util.List;
13 |
14 | import static org.springframework.http.HttpStatus.OK;
15 |
16 | @RestController
17 | public class UserController {
18 | private static List userList = new ArrayList();
19 |
20 | {
21 | userList.add(new User(1, "jpub01", "user01@test.com", "remine", new Date()));
22 | userList.add(new User(2, "jpub02", "user02@test.com", "restart", new Date()));
23 | userList.add(new User(3, "jpub03", "user03@test.com", "nine", new Date()));
24 | userList.add(new User(4, "jpub04", "user04@test.com", "namu", new Date()));
25 | }
26 |
27 | @RequestMapping("/user/{userNo}")
28 | public ResponseEntity getuserInfo(@PathVariable int userNo) {
29 | User user = userList.get(userNo);
30 | return new ResponseEntity(user, OK);
31 | }
32 |
33 | @RequestMapping("/user")
34 | public ResponseEntity> getUserList() {
35 | HashMap resultList = new HashMap();
36 | resultList.put("result", userList);
37 | return new ResponseEntity(resultList, OK);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ch05/src/main/java/info/thecodinglive/model/Todo.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import io.swagger.annotations.ApiModel;
4 |
5 | @ApiModel
6 | public class Todo {
7 | private long id;
8 | private String title;
9 |
10 | public Todo() {
11 | }
12 |
13 | public Todo(long id, String title) {
14 | this.id = id;
15 | this.title = title;
16 | }
17 |
18 | public long getId() {
19 | return id;
20 | }
21 |
22 | public void setId(long id) {
23 | this.id = id;
24 | }
25 |
26 | public String getTitle() {
27 | return title;
28 | }
29 |
30 | public void setTitle(String title) {
31 | this.title = title;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ch05/src/main/java/info/thecodinglive/model/TodoResource.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import org.springframework.hateoas.ResourceSupport;
4 |
5 | public class TodoResource extends ResourceSupport {
6 |
7 | private String title;
8 |
9 | public TodoResource() {
10 | }
11 |
12 | public TodoResource(String title) {
13 |
14 | this.title = title;
15 | }
16 |
17 | public String getTitle() {
18 | return title;
19 | }
20 |
21 | public void setTitle(String title) {
22 | this.title = title;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/ch05/src/main/java/info/thecodinglive/model/User.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 |
5 | import java.util.Date;
6 |
7 | /**
8 | * Created by ysj on 2017-12-06.
9 | */
10 | public class User {
11 | private Integer userNo;
12 | private String userId;
13 | private String email;
14 | private String uname;
15 | @JsonFormat(pattern = "yyyy-MM-dd")
16 | private Date regDate;
17 |
18 | public User() {
19 | }
20 |
21 | public User(Integer userNo, String userId, String email, String uname, Date regDate) {
22 | this.userNo = userNo;
23 | this.userId = userId;
24 | this.email = email;
25 | this.uname = uname;
26 | this.regDate = regDate;
27 | }
28 |
29 | public Integer getUserNo() {
30 | return userNo;
31 | }
32 |
33 | public void setUserNo(Integer userNo) {
34 | this.userNo = userNo;
35 | }
36 |
37 | public String getUserId() {
38 | return userId;
39 | }
40 |
41 | public void setUserId(String userId) {
42 | this.userId = userId;
43 | }
44 |
45 | public String getEmail() {
46 | return email;
47 | }
48 |
49 | public void setEmail(String email) {
50 | this.email = email;
51 | }
52 |
53 | public String getUname() {
54 | return uname;
55 | }
56 |
57 | public void setUname(String uname) {
58 | this.uname = uname;
59 | }
60 |
61 | public Date getRegDate() {
62 | return regDate;
63 | }
64 |
65 | public void setRegDate(Date regDate) {
66 | this.regDate = regDate;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/ch05/src/main/resources/application-dev.properties:
--------------------------------------------------------------------------------
1 | server.port=7080
2 | endpoints.health.sensitive: false
3 | # spring.cloud.enabled: false
--------------------------------------------------------------------------------
/ch05/src/main/resources/application-prod.properties:
--------------------------------------------------------------------------------
1 | server.port=7080
2 | endpoints.health.sensitive: false
--------------------------------------------------------------------------------
/ch05/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=9090
2 | endpoints.health.sensitive: false
3 | # spring.cloud.enabled: false
--------------------------------------------------------------------------------
/ch05/src/test/java/RestClient.java:
--------------------------------------------------------------------------------
1 | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
2 | import org.springframework.web.client.RestTemplate;
3 |
4 | public class RestClient extends RestTemplate{
5 |
6 | private RestClient(){
7 | HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
8 | factory.setReadTimeout(1000 * 60 * 2);
9 | factory.setConnectTimeout(2000);
10 |
11 |
12 | new RestTemplate(factory);
13 | }
14 |
15 | //싱글톤 아니여도 됨 테스트코드용
16 | public static RestClient getInstance(){
17 | return new RestClient();
18 | }
19 |
20 | public static void main(String ar[]){
21 | RestClient restClient = RestClient.getInstance();
22 | restClient.getForEntity("http://www.naver.com", String.class);
23 | restClient.getForEntity("http://www.daum.net", String.class);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ch06-mariadb/build.gradle:
--------------------------------------------------------------------------------
1 | plugins{
2 | id 'java'
3 | id 'idea'
4 | id 'org.springframework.boot' version '1.5.8.RELEASE'
5 | }
6 |
7 | ext{
8 | springBootVersion='1.5.8.RELEASE'
9 | }
10 |
11 | sourceCompatibility = 1.8
12 | targetCompatibility = 1.8
13 |
14 |
15 | repositories {
16 | jcenter()
17 | }
18 |
19 |
20 | dependencies {
21 | compile 'org.slf4j:slf4j-api:1.7.7'
22 | //db
23 | compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '1.5.7'
24 | compile group: 'com.zaxxer', name: 'HikariCP', version: '2.5.1'
25 |
26 | compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1')
27 |
28 | testCompile("org.springframework.boot:spring-boot-starter-test")
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/java/info/thecodinglive/ForEachMain.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import info.thecodinglive.repository.UserRepository;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.CommandLineRunner;
6 | import org.springframework.boot.SpringApplication;
7 | import org.springframework.boot.autoconfigure.SpringBootApplication;
8 | import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
9 |
10 | import java.util.ArrayList;
11 | import java.util.HashMap;
12 | import java.util.List;
13 | import java.util.Map;
14 |
15 | /**
16 | * references
17 | * http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html
18 | */
19 |
20 | @SpringBootApplication(exclude = WebMvcAutoConfiguration.class)
21 | public class ForEachMain implements CommandLineRunner{
22 |
23 | public static void main(String[] args) {
24 | SpringApplication.run(ForEachMain.class, args);
25 | }
26 |
27 | @Autowired
28 | UserRepository userRepository;
29 |
30 | @Override
31 | public void run(String... args) throws Exception {
32 | List userList = new ArrayList();
33 | userList.add("test1");
34 | userList.add("test2");
35 | userList.add("test3");
36 |
37 | Map paramMap = new HashMap();
38 | paramMap.put("user_list", userList);
39 |
40 | System.out.println( userRepository.findByForeach(paramMap) );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/java/info/thecodinglive/FreeBoardApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import info.thecodinglive.model.FreeBoardVO;
4 | import info.thecodinglive.repository.FreeBoardRepository;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.CommandLineRunner;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 | import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
10 |
11 | /**
12 | * references
13 | * http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html
14 | */
15 |
16 | @SpringBootApplication(exclude = WebMvcAutoConfiguration.class)
17 | public class FreeBoardApp implements CommandLineRunner{
18 | public static void main(String[] args) {
19 | SpringApplication.run(FreeBoardApp.class, args);
20 | }
21 |
22 | @Autowired
23 | FreeBoardRepository freeBoardRepository;
24 |
25 | @Override
26 | public void run(String... args) throws Exception {
27 | System.out.println("frebboard run");
28 | FreeBoardVO freeBoardVO = new FreeBoardVO();
29 | freeBoardVO.setUserName("홍길동");
30 | freeBoardVO.setCategory("101");
31 | freeBoardVO.setContent("자유게시판 첫 글");
32 | freeBoardVO.setTitle("안녕");
33 |
34 | freeBoardRepository.registBoard(freeBoardVO);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/java/info/thecodinglive/model/FreeBoardVO.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import java.sql.Date;
4 |
5 | public class FreeBoardVO{
6 | private String boardId;
7 | private String userName;
8 | private String title;
9 | private String category;
10 | private String content;
11 | private int viewCount;
12 | private Date wdate;
13 |
14 | public String getBoardId() {
15 | return boardId;
16 | }
17 |
18 | public void setBoardId(String boardId) {
19 | this.boardId = boardId;
20 | }
21 |
22 | public String getUserName() {
23 | return userName;
24 | }
25 |
26 | public void setUserName(String userName) {
27 | this.userName = userName;
28 | }
29 |
30 | public String getTitle() {
31 | return title;
32 | }
33 |
34 | public void setTitle(String title) {
35 | this.title = title;
36 | }
37 |
38 | public String getCategory() {
39 | return category;
40 | }
41 |
42 | public void setCategory(String category) {
43 | this.category = category;
44 | }
45 |
46 | public String getContent() {
47 | return content;
48 | }
49 |
50 | public void setContent(String content) {
51 | this.content = content;
52 | }
53 |
54 | public int getViewCount() {
55 | return viewCount;
56 | }
57 |
58 | public void setViewCount(int viewCount) {
59 | this.viewCount = viewCount;
60 | }
61 |
62 | public Date getWdate() {
63 | return wdate;
64 | }
65 |
66 | public void setWdate(Date wdate) {
67 | this.wdate = wdate;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/java/info/thecodinglive/model/UserVO.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import java.io.Serializable;
4 |
5 |
6 | /**
7 | * Created by yun_dev1 on 2016-07-28.
8 | */
9 |
10 | public class UserVO implements Serializable{
11 | private String id;
12 | private String userName;
13 | private String passWord;
14 |
15 | public UserVO() {
16 | }
17 |
18 | public UserVO(String id, String userName, String passWord) {
19 | this.id = id;
20 | this.userName = userName;
21 | this.passWord = passWord;
22 | }
23 |
24 | public String getId() {
25 | return id;
26 | }
27 |
28 | public void setId(String id) {
29 | this.id = id;
30 | }
31 |
32 | public String getUserName() {
33 | return userName;
34 | }
35 |
36 | public void setUserName(String userName) {
37 | this.userName = userName;
38 | }
39 |
40 | public String getPassword() {
41 | return passWord;
42 | }
43 |
44 | public void setPassword(String passWord) {
45 | this.passWord = passWord;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/java/info/thecodinglive/repository/FreeBoardRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.repository;
2 |
3 | import info.thecodinglive.model.FreeBoardVO;
4 | import org.mybatis.spring.SqlSessionTemplate;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Repository;
7 |
8 | @Repository
9 | public class FreeBoardRepository {
10 | private static final String MAPPER_NAME_SPACE="sample.sample.mapper.freeBoard.";
11 |
12 | @Autowired
13 | private SqlSessionTemplate sqlSessionTemplate;
14 |
15 | public void registBoard(FreeBoardVO freeBoardVO){
16 | sqlSessionTemplate.insert(MAPPER_NAME_SPACE+ "insertBoard", freeBoardVO);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mariadb://localhost:3306/jpub?useUnicode=yes&characterEncoding=utf8
2 | spring.datasource.classname=org.mariadb.jdbc.MySQLDataSource
3 | spring.datasource.username=jpubdev
4 | spring.datasource.password=qwer1234
5 | spring.datasource.separator=;
6 | spring.datasource.sql-script-encoding=UTF-8
7 | spring.main.web-environment=false
8 | spring.database.platform=mariadb
9 | spring.datasource.schema=schema-mariadb.sql
10 | spring.datasource.data=data-mariadb.sql
11 | #h2 setting
12 | #spring.h2.console.enabled=true
13 | #spring.h2.console.path=/h2-console
14 | #spring.datasource.continue-on-error=true
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/resources/data-mariadb.sql:
--------------------------------------------------------------------------------
1 | insert into TBL_USER values('test1', 'kim', '1234');
2 | insert into TBL_USER values('test2', 'kim1', '1234');
3 | insert into TBL_USER values('test3', 'kim3', '1234');
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/resources/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/resources/sample/mapper/freeBoardMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 | SELECT
11 | CONCAT('FB', DATE_FORMAT(NOW(), '%y%m%d%h%i%s')) AS FBSEQ
12 |
13 | INSERT INTO FREE_BOARD
14 | (BOARD_ID ,UNAME, TITLE, CATEGORY, CONTENT, WDATE)
15 | values(#{boardId},#{userName}, #{title}, #{category}, #{content}, now())
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/ch06-mariadb/src/main/resources/schema-mariadb.sql:
--------------------------------------------------------------------------------
1 | use jpub;
2 | CREATE OR REPLACE TABLE TBL_USER (
3 | id varchar(40) NOT NULL,
4 | username varchar(45) NOT NULL,
5 | password varchar(45) NOT NULL
6 | );
--------------------------------------------------------------------------------
/ch06-mybatis/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.springframework.boot' version '1.5.8.RELEASE'
4 | }
5 |
6 | ext{
7 | springBootVersion='1.5.8.RELEASE'
8 | }
9 |
10 | sourceCompatibility = 1.8
11 | targetCompatibility = 1.8
12 |
13 |
14 | repositories {
15 | jcenter()
16 | }
17 |
18 | dependencies {
19 | compile 'org.slf4j:slf4j-api:1.7.7'
20 | //db
21 | compile group: 'org.hsqldb', name: 'hsqldb', version:'2.3.2'
22 | compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0')
23 | }
24 |
--------------------------------------------------------------------------------
/ch06-mybatis/src/main/java/info/thecodinglive/model/UserVO.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class UserVO implements Serializable{
6 | private String id;
7 | private String userName;
8 | private String passWord;
9 |
10 | public UserVO() {
11 | }
12 |
13 | public UserVO(String id, String userName, String passWord) {
14 | this.id = id;
15 | this.userName = userName;
16 | this.passWord = passWord;
17 | }
18 |
19 | public String getId() {
20 | return id;
21 | }
22 |
23 | public void setId(String id) {
24 | this.id = id;
25 | }
26 |
27 | public String getUserName() {
28 | return userName;
29 | }
30 |
31 | public void setUserName(String userName) {
32 | this.userName = userName;
33 | }
34 |
35 | public String getPassword() {
36 | return passWord;
37 | }
38 |
39 | public void setPassword(String passWord) {
40 | this.passWord = passWord;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/ch06-mybatis/src/main/java/info/thecodinglive/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.repository;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.mybatis.spring.SqlSessionTemplate;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Repository;
10 |
11 | import info.thecodinglive.model.UserVO;
12 | import org.springframework.transaction.annotation.Transactional;
13 |
14 | /**
15 | * Created by yun_dev1 on 2017-01-06.
16 | */
17 | @Repository
18 | public class UserRepository {
19 | private static final String MAPPER_NAME_SPACE = "sample.mapper.userMapper.";
20 |
21 | @Autowired
22 | private SqlSessionTemplate sqlSessionTemplate;
23 |
24 | public List getUserInfoAll(){
25 | return sqlSessionTemplate.selectList(MAPPER_NAME_SPACE + "selectUserInfoAll");
26 | }
27 |
28 | public void adduserInfo(UserVO userVO){
29 | sqlSessionTemplate.insert(MAPPER_NAME_SPACE+ "addUserInfo", userVO);
30 | }
31 |
32 | public List findByUserNameLike(String userName){
33 | Map params = new HashMap();
34 | params.put("userName", userName);
35 |
36 | return sqlSessionTemplate.selectList(MAPPER_NAME_SPACE + "findByUserNameLike", params);
37 | }
38 |
39 | public UserVO findByUserName(String userName){
40 | Map params = new HashMap();
41 | params.put("userName", userName);
42 |
43 | return sqlSessionTemplate.selectOne(MAPPER_NAME_SPACE + "findByUserName", params);
44 | }
45 |
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/ch06-mybatis/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:hsqldb:mem:mydb
2 | #spring.datasource.password=sa
3 | spring.database.platform=hsqldb
4 | spring.datasource.schema=schema-hsqldb.sql
5 | spring.datasource.data=data-hsqldb.sql
6 | spring.datasource.separator=;
7 | spring.datasource.sql-script-encoding=UTF-8
8 | spring.main.web-environment=false
9 | #h2 setting
10 | #spring.h2.console.enabled=true
11 | #spring.h2.console.path=/h2-console
12 | #spring.datasource.continue-on-error=true
--------------------------------------------------------------------------------
/ch06-mybatis/src/main/resources/data-hsqldb.sql:
--------------------------------------------------------------------------------
1 | insert into TBL_USER values('test1', 'kim', '1234');
2 | insert into TBL_USER values('test2', 'kim1', '1234');
3 | insert into TBL_USER values('test3', 'kim3', '1234');
--------------------------------------------------------------------------------
/ch06-mybatis/src/main/resources/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ch06-mybatis/src/main/resources/sample/mapper/userMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
27 |
28 |
29 |
39 |
40 |
50 |
--------------------------------------------------------------------------------
/ch06-mybatis/src/main/resources/schema-hsqldb.sql:
--------------------------------------------------------------------------------
1 | drop table TBL_USER if exists;
2 |
3 | CREATE TABLE TBL_USER (
4 | id varchar(40) NOT NULL,
5 | username varchar(45) NOT NULL,
6 | password varchar(45) NOT NULL
7 | );
--------------------------------------------------------------------------------
/ch06-querydsl/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch06-querydsl/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch06-querydsl/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip
6 |
--------------------------------------------------------------------------------
/ch06-querydsl/src/main/java/info/thecodinglive/querydsl/MinMaxApplication.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.querydsl;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.ConfigurableApplicationContext;
6 |
7 | @SpringBootApplication
8 | public class MinMaxApplication {
9 | public static void main(String[] args) {
10 | ConfigurableApplicationContext context = SpringApplication.run(MinMaxApplication.class, args);
11 | UserRepository userRepository = context.getBean(UserRepository.class);
12 |
13 | UserEntity u = new UserEntity("나라", 26, UserRole.USER);
14 | UserEntity u1 = new UserEntity("민하", 26, UserRole.USER);
15 | UserEntity u2 = new UserEntity("경리", 28, UserRole.USER);
16 | UserEntity u3 = new UserEntity("서지혜", 34, UserRole.USER);
17 |
18 | userRepository.save(u);
19 | userRepository.save(u1);
20 | userRepository.save(u2);
21 | userRepository.save(u3);
22 |
23 | System.out.println(userRepository.maxAge());
24 | System.out.println(userRepository.minAge());
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ch06-querydsl/src/main/java/info/thecodinglive/querydsl/UserRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.querydsl;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 | import org.springframework.data.repository.query.Param;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface UserRepository extends JpaRepository, UserRepositoryCustom {
9 | UserEntity findByUsername(@Param("username") String username);
10 | }
11 |
--------------------------------------------------------------------------------
/ch06-querydsl/src/main/java/info/thecodinglive/querydsl/UserRepositoryCustom.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.querydsl;
2 |
3 | import java.util.List;
4 |
5 | public interface UserRepositoryCustom {
6 | List findAllLike(String keyword);
7 |
8 | int maxAge();
9 |
10 | int minAge();
11 | }
12 |
--------------------------------------------------------------------------------
/ch06-querydsl/src/main/java/info/thecodinglive/querydsl/UserRepositoryImpl.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.querydsl;
2 |
3 | import com.querydsl.jpa.JPQLQuery;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.data.jpa.repository.support.QueryDslRepositorySupport;
6 |
7 | import info.thecodinglive.querydsl.QUserEntity;
8 |
9 | import javax.persistence.EntityManager;
10 | import java.util.List;
11 |
12 | public class UserRepositoryImpl extends QueryDslRepositorySupport implements UserRepositoryCustom {
13 | public UserRepositoryImpl() {
14 | super(UserEntity.class);
15 | }
16 |
17 | @Override
18 | @Autowired
19 | public void setEntityManager(EntityManager entityManager) {
20 | super.setEntityManager(entityManager);
21 | }
22 |
23 | @Override
24 | public List findAllLike(String keyword) {
25 | QUserEntity qUserEntity = QUserEntity.userEntity;
26 | JPQLQuery query = from(qUserEntity);
27 | List resultlist =
28 | query
29 | .where(qUserEntity.username.like(keyword))
30 | .fetch();
31 |
32 | return resultlist;
33 | }
34 |
35 | @Override
36 | public int maxAge() {
37 | QUserEntity qUserEntity = QUserEntity.userEntity;
38 | return from(qUserEntity).select(qUserEntity.age.max()).fetchOne();
39 | }
40 |
41 | @Override
42 | public int minAge() {
43 | QUserEntity qUserEntity = QUserEntity.userEntity;
44 | return from(qUserEntity).select(qUserEntity.age.min()).fetchOne();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ch06-querydsl/src/main/java/info/thecodinglive/querydsl/UserRole.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.querydsl;
2 |
3 |
4 | public enum UserRole {
5 | USER, //0
6 | ADMIN //1
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/ch06-querydsl/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.main.web-environment=false
--------------------------------------------------------------------------------
/ch06-querydsl/src/test/java/com/example/querydsl/QuerydslApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.querydsl;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class QuerydslApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/ch06/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.springframework.boot' version '1.5.8.RELEASE'
4 | }
5 |
6 | ext{
7 | springBootVersion='1.5.8.RELEASE'
8 | }
9 |
10 | sourceCompatibility = 1.8
11 | targetCompatibility = 1.8
12 |
13 |
14 | repositories {
15 | jcenter()
16 | }
17 |
18 | dependencies {
19 | compile 'org.slf4j:slf4j-api:1.7.7'
20 | //db
21 | compile group: 'org.hsqldb', name: 'hsqldb', version:'2.3.2'
22 | compile "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}"
23 | compile group: 'org.hibernate', name: 'hibernate-validator', version: '4.2.0.Final'
24 | compile group: 'javax.el', name: 'javax.el-api', version: '3.0.0'
25 | compile group: 'javax.validation', name: 'validation-api', version: '1.0.0.GA'
26 | }
27 |
--------------------------------------------------------------------------------
/ch06/gradle/querydsl.gradle:
--------------------------------------------------------------------------------
1 | sourceSets {
2 | generated {
3 | java {
4 | srcDirs = ['src/main/generated']
5 | }
6 | }
7 |
8 | }
9 |
10 | // QEntity 생성 task
11 | task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
12 | source = sourceSets.main.java
13 | classpath = configurations.compile + configurations.querydslapt
14 | options.compilerArgs = [
15 | "-proc:only",
16 | "-processor", "com.querydsl.apt.jpa.JPAAnnotationProcessor"
17 |
18 | ]
19 | destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
20 | }
21 |
22 | // compileJava task에 dependency를 걸어줍니다.
23 | compileJava {
24 | dependsOn generateQueryDSL
25 | // compile target에 generated된 QClass들의 위치를 추가.
26 | source sourceSets.generated.java.srcDirs.iterator().next()
27 | }
28 |
29 | compileGeneratedJava {
30 | dependsOn generateQueryDSL
31 | options.warnings = false
32 | classpath += sourceSets.main.runtimeClasspath
33 | }
34 |
35 | clean {
36 | delete sourceSets.generated.java.srcDirs
37 | }
38 |
39 |
40 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/JPAMain.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import info.thecodinglive.model.UserEntity;
4 | import info.thecodinglive.model.UserRole;
5 | import info.thecodinglive.repository.UserRepository;
6 | import org.springframework.boot.SpringApplication;
7 | import org.springframework.boot.autoconfigure.SpringBootApplication;
8 | import org.springframework.context.ConfigurableApplicationContext;
9 |
10 | //@SpringBootApplication(exclude = WebMvcAutoConfiguration.class)
11 | @SpringBootApplication
12 | public class JPAMain{
13 | public static void main(String[] args) {
14 | ConfigurableApplicationContext context = SpringApplication.run(JPAMain.class, args);
15 | UserRepository userRepository = context.getBean(UserRepository.class);
16 |
17 | userRepository.save(new UserEntity("윤사장", 60, UserRole.ADMIN));
18 | UserEntity user = userRepository.findByUserName("윤사장");
19 | System.out.println("나이:" + user.getAge() + "," + "이름:" + user.getUserName() + "," + "생성일:" + user.getCreatedAt());
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/ManyToOneRun.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import info.thecodinglive.service.SchoolService;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.ConfigurableApplicationContext;
7 |
8 | @SpringBootApplication
9 | public class ManyToOneRun {
10 | public static void main(String[] args) {
11 | ConfigurableApplicationContext context = SpringApplication.run(JPAMain.class, args);
12 | SchoolService schoolService = context.getBean(SchoolService.class);
13 |
14 | schoolService.findStudentInfo();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/OneToManyRun.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import info.thecodinglive.service.SchoolService;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.ConfigurableApplicationContext;
7 |
8 | @SpringBootApplication
9 | public class OneToManyRun {
10 | public static void main(String[] args) {
11 | ConfigurableApplicationContext context = SpringApplication.run(JPAMain.class, args);
12 | SchoolService schoolService = context.getBean(SchoolService.class);
13 | schoolService.findSchoolInfo();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/model/Address.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import javax.persistence.Embeddable;
4 |
5 | @Embeddable
6 | public class Address {
7 | private Integer zipCode;
8 | private String detail;
9 |
10 | public Address() {
11 | }
12 |
13 | public Address(Integer zipCode, String detail) {
14 | this.zipCode = zipCode;
15 | this.detail = detail;
16 | }
17 |
18 | public Integer getZipCode() {
19 | return zipCode;
20 | }
21 |
22 | public String getDetail() {
23 | return detail;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/model/Student.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import javax.persistence.*;
4 |
5 | @Entity
6 | public class Student {
7 | @Id
8 | @GeneratedValue(strategy = GenerationType.AUTO)
9 | @Column(name = "STUDENT_ID")
10 | private Long id;
11 | private String userName;
12 | private String grade;
13 | @ManyToOne(fetch = FetchType.LAZY)
14 | @JoinColumn(name = "SCHOOL_ID")
15 | private School school;
16 |
17 | public Student() {
18 | }
19 |
20 | public Student(String userName) {
21 | this.userName = userName;
22 | }
23 |
24 | public School getSchool() {
25 | return school;
26 | }
27 |
28 | public void setSchool(School school) {
29 | this.school = school;
30 | }
31 |
32 | public Long getId() {
33 | return id;
34 | }
35 |
36 | public void setId(Long id) {
37 | this.id = id;
38 | }
39 |
40 | public String getUserName() {
41 | return userName;
42 | }
43 |
44 | public void setUserName(String userName) {
45 | this.userName = userName;
46 | }
47 |
48 | public String getGrade() {
49 | return grade;
50 | }
51 |
52 | public void setGrade(String grade) {
53 | this.grade = grade;
54 | }
55 |
56 | @Override
57 | public String toString() {
58 | return "Student{" +
59 | "id=" + id +
60 | ", userName='" + userName + '\'' +
61 | ", grade='" + grade + '\'' +
62 | ", school=" + school +
63 | '}';
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/model/UserRole.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | /**
4 | * Created by yun_dev1 on 2016-12-26.
5 | */
6 | public enum UserRole {
7 | USER, //0
8 | ADMIN //1
9 | }
10 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/repository/SchoolRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.repository;
2 |
3 | import info.thecodinglive.model.School;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface SchoolRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/repository/StudentRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.repository;
2 |
3 | import info.thecodinglive.model.Student;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | @Repository
8 | public interface StudentRepository extends JpaRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/ch06/src/main/java/info/thecodinglive/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.repository;
2 |
3 | import info.thecodinglive.model.UserEntity;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.data.repository.query.Param;
6 | import org.springframework.stereotype.Repository;
7 |
8 | @Repository
9 | public interface UserRepository extends JpaRepository{
10 | UserEntity findByUserName(@Param("userName") String userName);
11 | }
12 |
--------------------------------------------------------------------------------
/ch06/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.main.web-environment=false
--------------------------------------------------------------------------------
/ch07/CustombootStarter/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.springframework.boot' version '1.5.8.RELEASE'
4 | }
5 |
6 | ext{
7 | springBootVersion='1.5.8.RELEASE'
8 | }
9 |
10 | repositories {
11 | jcenter()
12 | }
13 |
14 | bootRepackage.enabled = false
15 |
16 | jar{
17 | baseName='spring-boot-helloService-starter'
18 | version='1.0.0-SNAPSHOT'
19 | }
20 |
21 | dependencies {
22 |
23 | compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.8.RELEASE'
24 |
25 | compile 'org.slf4j:slf4j-api:1.7.21'
26 |
27 | testCompile 'junit:junit:4.12'
28 | }
29 |
--------------------------------------------------------------------------------
/ch07/CustombootStarter/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch07/CustombootStarter/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch07/CustombootStarter/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Aug 29 17:39:42 KST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
7 |
--------------------------------------------------------------------------------
/ch07/CustombootStarter/src/main/java/info/thecodinglive/config/HelloServiceAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.config;
2 |
3 | import info.thecodinglive.service.ConsoleHello;
4 | import info.thecodinglive.service.HelloService;
5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | @Configuration
11 | @ConditionalOnClass(HelloService.class)
12 | public class HelloServiceAutoConfiguration {
13 | @Bean
14 | @ConditionalOnMissingBean
15 | public HelloService helloService(){return new ConsoleHello();}
16 | }
17 |
--------------------------------------------------------------------------------
/ch07/CustombootStarter/src/main/java/info/thecodinglive/service/ConsoleHello.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.service;
2 |
3 | /**
4 | * Created by yun_dev1 on 2016-08-30.
5 | */
6 | public class ConsoleHello implements HelloService{
7 | @Override
8 | public void hi() {
9 | System.out.println("hello in console");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/ch07/CustombootStarter/src/main/java/info/thecodinglive/service/HelloService.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.service;
2 |
3 | public interface HelloService {
4 | void hi();
5 | }
6 |
--------------------------------------------------------------------------------
/ch07/CustombootStarter/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=info.thecodinglive.config.HelloServiceAutoConfiguration
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.springframework.boot' version '1.5.8.RELEASE'
4 | id 'application'
5 | }
6 |
7 | ext{
8 | springBootVersion='1.5.8.RELEASE'
9 | }
10 |
11 | sourceCompatibility = 1.8
12 | targetCompatibility = 1.8
13 |
14 | repositories {
15 | jcenter()
16 | }
17 |
18 | dependencies {
19 | compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.8.RELEASE'
20 | compile files('lib/spring-boot-helloService-starter-1.0.0-SNAPSHOT.jar')
21 | }
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/AnnotationApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import info.thecodinglive.config.MyAnnotation;
4 | import info.thecodinglive.service.MyService;
5 |
6 | import java.lang.reflect.Method;
7 |
8 | public class AnnotationApp {
9 | public static void main(String ar[]) throws Exception {
10 | Method[] methods = Class.forName(MyService.class.getName()).getMethods();
11 |
12 | for (int i = 0; i < methods.length; i++) {
13 | if (methods[i].isAnnotationPresent(MyAnnotation.class)) {
14 | MyAnnotation an = methods[i].getAnnotation(MyAnnotation.class);
15 |
16 | System.out.println("my annotation str value::" + an.strValue());
17 | System.out.println("my annotation int value:" + an.intValue());
18 | }
19 |
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/UseCustomStarterApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import info.thecodinglive.service.*;
7 | import org.springframework.context.annotation.ComponentScan;
8 |
9 | @SpringBootApplication
10 | @ComponentScan(basePackages = "info.thecodinglive.service", basePackageClasses = HelloService.class)
11 | public class UseCustomStarterApp {
12 | public static void main(String ar[]) {
13 |
14 | SpringApplication.run(UseCustomStarterApp.class, ar).getBean(HelloService.class).hi();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/autopackage/AutoPackageMain.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.autopackage;
2 |
3 | import org.springframework.boot.Banner;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
6 | import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
7 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
8 | import org.springframework.context.ConfigurableApplicationContext;
9 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
10 |
11 | import java.util.List;
12 |
13 | @EnableAutoConfiguration
14 | public class AutoPackageMain {
15 | public static void main(String ar[]) {
16 | SpringApplication app =
17 | new SpringApplication(AutoPackageMain.class);
18 | app.setBannerMode(Banner.Mode.OFF);
19 | app.setLogStartupInfo(false);
20 | String[] args = {"--debug"};
21 | ConfigurableApplicationContext c = app.run(args);
22 | List packages = AutoConfigurationPackages.get(c);
23 | System.out.println("packages: " + packages);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/conditional/ConditionApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.conditional;
2 |
3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4 |
5 | public class ConditionApp {
6 | public static void main(String ar[]) {
7 | Package pack = ConditionApp.class.getPackage();
8 |
9 | AnnotationConfigApplicationContext context =
10 | new AnnotationConfigApplicationContext();
11 | context.scan(pack.getName());
12 | context.refresh();
13 | MsgBean bean = context.getBean(MsgBean.class);
14 | bean.printMsg();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/conditional/ConditionalMainConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.conditional;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | public class ConditionalMainConfig {
8 | @Autowired
9 | MsgBean msgBean;
10 | }
11 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/conditional/MsgBean.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.conditional;
2 |
3 | public interface MsgBean {
4 | default void printMsg(){
5 | System.out.println("My Bean default is running");
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/conditional/SiteABean.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.conditional;
2 |
3 | import org.springframework.context.annotation.Conditional;
4 | import org.springframework.stereotype.Component;
5 |
6 | @Component
7 | @Conditional(SiteAConfigCondition.class)
8 | public class SiteABean implements MsgBean{
9 | @Override
10 | public void printMsg() {
11 | System.out.printf("Site A is working");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/conditional/SiteAConfigCondition.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.conditional;
2 |
3 | import org.springframework.context.annotation.Condition;
4 | import org.springframework.context.annotation.ConditionContext;
5 | import org.springframework.core.type.AnnotatedTypeMetadata;
6 |
7 | public class SiteAConfigCondition implements Condition{
8 | @Override
9 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
10 | return "sitea".equals(context.getEnvironment().getProperty("env", "sitea"));
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/conditional/SiteBBean.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.conditional;
2 |
3 | import org.springframework.context.annotation.Conditional;
4 | import org.springframework.stereotype.Component;
5 |
6 | @Component
7 | @Conditional(SiteBConfigCondition.class)
8 | public class SiteBBean implements MsgBean{
9 | @Override
10 | public void printMsg() {
11 | System.out.printf("Site B is working");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/conditional/SiteBConfigCondition.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.conditional;
2 |
3 | import org.springframework.context.annotation.Condition;
4 | import org.springframework.context.annotation.ConditionContext;
5 | import org.springframework.core.type.AnnotatedTypeMetadata;
6 |
7 | public class SiteBConfigCondition implements Condition{
8 | @Override
9 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
10 | return "siteb".equals(context.getEnvironment().getProperty("env", "siteb"));
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/config/MyAnnotation.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.config;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target(ElementType.METHOD)
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface MyAnnotation {
11 | String strValue();
12 |
13 | int intValue();
14 | }
15 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/AConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | public class AConfig {
8 | @Bean
9 | MyBean myBean() {
10 | return new MyBean("from Aconfig");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/BConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | public class BConfig {
8 | @Bean
9 | MyBean myBean() {
10 | return new MyBean("from bconfig");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/EnableAutoMyModule.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | import org.springframework.context.annotation.Import;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | @Retention(RetentionPolicy.RUNTIME)
11 | @Target(ElementType.TYPE)
12 | @Import(MyImportSelector.class)
13 | public @interface EnableAutoMyModule {
14 | String value() default "";
15 | }
16 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/ImportSelectApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5 |
6 | public class ImportSelectApp {
7 | public static void main(String ar[]) {
8 | ApplicationContext context =
9 | new AnnotationConfigApplicationContext(MainConfig.class);
10 | UseMyBean bean = context.getBean(UseMyBean.class);
11 | bean.printMsg();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/MainConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @EnableAutoMyModule("someValue")
8 | public class MainConfig {
9 | @Bean
10 | public UseMyBean useMyBean() {
11 | return new UseMyBean();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/MyBean.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | public class MyBean {
4 | private String msg;
5 |
6 | public MyBean(String msg) {
7 | this.msg = msg;
8 | }
9 |
10 | public String getMsg() {
11 | return msg;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/MyImportSelector.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | import org.springframework.context.annotation.ImportSelector;
4 | import org.springframework.core.annotation.AnnotationAttributes;
5 | import org.springframework.core.type.AnnotationMetadata;
6 |
7 | public class MyImportSelector implements ImportSelector {
8 | @Override
9 | public String[] selectImports(AnnotationMetadata importingClassMetadata) {
10 | AnnotationAttributes attr = AnnotationAttributes.fromMap(
11 | importingClassMetadata.getAnnotationAttributes(EnableAutoMyModule.class.getName(), false));
12 | String value = attr.getString("value");
13 | if ("someValue".equals(value)) {
14 | return new String[]{AConfig.class.getName()};
15 | } else {
16 | return new String[]{BConfig.class.getName()};
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/importSelect/UseMyBean.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.importSelect;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 |
5 | public class UseMyBean {
6 | @Autowired
7 | private MyBean myBean;
8 |
9 | public void printMsg() {
10 | System.out.println(myBean.getMsg());
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/prop/MyProperties.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.prop;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 |
5 | @ConfigurationProperties(prefix = "myapp")
6 | public class MyProperties {
7 | private String name;
8 | private String descrption;
9 | private String serverIp;
10 |
11 | public String getName() {
12 | return name;
13 | }
14 |
15 | public void setName(String name) {
16 | this.name = name;
17 | }
18 |
19 | public String getDescrption() {
20 | return descrption;
21 | }
22 |
23 | public void setDescrption(String descrption) {
24 | this.descrption = descrption;
25 | }
26 |
27 | public String getServerIp() {
28 | return serverIp;
29 | }
30 |
31 | public void setServerIp(String serverIp) {
32 | this.serverIp = serverIp;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/prop/PropApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.prop;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.CommandLineRunner;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
8 | import org.springframework.context.annotation.Bean;
9 |
10 | @SpringBootApplication
11 | @EnableConfigurationProperties({MyProperties.class})
12 | public class PropApp {
13 | public static void main(String ar[]) {
14 | SpringApplication.run(PropApp.class, ar);
15 | }
16 |
17 | @Autowired
18 | MyProperties prop;
19 |
20 | @Bean
21 | CommandLineRunner values() {
22 | return ar -> {
23 | System.out.println("server ip:" + prop.getServerIp());
24 | System.out.println("app name:" + prop.getName());
25 | };
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/java/info/thecodinglive/service/MyService.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.service;
2 |
3 | import info.thecodinglive.config.MyAnnotation;
4 |
5 | public class MyService {
6 | @MyAnnotation(strValue = "hi", intValue = 0607)
7 | public void printSomething() {
8 | System.out.println("test my annotation");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/ch07/UseCustomStarter/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.main.web-environment=false
2 | myapp.server-ip=192.168.34.56
3 | myapp.name=My Config App
4 | myapp.description=This is an example
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/Ch8Main.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.boot.CommandLineRunner;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | public class Ch8Main implements CommandLineRunner{
9 | public static void main(String[] args) {
10 | SpringApplication.run(Ch8Main.class, args);
11 | }
12 |
13 | @Override
14 | public void run(String... args) throws Exception {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/config/MessageConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.support.ReloadableResourceBundleMessageSource;
6 |
7 | /**
8 | * Created by yun_dev1 on 2017-03-02.
9 | */
10 | @Configuration
11 | public class MessageConfig {
12 | @Bean
13 | public ReloadableResourceBundleMessageSource messageSource(){
14 | ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
15 | messageSource.setDefaultEncoding("UTF-8");
16 | messageSource.setBasename("classpath:messages/messages");
17 |
18 | return messageSource;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/config/ServiceConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.config;
2 |
3 | import org.springframework.context.annotation.ComponentScan;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.Import;
6 | import org.springframework.stereotype.Service;
7 |
8 | @Configuration
9 | @ComponentScan(basePackages = {"info.thecodinglive.service"},
10 | useDefaultFilters = false,
11 | includeFilters = {@ComponentScan.Filter(Service.class)}
12 | )
13 | @Import(MyBatisConfig.class)
14 | public class ServiceConfig {
15 | }
16 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/controller/ApiExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import java.util.Date;
4 |
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.ControllerAdvice;
8 | import org.springframework.web.bind.annotation.ExceptionHandler;
9 | import org.springframework.web.bind.annotation.ResponseStatus;
10 |
11 | import info.thecodinglive.exception.UserNotFoundException;
12 | import info.thecodinglive.model.ApiErrorDetail;
13 |
14 | @ControllerAdvice
15 | public class ApiExceptionHandler {
16 | @ExceptionHandler(UserNotFoundException.class)
17 | @ResponseStatus(HttpStatus.NOT_FOUND)
18 | public ResponseEntity handleUserNotFoundException(UserNotFoundException unfe){
19 | ApiErrorDetail errorDetail = new ApiErrorDetail();
20 | errorDetail.setTimeStamp(new Date());
21 | errorDetail.setCode(1002);
22 | errorDetail.setMessage(unfe.getMessage());
23 |
24 | return new ResponseEntity(errorDetail, HttpStatus.NOT_FOUND);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/exception/ThrowExample.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.exception;
2 |
3 | /**
4 | * Created by ysj on 2017-09-27.
5 | */
6 | public class ThrowExample {
7 | void validAge(int age){
8 | if(age<19)
9 | throw new ArithmeticException("소주를 구매할 수 없습니다.");
10 | else
11 | System.out.println("소주를 구매할 수 있습니다.");
12 | }
13 | public static void main(String args[]){
14 | ThrowExample obj = new ThrowExample();
15 | obj.validAge(13);
16 | System.out.println("end");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/exception/ThrowsExample.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.exception;
2 |
3 | /**
4 | * Created by ysj on 2017-09-27.
5 | */
6 | public class ThrowsExample {
7 | int division(int a, int b) throws ArithmeticException{
8 | int t = a/b;
9 | return t;
10 | }
11 | public static void main(String args[]){
12 | ThrowsExample obj = new ThrowsExample();
13 | try{
14 | System.out.println(obj.division(15,0));
15 | }
16 | catch(ArithmeticException e){
17 | System.out.println("0으로 나눌 수 없습니다.");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/exception/UserNotFoundException.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.exception;
2 |
3 | public class UserNotFoundException extends RuntimeException{
4 | private static final long serialVersionUID = 1L;
5 |
6 | public UserNotFoundException() {
7 | }
8 |
9 | public UserNotFoundException(String message) {
10 | super(message);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/model/ApiErrorDetail.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import java.util.Date;
5 |
6 | public class ApiErrorDetail {
7 | private String message;
8 | private int code;
9 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
10 | private Date timeStamp;
11 | private String status;
12 |
13 | public String getStatus() {
14 | return status;
15 | }
16 |
17 | public void setStatus(String status) {
18 | this.status = status;
19 | }
20 |
21 | public String getMessage() {
22 | return message;
23 | }
24 |
25 | public void setMessage(String message) {
26 | this.message = message;
27 | }
28 |
29 | public int getCode() {
30 | return code;
31 | }
32 |
33 | public void setCode(int code) {
34 | this.code = code;
35 | }
36 |
37 | public Date getTimeStamp() {
38 | return timeStamp;
39 | }
40 |
41 | public void setTimeStamp(Date timeStamp) {
42 | this.timeStamp = timeStamp;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/model/UserVO.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import java.io.Serializable;
4 |
5 | import javax.validation.constraints.NotNull;
6 |
7 | public class UserVO implements Serializable{
8 | private String id;
9 |
10 | @NotNull(message = "userName필드가 null입니다.")
11 | private String userName;
12 |
13 | private String email;
14 |
15 | public UserVO() {
16 | }
17 |
18 | public UserVO(String id, String userName, String email) {
19 | this.id = id;
20 | this.userName = userName;
21 | this.email = email;
22 | }
23 |
24 | public String getId() {
25 | return id;
26 | }
27 |
28 | public void setId(String id) {
29 | this.id = id;
30 | }
31 |
32 | public String getUserName() {
33 | return userName;
34 | }
35 |
36 | public void setUserName(String userName) {
37 | this.userName = userName;
38 | }
39 |
40 | public String getEmail() {
41 | return email;
42 | }
43 |
44 | public void setEmail(String email) {
45 | this.email = email;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "UserVO{" +
51 | "id='" + id + '\'' +
52 | ", userName='" + userName + '\'' +
53 | ", email='" + email + '\'' +
54 | '}';
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/repository/UserRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.repository;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.mybatis.spring.SqlSessionTemplate;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Repository;
10 |
11 | import info.thecodinglive.model.UserVO;
12 |
13 | /**
14 | * Created by yun_dev1 on 2017-01-06.
15 | */
16 | @Repository
17 | public class UserRepository {
18 | private static final String MAPPER_NAME_SPACE = "user.mapper.userMapper.";
19 |
20 | @Autowired
21 | private SqlSessionTemplate sqlSessionTemplate;
22 |
23 | public List getUserInfoAll(){
24 | return sqlSessionTemplate.selectList(MAPPER_NAME_SPACE + "selectUserInfoAll");
25 | }
26 |
27 | public void adduserInfo(UserVO userVO){
28 | sqlSessionTemplate.insert(MAPPER_NAME_SPACE+ "addUserInfo", userVO);
29 | }
30 |
31 | public List findByUserNameLike(String userName){
32 | Map params = new HashMap();
33 | params.put("userName", userName);
34 |
35 | return sqlSessionTemplate.selectList(MAPPER_NAME_SPACE + "findByUserNameLike", params);
36 | }
37 |
38 | public UserVO findByUserName(String userName){
39 | Map params = new HashMap();
40 | params.put("userName", userName);
41 |
42 | return sqlSessionTemplate.selectOne(MAPPER_NAME_SPACE + "findByUserName", params);
43 | }
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/ch08/src/main/java/info/thecodinglive/service/UserService.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.service;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Service;
5 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
6 |
7 | import info.thecodinglive.model.UserVO;
8 | import info.thecodinglive.repository.UserRepository;
9 |
10 | @Service
11 | public class UserService {
12 | @Autowired
13 | UserRepository userRepository;
14 |
15 | public Iterable findAllUserInfo(){
16 | Iterable allUsers = userRepository.getUserInfoAll();
17 | return allUsers;
18 | }
19 |
20 | public void dummyInfo(){
21 | ServletUriComponentsBuilder.fromCurrentRequest()
22 | .toUriString();
23 | }
24 |
25 | public void createUser(UserVO userVO){
26 | System.out.println("userVO::" + userVO.toString());
27 | userRepository.adduserInfo(userVO);
28 | }
29 |
30 | public Iterable extends UserVO> findByLikeUserName(String userName){
31 | Iterable resultList = userRepository.findByUserNameLike(userName);
32 | return resultList;
33 | }
34 |
35 | public UserVO findByOneUserName(String userName){
36 | UserVO userVO = userRepository.findByUserName(userName);
37 | return userVO;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ch08/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:mem:testdb
2 | spring.datasource.driver-class-name=org.h2.Driver
3 | spring.datasource.username=sa
4 | spring.datasource.password=
5 | spring.database.platform=h2
6 | spring.datasource.schema=schema-h2.sql
7 | spring.datasource.data=data-h2.sql
8 | spring.datasource.separator=;
9 | spring.datasource.sql-script-encoding=UTF-8
10 |
11 | #h2 config
12 | spring.h2.console.enabled=true
13 | spring.h2.console.path=/h2-console
14 | #remote access
15 | spring.h2.console.settings.web-allow-others=false
16 | #enable trace output
17 | spring.h2.console.settings.trace=false
--------------------------------------------------------------------------------
/ch08/src/main/resources/data-h2.sql:
--------------------------------------------------------------------------------
1 | insert into TBL_USER values('test1', 'kim1', 'test1@test.com');
2 | insert into TBL_USER values('test2', 'kim2', 'test2@test.com');
3 | insert into TBL_USER values('test3', 'kim3', 'test3@test.com');
4 | insert into TBL_USER values('test4', 'kim4', 'test4@test.com');
5 | insert into TBL_USER values('test5', 'kim5', 'test5@test.com');
6 | insert into TBL_USER values('test6', 'kim6', 'test6@test.com');
7 | insert into TBL_USER values('test7', 'kim7', 'test7@test.com');
8 |
--------------------------------------------------------------------------------
/ch08/src/main/resources/messages.properties:
--------------------------------------------------------------------------------
1 | error.username.notnull=유저네임값이누락되었습니다.
--------------------------------------------------------------------------------
/ch08/src/main/resources/mybatis/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ch08/src/main/resources/schema-h2.sql:
--------------------------------------------------------------------------------
1 | drop table tbl_user if exists;
2 |
3 | CREATE TABLE tbl_user (
4 | id varchar(40) NOT NULL,
5 | username varchar(45) NOT NULL,
6 | email varchar(45) NOT NULL
7 | );
--------------------------------------------------------------------------------
/ch08/src/main/resources/user/mapper/userMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
27 |
28 |
29 |
39 |
40 |
50 |
--------------------------------------------------------------------------------
/ch08/src/test/java/controllerTest/UserControllerTest.java:
--------------------------------------------------------------------------------
1 | package controllerTest;
2 |
3 | import static org.hamcrest.Matchers.containsString;
4 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
5 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
6 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
7 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
8 |
9 | import info.thecodinglive.Ch8Main;
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 | import org.springframework.beans.factory.annotation.Autowired;
13 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
14 | import org.springframework.boot.test.context.SpringBootTest;
15 | import org.springframework.test.context.junit4.SpringRunner;
16 | import org.springframework.test.web.servlet.MockMvc;
17 |
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest(
20 | classes = {Ch8Main.class},
21 | webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
22 | @AutoConfigureMockMvc
23 | public class UserControllerTest {
24 | @Autowired
25 | private MockMvc mockMvc;
26 |
27 | @Test
28 | public void getUserListApiResponse() throws Exception{
29 | this.mockMvc.perform(get("/user/list")).andDo(print()).andExpect(status().isOk())
30 | .andExpect(content().string(containsString("jpub.com")));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/ch08/src/test/java/daoTest/MybatisTestConfig.java:
--------------------------------------------------------------------------------
1 | package daoTest;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.test.annotation.Rollback;
5 | import org.springframework.test.context.ContextConfiguration;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 | import org.springframework.test.context.support.AnnotationConfigContextLoader;
8 |
9 | import info.thecodinglive.config.MyBatisConfig;
10 |
11 | @RunWith(SpringRunner.class)
12 | @ContextConfiguration(classes = MyBatisConfig.class, loader = AnnotationConfigContextLoader.class)
13 | @Rollback
14 | public class MybatisTestConfig {
15 | }
16 |
--------------------------------------------------------------------------------
/ch08/src/test/java/daoTest/UserDaoTest.java:
--------------------------------------------------------------------------------
1 | package daoTest;
2 |
3 | import org.junit.Test;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.mock.mockito.MockBean;
6 |
7 | import info.thecodinglive.model.UserVO;
8 | import info.thecodinglive.repository.UserRepository;
9 |
10 | import static org.mockito.BDDMockito.given;
11 |
12 | public class UserDaoTest extends MybatisTestConfig {
13 | @Autowired
14 | private UserRepository userRepository;
15 |
16 |
17 | @Test
18 | public void testList(){
19 | System.out.println(userRepository.getUserInfoAll());
20 | }
21 |
22 | @Test
23 | public void createUser(){
24 | UserVO userVO = new UserVO();
25 | userVO.setId("jpub115");
26 | userVO.setUserName("홍길동");
27 | userVO.setEmail("test4@jpub.com");
28 | userRepository.adduserInfo(userVO);
29 | System.out.println(userRepository.getUserInfoAll());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ch08/src/test/java/serviceTest/ServiceTestConfig.java:
--------------------------------------------------------------------------------
1 | package serviceTest;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.springframework.test.annotation.Rollback;
5 | import org.springframework.test.context.ContextConfiguration;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 | import org.springframework.test.context.support.AnnotationConfigContextLoader;
8 |
9 | import info.thecodinglive.config.ServiceConfig;
10 |
11 | @RunWith(SpringRunner.class)
12 | @ContextConfiguration(classes = ServiceConfig.class, loader = AnnotationConfigContextLoader.class)
13 | @Rollback
14 | public class ServiceTestConfig {
15 | }
16 |
--------------------------------------------------------------------------------
/ch08/src/test/java/serviceTest/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package serviceTest;
2 |
3 | import org.junit.Test;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.test.mock.mockito.MockBean;
6 |
7 | import info.thecodinglive.service.UserService;
8 |
9 | public class UserServiceTest extends ServiceTestConfig {
10 | @Autowired
11 | UserService userService;
12 |
13 | @Test
14 | public void findUserList(){
15 | userService.findAllUserInfo();
16 | }
17 |
18 | @Test
19 | public void findUserNameTest(){
20 | String uname = "kim1";
21 | System.out.println(userService.findByOneUserName(uname));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ch08/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:mem:testdb
2 | spring.datasource.driver-class-name=org.h2.Driver
3 | spring.datasource.username=sa
4 | spring.datasource.password=
5 | spring.database.platform=h2
6 | spring.datasource.schema=schema-h2.sql
7 | spring.datasource.data=data-h2.sql
8 | spring.datasource.separator=;
9 | spring.datasource.sql-script-encoding=UTF-8
10 |
11 | #h2 config
12 | spring.h2.console.enabled=true
13 | spring.h2.console.path=/h2-console
14 | #remote access
15 | spring.h2.console.settings.web-allow-others=false
16 | #enable trace output
17 | spring.h2.console.settings.trace=false
--------------------------------------------------------------------------------
/ch08/src/test/resources/data-h2.sql:
--------------------------------------------------------------------------------
1 | insert into TBL_USER values('test1', 'kim', 'test1@jpub.com');
2 | insert into TBL_USER values('test2', 'kim1', 'test2@jpub.com');
3 | insert into TBL_USER values('test3', 'kim3', 'test3@jpub.com');
--------------------------------------------------------------------------------
/ch08/src/test/resources/schema-h2.sql:
--------------------------------------------------------------------------------
1 | drop table tbl_user if exists;
2 |
3 | CREATE TABLE tbl_user (
4 | id varchar(40) NOT NULL,
5 | username varchar(45) NOT NULL,
6 | email varchar(45) NOT NULL
7 | );
--------------------------------------------------------------------------------
/ch09/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript{
2 | ext {
3 | springBootVersion = '1.5.8.RELEASE'
4 | }
5 | repositories{
6 | jcenter()
7 | mavenCentral()
8 | }
9 | dependencies{
10 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
11 | classpath('se.transmode.gradle:gradle-docker:1.2')
12 | }
13 | }
14 |
15 | apply plugin: 'java'
16 | apply plugin: 'org.springframework.boot'
17 | apply plugin: 'docker'
18 |
19 | sourceCompatibility = 1.8
20 | targetCompatibility = 1.8
21 |
22 | springBoot{
23 | executable = true
24 | }
25 |
26 | jar{
27 | baseName = 'ch09-boot'
28 | version = '0.0.1'
29 | }
30 |
31 |
32 |
33 | repositories {
34 | jcenter()
35 | }
36 |
37 | dependencies {
38 | compile 'org.springframework.boot:spring-boot-starter-web'
39 |
40 | //db
41 | runtime group: 'com.h2database', name: 'h2', version: '1.4.193'
42 | compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '1.5.7'
43 | compile group: 'com.zaxxer', name: 'HikariCP', version: '2.5.1'
44 | compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
45 |
46 | testCompile("org.springframework.boot:spring-boot-starter-test")
47 | }
48 |
49 | task buildDocker(type: Docker, dependsOn: build){
50 | push = false
51 | applicationName = jar.baseName
52 | tagVersion = jar.version
53 | dockerfile = file('src/docker/Dockerfile')
54 | doFirst{
55 | copy{
56 | from jar
57 | into stageDir
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/ch09/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch09/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch09/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 05 16:19:28 KST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
7 |
--------------------------------------------------------------------------------
/ch09/src/docker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8
2 | VOLUME /tmp
3 | ADD ch09-boot-0.0.1.jar app.jar
4 | RUN bash -c 'touch /app.jar'
5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
--------------------------------------------------------------------------------
/ch09/src/main/java/info/thecodinglive/Chapter9Main.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.boot.CommandLineRunner;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.context.event.ApplicationStartingEvent;
7 | import org.springframework.boot.system.ApplicationPidFileWriter;
8 | import org.springframework.context.ApplicationListener;
9 | import org.springframework.context.annotation.EnableAspectJAutoProxy;
10 |
11 | @EnableAspectJAutoProxy
12 | @SpringBootApplication
13 | public class Chapter9Main implements CommandLineRunner, ApplicationListener {
14 | public static void main(String[] args) {
15 | SpringApplication.run(Chapter9Main.class, args);
16 | }
17 |
18 | @Override
19 | public void onApplicationEvent(ApplicationStartingEvent event) {
20 | new ApplicationPidFileWriter("Ch09.pid");
21 | }
22 |
23 | @Override
24 | public void run(String... args) throws Exception {
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ch09/src/main/java/info/thecodinglive/aspect/Logging.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.aspect;
2 |
3 | /**
4 | * Created by jins on 2017-01-30.
5 | */
6 | public interface Logging {
7 | public void log(String str);
8 | }
9 |
--------------------------------------------------------------------------------
/ch09/src/main/java/info/thecodinglive/aspect/LoggingConsole.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.aspect;
2 |
3 | /**
4 | * Created by jins on 2017-01-30.
5 | */
6 | public class LoggingConsole implements Logging {
7 | @Override
8 | public void log(String str) {
9 | // logger.debug(str);
10 | System.out.println("loggingconsole::" + str);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/ch09/src/main/java/info/thecodinglive/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import info.thecodinglive.model.UserVO;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | @RestController
10 | @RequestMapping("/user")
11 | public class UserController {
12 |
13 | @RequestMapping("/list")
14 | public ResponseEntity> findUserInfoAll() throws Exception{
15 | return null;
16 | }
17 |
18 | @RequestMapping("/regist")
19 | public ResponseEntity> registUser(@RequestBody UserVO userVO){
20 | return null;
21 | }
22 |
23 | @RequestMapping("/search")
24 | public ResponseEntity> findUserListbyNames(@RequestParam("username") String userName){
25 | return null;
26 | }
27 |
28 | @RequestMapping("/{username}")
29 | public ResponseEntity> findByUserOne(@PathVariable("username") String userName){
30 | return null;
31 | }
32 |
33 | @RequestMapping("/exception")
34 | public ResponseEntity> exceptionUser()throws Exception{
35 | throw new Exception("exception occur");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/ch09/src/main/java/info/thecodinglive/model/UserVO.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.model;
2 |
3 | import java.io.Serializable;
4 |
5 |
6 | /**
7 | * Created by yun_dev1 on 2016-07-28.
8 | */
9 |
10 | public class UserVO implements Serializable{
11 | private String id;
12 | private String userName;
13 | private String passWord;
14 |
15 | public UserVO() {
16 | }
17 |
18 | public UserVO(String id, String userName, String passWord) {
19 | this.id = id;
20 | this.userName = userName;
21 | this.passWord = passWord;
22 | }
23 |
24 | public String getId() {
25 | return id;
26 | }
27 |
28 | public void setId(String id) {
29 | this.id = id;
30 | }
31 |
32 | public String getUserName() {
33 | return userName;
34 | }
35 |
36 | public void setUserName(String userName) {
37 | this.userName = userName;
38 | }
39 |
40 | public String getPassword() {
41 | return passWord;
42 | }
43 |
44 | public void setPassword(String passWord) {
45 | this.passWord = passWord;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "UserVO{" +
51 | "id='" + id + '\'' +
52 | ", userName='" + userName + '\'' +
53 | ", passWord='" + passWord + '\'' +
54 | '}';
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/ch09/src/main/resources/application-dev.properties:
--------------------------------------------------------------------------------
1 | server.port=7080
2 | spring.datasource.url=jdbc:mariadb://localhost:3306/jpub?useUnicode=yes&characterEncoding=utf8
3 | spring.datasource.classname=org.mariadb.jdbc.MySQLDataSource
4 | spring.datasource.username=jpubdev
5 | spring.datasource.password=qwer1234
6 | spring.datasource.separator=;
7 | spring.datasource.sql-script-encoding=UTF-8
8 | spring.database.platform=mariadb
9 | spring.datasource.schema=schema-mariadb.sql
10 | spring.datasource.data=data-mariadb.sql
11 | spring.datasource.continue-on-error=true
12 |
--------------------------------------------------------------------------------
/ch09/src/main/resources/application-prod.properties:
--------------------------------------------------------------------------------
1 | server.port=7080
--------------------------------------------------------------------------------
/ch09/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:mem:station
2 | spring.datasource.driver-class-name=org.h2.Driver
3 | spring.datasource.username=sa
4 | spring.datasource.password=
5 | spring.database.platform=h2
6 | spring.datasource.schema=classpath:schema-h2.sql
7 | spring.datasource.data=classpath:data-h2.sql
8 |
9 | spring.datasource.separator=;
10 | spring.datasource.sql-script-encoding=UTF-8
11 | #h2 config
12 | spring.h2.console.enabled=true
13 | spring.h2.console.path=/h2-console
14 | #remote access
15 | spring.h2.console.settings.web-allow-others=false
16 | #enable trace output
17 | spring.h2.console.settings.trace=false
--------------------------------------------------------------------------------
/ch09/src/main/resources/data-h2.sql:
--------------------------------------------------------------------------------
1 | insert into TBL_USER values('test1', 'kim', '1234');
2 | insert into TBL_USER values('test2', 'kim1', '1234');
3 | insert into TBL_USER values('test3', 'kim3', '1234');
--------------------------------------------------------------------------------
/ch09/src/main/resources/data-mariadb.sql:
--------------------------------------------------------------------------------
1 | insert into TBL_USER values('test1', 'kim', '1234');
2 | insert into TBL_USER values('test2', 'kim1', '1234');
3 | insert into TBL_USER values('test3', 'kim3', '1234');
--------------------------------------------------------------------------------
/ch09/src/main/resources/schema-h2.sql:
--------------------------------------------------------------------------------
1 | drop table tbl_user if exists;
2 |
3 | CREATE TABLE tbl_user (
4 | id varchar(40) NOT NULL,
5 | username varchar(45) NOT NULL,
6 | password varchar(45) NOT NULL
7 | );
--------------------------------------------------------------------------------
/ch09/src/main/resources/schema-mariadb.sql:
--------------------------------------------------------------------------------
1 | use jpub;
2 | CREATE OR REPLACE TABLE TBL_USER (
3 | id varchar(40) NOT NULL,
4 | username varchar(45) NOT NULL,
5 | password varchar(45) NOT NULL
6 | );
--------------------------------------------------------------------------------
/ch09/src/test/java/daoTest/UserDaoTest.java:
--------------------------------------------------------------------------------
1 | package daoTest;
2 |
3 | import org.junit.Ignore;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.test.context.ContextConfiguration;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 | import org.springframework.test.context.support.AnnotationConfigContextLoader;
10 |
11 | import info.thecodinglive.config.MyBatisConfig;
12 | import info.thecodinglive.model.UserVO;
13 | import info.thecodinglive.repository.UserRepository;
14 |
15 | /**
16 | * Created by yun_dev1 on 2017-01-24.
17 | */
18 | @RunWith(SpringJUnit4ClassRunner.class)
19 | @ContextConfiguration(classes = MyBatisConfig.class, loader = AnnotationConfigContextLoader.class)
20 | public class UserDaoTest {
21 | @Autowired
22 | private UserRepository userRepository;
23 |
24 | @Ignore
25 | @Test
26 | public void testList() {
27 | userRepository.getUserInfoAll();
28 | }
29 |
30 | @Ignore
31 | @Test
32 | public void createUser() {
33 | UserVO userVO = new UserVO();
34 | userVO.setId("jpub115");
35 | userVO.setPassword("qwer1234");
36 | userVO.setUserName("현지환");
37 | userRepository.adduserInfo(userVO);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ch09/src/test/java/serviceTest/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package serviceTest;
2 |
3 | import org.junit.Ignore;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.test.context.ContextConfiguration;
8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9 | import org.springframework.test.context.support.AnnotationConfigContextLoader;
10 |
11 | import info.thecodinglive.config.ServiceConfig;
12 | import info.thecodinglive.service.UserService;
13 |
14 | /**
15 | * Created by jins on 2017-01-30.
16 | */
17 | @RunWith(SpringJUnit4ClassRunner.class)
18 | @ContextConfiguration(classes = ServiceConfig.class, loader = AnnotationConfigContextLoader.class)
19 | public class UserServiceTest {
20 | @Autowired
21 | UserService userService;
22 |
23 | @Ignore
24 | @Test
25 | public void findUserList() {
26 | userService.findAllUserInfo();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/ch09/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:mem:testdb
2 | spring.datasource.driver-class-name=org.h2.Driver
3 | spring.datasource.username=sa
4 | spring.datasource.password=
5 | spring.database.platform=h2
6 | spring.datasource.schema=classpath:schema-h2.sql
7 | spring.datasource.data=classpath:data-h2.sql
8 | spring.datasource.separator=;
9 | spring.datasource.sql-script-encoding=UTF-8
10 | spring.datasource.continue-on-error=true
11 |
12 | #h2 config
13 | spring.h2.console.enabled=true
14 | spring.h2.console.path=/h2-console
15 | #remote access
16 | spring.h2.console.settings.web-allow-others=false
17 | #enable trace output
18 | spring.h2.console.settings.trace=false
19 |
--------------------------------------------------------------------------------
/ch09/src/test/resources/data-h2.sql:
--------------------------------------------------------------------------------
1 | insert into TBL_USER values('test1', 'kim', '1234');
2 | insert into TBL_USER values('test2', 'kim1', '1234');
3 | insert into TBL_USER values('test3', 'kim3', '1234');
--------------------------------------------------------------------------------
/ch09/src/test/resources/schema-h2.sql:
--------------------------------------------------------------------------------
1 | drop table tbl_user if exists;
2 |
3 | CREATE TABLE tbl_user (
4 | id varchar(40) NOT NULL,
5 | username varchar(45) NOT NULL,
6 | password varchar(45) NOT NULL
7 | );
--------------------------------------------------------------------------------
/ch10/build.gradle:
--------------------------------------------------------------------------------
1 | plugins{
2 | id 'java'
3 | id 'org.springframework.boot' version '1.5.8.RELEASE'
4 | }
5 |
6 | repositories {
7 | jcenter()
8 | }
9 |
10 | dependencies {
11 | compile("org.springframework.boot:spring-boot-starter-web")
12 | compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.5.8.RELEASE'
13 | }
14 |
--------------------------------------------------------------------------------
/ch10/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch10/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch10/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 01 19:42:26 KST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
7 |
--------------------------------------------------------------------------------
/ch10/src/main/java/info/thecodinglive/SpringApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.boot.CommandLineRunner;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.annotation.Bean;
7 |
8 | @SpringBootApplication
9 | public class SpringApp {
10 | public static void main(String ar[])
11 | {
12 | SpringApplication.run(SpringApp.class);
13 | }
14 |
15 | @Bean
16 | public CommandLineRunner runner() {
17 | return (a) -> {
18 | System.out.println("runnable jar running");
19 | };
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ch10/src/main/java/info/thecodinglive/controller/IndexController.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | /**
7 | * Created by yun_dev1 on 2016-12-20.
8 | */
9 | @RestController
10 | public class IndexController {
11 | @RequestMapping("/")
12 | public String indexController(){
13 | return "info";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ch10/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | management.security.enabled=false
2 | management.port=18000
3 | #endpoints.env.enabled=false
4 | #management.health.defaults.enabled=true
5 | #management.health.diskspace.enabled=true
--------------------------------------------------------------------------------
/ch11-a/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE")
7 | }
8 | }
9 |
10 | apply plugin: 'spring-boot'
11 | apply plugin: 'java'
12 |
13 |
14 | repositories {
15 | jcenter()
16 | }
17 |
18 |
19 | dependencies {
20 | compile("org.springframework.boot:spring-boot-starter-web") {
21 | exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
22 | }
23 | compile ("org.springframework.boot:spring-boot-starter-undertow") {
24 | exclude group: "io.undertow", module: "undertow-websockets-jsr"
25 | }
26 | //compile("org.springframework.boot:spring-boot-starter-cache")
27 |
28 | compile 'org.slf4j:slf4j-api:1.7.21'
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/ch11-a/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch11-a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch11-a/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 05 16:19:28 KST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
7 |
--------------------------------------------------------------------------------
/ch11-a/src/main/java/info/thecodinglive/Car.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | public class Car {
4 | private String name;
5 | private String color;
6 |
7 | public Car(String name, String color) {
8 | this.name = name;
9 | this.color = color;
10 | }
11 |
12 | public Car(String name) {
13 | this.name = name;
14 | }
15 |
16 | @Override
17 | public String toString() {
18 | return "Car{" +
19 | "name='" + name + '\'' +
20 | ", color='" + color + '\'' +
21 | '}';
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getColor() {
33 | return color;
34 | }
35 |
36 | public void setColor(String color) {
37 | this.color = color;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ch11-a/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch11-a/src/main/resources/application.properties
--------------------------------------------------------------------------------
/ch11-a/src/main/resources/ehcache.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/ch11-b/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE")
7 | }
8 | }
9 |
10 | apply plugin: 'spring-boot'
11 | apply plugin: 'java'
12 |
13 |
14 | repositories {
15 | jcenter()
16 | }
17 |
18 |
19 | dependencies {
20 | compile("org.springframework.boot:spring-boot-starter-web") {
21 | exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
22 | }
23 | compile ("org.springframework.boot:spring-boot-starter-undertow") {
24 | exclude group: "io.undertow", module: "undertow-websockets-jsr"
25 | }
26 |
27 | compile group: 'org.ehcache', name: 'jcache', version: '1.0.1'
28 | compile group: 'javax.cache', name: 'cache-api', version: '1.0.0'
29 |
30 | compile 'org.slf4j:slf4j-api:1.7.21'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/ch11-b/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch11-b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch11-b/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 05 16:19:28 KST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
7 |
--------------------------------------------------------------------------------
/ch11-b/src/main/java/info/thecodinglive/Car.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | public class Car {
4 | private String name;
5 | private String color;
6 |
7 | public Car(String name, String color) {
8 | this.name = name;
9 | this.color = color;
10 | }
11 |
12 | public Car(String name) {
13 | this.name = name;
14 | }
15 |
16 | @Override
17 | public String toString() {
18 | return "Car{" +
19 | "name='" + name + '\'' +
20 | ", color='" + color + '\'' +
21 | '}';
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getColor() {
33 | return color;
34 | }
35 |
36 | public void setColor(String color) {
37 | this.color = color;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ch11-b/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch11-b/src/main/resources/application.properties
--------------------------------------------------------------------------------
/ch11-c/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE")
7 | }
8 | }
9 |
10 | apply plugin: 'spring-boot'
11 | apply plugin: 'java'
12 |
13 |
14 | repositories {
15 | jcenter()
16 | }
17 |
18 |
19 | dependencies {
20 | compile("org.springframework.boot:spring-boot-starter-web") {
21 | exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
22 | }
23 | compile ("org.springframework.boot:spring-boot-starter-undertow") {
24 | exclude group: "io.undertow", module: "undertow-websockets-jsr"
25 | }
26 | compile("org.springframework.boot:spring-boot-starter-cache")
27 | compile group: 'javax.cache', name: 'cache-api', version: '1.0.0'
28 | compile group: 'net.sf.ehcache', name: 'ehcache', version: '2.10.4'
29 |
30 | compile 'org.slf4j:slf4j-api:1.7.21'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/ch11-c/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch11-c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ch11-c/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 05 16:19:28 KST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
7 |
--------------------------------------------------------------------------------
/ch11-c/src/main/java/info/thecodinglive/CacheConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | import org.springframework.cache.annotation.CachingConfigurerSupport;
4 | import org.springframework.cache.annotation.EnableCaching;
5 | import org.springframework.cache.interceptor.KeyGenerator;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | import java.lang.reflect.Method;
10 |
11 | @EnableCaching
12 | @Configuration
13 | public class CacheConfig extends CachingConfigurerSupport {
14 |
15 | @Bean
16 | public KeyGenerator keyGenerator() {
17 | return new KeyGenerator() {
18 | @Override
19 | public Object generate(Object o, Method method, Object... objects) {
20 | StringBuilder sb = new StringBuilder();
21 | sb.append(o.getClass().getName());
22 | sb.append(method.getName());
23 | for (Object obj : objects) {
24 | sb.append(obj.toString());
25 | }
26 | return sb.toString().hashCode();
27 | }
28 | };
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ch11-c/src/main/java/info/thecodinglive/Car.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive;
2 |
3 | public class Car {
4 | private String name;
5 | private String color;
6 |
7 | public Car(String name, String color) {
8 | this.name = name;
9 | this.color = color;
10 | }
11 |
12 | public Car(String name) {
13 | this.name = name;
14 | }
15 |
16 | @Override
17 | public String toString() {
18 | return "Car{" +
19 | "name='" + name + '\'' +
20 | ", color='" + color + '\'' +
21 | '}';
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getColor() {
33 | return color;
34 | }
35 |
36 | public void setColor(String color) {
37 | this.color = color;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ch11-c/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/ch11-c/src/main/resources/application.properties
--------------------------------------------------------------------------------
/ch11-c/src/main/resources/ehcache.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Oct 17 00:13:30 KST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip
7 |
--------------------------------------------------------------------------------
/memberApp/README.md:
--------------------------------------------------------------------------------
1 | 헤로쿠로 배포
--------------------------------------------------------------------------------
/memberApp/gradle/querydsl.gradle:
--------------------------------------------------------------------------------
1 | def querydslOutput = file('src/main/generated')
2 |
3 | task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
4 | file(new File(projectDir, "/src/main/generated")).deleteDir()
5 | file(new File(projectDir, "/src/main/generated")).mkdirs()
6 | source = sourceSets.main.java
7 | classpath = configurations.compile + configurations.compileOnly
8 | options.compilerArgs = [
9 | "-proc:only",
10 | "-processor", 'com.querydsl.apt.jpa.JPAAnnotationProcessor,lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
11 | ]
12 | destinationDir = file('src/main/generated')
13 | }
14 |
15 | compileJava {
16 | dependsOn generateQueryDSL
17 | }
18 |
19 | clean.doFirst{
20 | delete querydslOutput
21 | }
--------------------------------------------------------------------------------
/memberApp/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thecodinglive/JPub-JavaWebService/f6206358b8e30b1f9330551e19665bd36f1ec76d/memberApp/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/memberApp/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 21 16:33:40 KST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https://services.gradle.org/distributions/gradle-4.1-bin.zip
7 |
--------------------------------------------------------------------------------
/memberApp/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * This settings file was generated by the Gradle 'init' task.
3 | *
4 | * The settings file is used to specify which projects to include in your build.
5 | * In a single project build this file can be empty or even removed.
6 | *
7 | * Detailed information about configuring a multi-project build in Gradle can be found
8 | * in the user guide at https://docs.gradle.org/3.5/userguide/multi_project_builds.html
9 | */
10 |
11 | /*
12 | // To declare projects as part of a multi-project build use the 'include' method
13 | include 'shared'
14 | include 'api'
15 | include 'services:webservice'
16 | */
17 |
18 | rootProject.name = 'bootBoard'
19 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/MemberApp.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.domain.EntityScan;
6 | import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
7 |
8 | @EntityScan(
9 | basePackageClasses = {Jsr310JpaConverters.class},
10 | basePackages = {"info.thecodinglive.member.model"})
11 | @SpringBootApplication
12 | public class MemberApp {
13 | public static void main(String ar[]){
14 | SpringApplication.run(MemberApp.class, ar);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/config/AuditConfig.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.data.domain.AuditorAware;
6 | import org.springframework.data.jpa.domain.support.AuditingEntityListener;
7 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
8 | import org.springframework.security.core.Authentication;
9 | import org.springframework.security.core.context.SecurityContextHolder;
10 |
11 | @Configuration
12 | @EnableJpaAuditing
13 | public class AuditConfig {
14 | @Bean
15 | public AuditorAware createAuditorProvider() {
16 | return new SecurityAuditor();
17 | }
18 |
19 | @Bean
20 | public AuditingEntityListener createAuditingListener() {
21 | return new AuditingEntityListener();
22 | }
23 |
24 | public static class SecurityAuditor implements AuditorAware {
25 | @Override
26 | public String getCurrentAuditor() {
27 | Authentication auth = SecurityContextHolder.getContext().getAuthentication();
28 | if (null == auth || !auth.isAuthenticated()) {
29 | return null;
30 | }
31 | String username = auth.getName();
32 | return username;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/model/AbstractEntityModel.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.model;
2 |
3 | import java.io.Serializable;
4 | import java.time.LocalDateTime;
5 |
6 | import javax.persistence.Column;
7 | import javax.persistence.EntityListeners;
8 | import javax.persistence.MappedSuperclass;
9 |
10 | import org.springframework.data.annotation.CreatedBy;
11 | import org.springframework.data.annotation.CreatedDate;
12 | import org.springframework.data.annotation.LastModifiedBy;
13 | import org.springframework.data.annotation.LastModifiedDate;
14 | import org.springframework.data.jpa.domain.support.AuditingEntityListener;
15 |
16 | @EntityListeners(AuditingEntityListener.class)
17 | @MappedSuperclass
18 | public abstract class AbstractEntityModel implements Serializable{
19 | @CreatedDate
20 | @Column(name = "reg_date", updatable = false)
21 | private LocalDateTime createdDateTime;
22 |
23 | @LastModifiedDate
24 | @Column(name = "update_date", updatable = true)
25 | private LocalDateTime lastModifiedDateTime;
26 |
27 | @Column(name = "created_by_user", nullable = false)
28 | @CreatedBy
29 | private String createdByUser;
30 |
31 | @Column(name = "modified_by_user", nullable = false)
32 | @LastModifiedBy
33 | private String modifiedByUser;
34 | }
35 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/model/Member.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.model;
2 |
3 | import javax.jdo.annotations.Unique;
4 | import javax.persistence.Column;
5 | import javax.persistence.Entity;
6 | import javax.persistence.EnumType;
7 | import javax.persistence.Enumerated;
8 | import javax.persistence.GeneratedValue;
9 | import javax.persistence.GenerationType;
10 | import javax.persistence.Id;
11 | import javax.persistence.Table;
12 |
13 | import lombok.Getter;
14 | import lombok.Setter;
15 | import lombok.ToString;
16 |
17 | @Getter
18 | @Setter
19 | @Entity
20 | @Table(name = "tbl_member")
21 | @ToString
22 | public class Member extends AbstractEntityModel{
23 |
24 | @Id
25 | @GeneratedValue(strategy=GenerationType.IDENTITY)
26 | private long id;
27 | private String username;
28 |
29 | private String password;
30 | private String passwordConfirm;
31 | @Unique
32 | private String email;
33 |
34 | @Column(name = "role_name")
35 | @Enumerated(EnumType.STRING)
36 | private MemberRole role;
37 | }
38 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/model/MemberRole.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.model;
2 |
3 |
4 | public enum MemberRole {
5 | USER, //0
6 | ADMIN //1
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/model/RememberMeToken.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.model;
2 |
3 | import lombok.Getter;
4 | import lombok.NoArgsConstructor;
5 | import lombok.Setter;
6 | import org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken;
7 |
8 | import javax.persistence.Column;
9 | import javax.persistence.Entity;
10 | import javax.persistence.Id;
11 | import javax.persistence.Table;
12 | import java.io.Serializable;
13 | import java.util.Date;
14 |
15 | @Entity
16 | @Table(name = "persistent_logins")
17 | @Getter
18 | @Setter
19 | @NoArgsConstructor
20 | public class RememberMeToken implements Serializable{
21 | @Id
22 | @Column(name = "SERIES")
23 | private String series;
24 |
25 | @Column(name = "USERNAME", nullable = false)
26 | private String username;
27 |
28 | @Column(name = "TOKEN", nullable = false)
29 | private String token;
30 |
31 | @Column(name = "LAST_USED", nullable = false)
32 | private Date lastUsed;
33 |
34 | public RememberMeToken(PersistentRememberMeToken token) {
35 | this.series = token.getSeries();
36 | this.username = token.getUsername();
37 | this.token = token.getTokenValue();
38 | this.lastUsed = token.getDate();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/repository/MemberRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import info.thecodinglive.member.model.Member;
6 | import org.springframework.stereotype.Repository;
7 |
8 | @Repository
9 | public interface MemberRepository extends JpaRepository{
10 | Member findByEmail(String email);
11 | Member findByUsername(String username);
12 | }
13 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/repository/RememberMeTokenRepository.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.repository;
2 |
3 | import info.thecodinglive.member.model.RememberMeToken;
4 | import org.springframework.data.jpa.repository.JpaRepository;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository
10 | public interface RememberMeTokenRepository extends JpaRepository{
11 | RememberMeToken findBySeries(String series);
12 | List findByUsername(String username);
13 | }
14 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/service/MemberAccessDeniedHandler.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.service;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.security.access.AccessDeniedException;
5 | import org.springframework.security.core.Authentication;
6 | import org.springframework.security.core.context.SecurityContextHolder;
7 | import org.springframework.security.web.access.AccessDeniedHandler;
8 | import org.springframework.stereotype.Component;
9 |
10 | import javax.servlet.ServletException;
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 | import java.io.IOException;
14 |
15 | @Slf4j
16 | @Component
17 | public class MemberAccessDeniedHandler implements AccessDeniedHandler {
18 | @Override
19 | public void handle(HttpServletRequest req, HttpServletResponse res, AccessDeniedException accessDeniedException) throws IOException, ServletException {
20 | Authentication auth
21 | = SecurityContextHolder.getContext().getAuthentication();
22 |
23 | if (auth != null) {
24 | log.info("User '" + auth.getName()
25 | + "' attempted to access the protected URL: "
26 | + req.getRequestURI());
27 | }
28 |
29 | res.sendRedirect(req.getContextPath() + "/403");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/service/MemberService.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.service;
2 |
3 | import info.thecodinglive.member.model.Member;
4 |
5 | public interface MemberService {
6 | void save(Member member);
7 | Member findByUserName(String username);
8 | Member findByUserEmail(String email);
9 | }
10 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/service/MemberServiceImpl.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.service;
2 |
3 | import info.thecodinglive.member.repository.MemberRepository;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
7 | import org.springframework.stereotype.Service;
8 |
9 | import info.thecodinglive.member.model.Member;
10 |
11 | @Service("MemberService")
12 | @Slf4j
13 | public class MemberServiceImpl implements MemberService{
14 | @Autowired
15 | private MemberRepository memberRepository;
16 | @Autowired
17 | private BCryptPasswordEncoder bCryptPasswordEncoder;
18 |
19 | @Override
20 | public Member findByUserEmail(String email) {
21 | return memberRepository.findByEmail(email);
22 | }
23 |
24 | @Override
25 | public Member findByUserName(String username) {
26 | return memberRepository.findByUsername(username);
27 | }
28 |
29 | @Override
30 | public void save(Member member) {
31 | member.setPassword(bCryptPasswordEncoder.encode(member.getPassword()));
32 | member.setPasswordConfirm(bCryptPasswordEncoder.encode(member.getPasswordConfirm()));
33 | memberRepository.save(member);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/memberApp/src/main/java/info/thecodinglive/member/support/PasswordEncoderUtil.java:
--------------------------------------------------------------------------------
1 | package info.thecodinglive.member.support;
2 |
3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
4 | import org.springframework.security.crypto.password.PasswordEncoder;
5 |
6 | public class PasswordEncoderUtil implements PasswordEncoder {
7 | private PasswordEncoder passwordEncoder;
8 |
9 | public PasswordEncoderUtil() {
10 | this.passwordEncoder = new BCryptPasswordEncoder();
11 | }
12 |
13 | public PasswordEncoderUtil(PasswordEncoder passwordEncoder) {
14 | this.passwordEncoder = passwordEncoder;
15 | }
16 |
17 | @Override
18 | public String encode(CharSequence rawPassword) {
19 | return passwordEncoder.encode(rawPassword);
20 | }
21 |
22 | @Override
23 | public boolean matches(CharSequence rawPassword, String encodedPassword) {
24 | return passwordEncoder.matches(rawPassword, encodedPassword);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:h2:mem:testdb;CACHE_SIZE=10240;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=15000;MODE=MySQL;
2 | spring.datasource.platform=h2
3 | spring.datasource.separator=;
4 | spring.datasource.username=sa
5 | spring.datasource.driver-class-name=org.h2.Driver
6 | spring.datasource.sql-script-encoding=UTF-8
7 | spring.jpa.database-platform=H2
8 | spring.jpa.hibernate.ddl-auto=update
9 | spring.datasource.data=classpath:sql/data-H2.sql
10 | spring.jpa.show-sql=true
11 |
12 | spring.thymeleaf.cache=false
13 | spring.thymeleaf.mode=LEGACYHTML5
14 |
15 | spring.devtools.livereload.enabled=true
16 | spring.messages.basename=validation
17 | spring.messages.encoding=UTF-8
18 |
19 | logging.level.org.springframework.security = debug
--------------------------------------------------------------------------------
/memberApp/src/main/resources/sql/data-H2.sql:
--------------------------------------------------------------------------------
1 | insert into tbl_member (email, password, password_confirm, username, role_name) VALUES ('jins@info.com', '$2a$10$PjLG8Nr50vGQXKR63.CdMeQvvf.ZAy0ZX3BJXZnJg3FmODO9ysmt2',
2 | '$2a$10$PjLG8Nr50vGQXKR63.CdMeQvvf.ZAy0ZX3BJXZnJg3FmODO9ysmt2', '윤석진', 'ADMIN');
3 |
4 |
5 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/static/css/home.css:
--------------------------------------------------------------------------------
1 |
2 | .intro-2 {
3 | background: url("https://mdbootstrap.com/img/Photos/Others/architecture.jpg")no-repeat center center;
4 | background-size: cover;
5 | }
6 | .btn .fa {
7 | margin-left: 3px;
8 | }
9 | .top-nav-collapse {
10 | background-color: #424f95 !important;
11 | }
12 | .navbar:not(.top-nav-collapse) {
13 | background: transparent !important;
14 | }
15 | @media (max-width: 768px) {
16 | .navbar:not(.top-nav-collapse) {
17 | background: #424f95 !important;
18 | }
19 | }
20 | h6 {
21 | line-height: 1.7;
22 | }
23 | .hm-gradient .full-bg-img {
24 | background: -moz-linear-gradient(45deg, rgba(42, 27, 161, 0.6), rgba(29, 210, 177, 0.6) 100%);
25 | background: -webkit-linear-gradient(45deg, rgba(42, 27, 161, 0.6), rgba(29, 210, 177, 0.6) 100%);
26 | background: -webkit-gradient(linear, 45deg, from(rgba(42, 27, 161, 0.6)), to(rgba(29, 210, 177, 0.6)));
27 | background: -o-linear-gradient(45deg, rgba(42, 27, 161, 0.6), rgba(29, 210, 177, 0.6) 100%);
28 | background: linear-gradient(to 45deg, rgba(42, 27, 161, 0.6), rgba(29, 210, 177, 0.6) 100%);
29 | }
30 | @media (max-width: 450px) {
31 | .margins {
32 | margin-right: 1rem;
33 | margin-left: 1rem;
34 | }
35 | }
36 | @media (max-width: 740px) {
37 | .full-height,
38 | .full-height body,
39 | .full-height header,
40 | .full-height header .view {
41 | height: 1040px;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/templates/admin.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | admin
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/templates/fragments/config.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | jpub book example
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/templates/fragments/footer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/templates/home.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
SpringBoot Tutorial
25 |
Jpub Java webService
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/templates/layout/base.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/templates/welcome.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
home
10 |
userName
11 | role:
12 |
sign out
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
--------------------------------------------------------------------------------
/memberApp/src/main/resources/validation.properties:
--------------------------------------------------------------------------------
1 | NotEmpty=\uD544\uC218\uAC12\uC785\uB2C8\uB2E4.
2 | Size.userForm.username=\uC774\uB984\uC740 3\uAE00\uC790 \uC774\uC0C1 32\uC790 \uBBF8\uB9CC\uC73C\uB85C \uC785\uB825\uD558\uC138\uC694
3 | Duplicate.userForm.username=\uC911\uBCF5\uB41C \uC774\uB984\uC785\uB2C8\uB2E4.
4 | Size.userForm.password=\uD328\uC2A4\uC6CC\uB4DC\uB294 7\uAE00\uC790 \uC774\uC0C1 32\uC790 \uBBF8\uB9CC\uC73C\uB85C \uC785\uB825\uD558\uC138\uC694
5 | Diff.userForm.passwordConfirm=\uD328\uC2A4\uC6CC\uB4DC\uAC00 \uD655\uC778\uC6A9 \uD328\uC2A4\uC6CC\uB4DC\uC640 \uC11C\uB85C \uB9DE\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.
6 | Duplicate.userForm.email=\uC774\uBBF8 \uC0AC\uC6A9\uC911\uC778 \uC774\uBA54\uC77C\uC785\uB2C8\uB2E4.
--------------------------------------------------------------------------------
/memberApp/src/test/java/PasswordEncodeTest.java:
--------------------------------------------------------------------------------
1 | import info.thecodinglive.member.support.PasswordEncoderUtil;
2 | import org.junit.Test;
3 |
4 | /**
5 | * Created by ysj on 2018-03-11.
6 | */
7 | public class PasswordEncodeTest {
8 |
9 | final String pwd = "qwer1234!";
10 |
11 | @Test
12 | public void getBcrpr(){
13 | PasswordEncoderUtil pwdu = new PasswordEncoderUtil();
14 | System.out.println(pwdu.encode(pwd));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'jpub-javawebservice'
2 | include 'ch02',
3 | 'ch03',
4 | 'ch03-web',
5 | 'ch04',
6 | 'ch05',
7 | 'ch06',
8 | 'ch06-querydsl',
9 | 'ch06-mybatis',
10 | 'ch06-mariadb',
11 | 'ch07',
12 | 'ch07:CustombootStarter',
13 | 'ch07:UseCustomStarter',
14 | 'ch08',
15 | 'ch09',
16 | 'ch10' ,
17 | 'ch11-a',
18 | 'ch11-b',
19 | 'ch11-c'
20 |
--------------------------------------------------------------------------------