├── README.md ├── ch10 ├── ch10.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch10 │ │ │ ├── Ch10Application.java │ │ │ └── DemoController.java │ └── resources │ │ ├── application.properties │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── com │ └── wisely │ └── ch10 │ └── Ch10ApplicationTests.java ├── ch10_4 ├── ch10_4.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch10_4 │ │ │ ├── Ch104Application.java │ │ │ ├── dao │ │ │ └── PersonRepository.java │ │ │ ├── domain │ │ │ └── Person.java │ │ │ └── web │ │ │ └── PersonController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch10_4 │ └── Ch104ApplicationTests.java ├── ch10docker ├── ch10docker.iml ├── pom.xml └── src │ ├── main │ ├── docker │ │ └── Dockerfile │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── Ch10dockerApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── Ch10dockerApplicationTests.java ├── ch10war ├── ch10war.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch10war │ │ │ ├── Ch10warApplication.java │ │ │ ├── DemoController.java │ │ │ └── ServletInitializer.java │ └── resources │ │ ├── application.properties │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── com │ └── wisely │ └── ch10war │ └── Ch10warApplicationTests.java ├── ch11_1 ├── ch11_1.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch11_1 │ │ │ ├── DemoApplication.java │ │ │ ├── StatusEndPoint.java │ │ │ ├── StatusHealth.java │ │ │ └── StatusService.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch12_1 │ └── DemoApplicationTests.java ├── ch11_3 ├── ch11_3.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch11_3 │ │ │ └── Ch123Application.java │ └── resources │ │ ├── application.properties │ │ └── commands │ │ └── hello.groovy │ └── test │ └── java │ └── com │ └── wisely │ └── ch12_3 │ └── Ch123ApplicationTests.java ├── ch12 ├── ch12.iml ├── config │ ├── config.iml │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── docker │ │ │ ├── Dockerfile │ │ │ └── runboot.sh │ │ │ ├── java │ │ │ └── com │ │ │ │ └── wisely │ │ │ │ └── config │ │ │ │ └── ConfigApplication.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── bootstrap.yml │ │ │ └── config │ │ │ ├── person-docker.yml │ │ │ ├── person.yml │ │ │ ├── some-docker.yml │ │ │ └── some.yml │ └── target │ │ ├── classes │ │ └── com │ │ │ └── wisely │ │ │ └── config │ │ │ └── ConfigApplication.class │ │ └── maven-status │ │ └── maven-compiler-plugin │ │ └── compile │ │ └── default-compile │ │ ├── createdFiles.lst │ │ └── inputFiles.lst ├── discovery │ ├── discovery.iml │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── docker │ │ │ ├── Dockerfile │ │ │ └── runboot.sh │ │ │ ├── java │ │ │ └── com │ │ │ │ └── wisely │ │ │ │ └── discovery │ │ │ │ └── DiscoveryApplication.java │ │ │ └── resources │ │ │ └── application.yml │ └── target │ │ ├── classes │ │ └── com │ │ │ └── wisely │ │ │ └── discovery │ │ │ └── DiscoveryApplication.class │ │ └── maven-status │ │ └── maven-compiler-plugin │ │ ├── compile │ │ └── default-compile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── testCompile │ │ └── default-testCompile │ │ └── inputFiles.lst ├── docker-compose.yml ├── monitor │ ├── monitor.iml │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── docker │ │ │ ├── Dockerfile │ │ │ └── runboot.sh │ │ │ ├── java │ │ │ └── com │ │ │ │ └── wisely │ │ │ │ └── monitor │ │ │ │ └── MonitorApplication.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ └── target │ │ ├── classes │ │ └── com │ │ │ └── wisely │ │ │ └── monitor │ │ │ └── MonitorApplication.class │ │ └── maven-status │ │ └── maven-compiler-plugin │ │ ├── compile │ │ └── default-compile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── testCompile │ │ └── default-testCompile │ │ └── inputFiles.lst ├── person │ ├── person.iml │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── docker │ │ │ ├── Dockerfile │ │ │ └── runboot.sh │ │ │ ├── java │ │ │ └── com │ │ │ │ └── wisely │ │ │ │ └── person │ │ │ │ ├── PersonApplication.java │ │ │ │ ├── controller │ │ │ │ └── PersonController.java │ │ │ │ ├── dao │ │ │ │ └── PersonRepository.java │ │ │ │ └── domain │ │ │ │ └── Person.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ └── target │ │ ├── classes │ │ └── com │ │ │ └── wisely │ │ │ └── person │ │ │ ├── PersonApplication.class │ │ │ ├── controller │ │ │ └── PersonController.class │ │ │ ├── dao │ │ │ └── PersonRepository.class │ │ │ └── domain │ │ │ └── Person.class │ │ └── maven-status │ │ └── maven-compiler-plugin │ │ ├── compile │ │ └── default-compile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── testCompile │ │ └── default-testCompile │ │ └── inputFiles.lst ├── pom.xml ├── some │ ├── pom.xml │ ├── some.iml │ ├── src │ │ └── main │ │ │ ├── docker │ │ │ ├── Dockerfile │ │ │ └── runboot.sh │ │ │ ├── java │ │ │ └── com │ │ │ │ └── wisely │ │ │ │ └── some │ │ │ │ └── SomeApplication.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ └── target │ │ ├── classes │ │ └── com │ │ │ └── wisely │ │ │ └── some │ │ │ └── SomeApplication.class │ │ └── maven-status │ │ └── maven-compiler-plugin │ │ ├── compile │ │ └── default-compile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── testCompile │ │ └── default-testCompile │ │ └── inputFiles.lst └── ui │ ├── pom.xml │ ├── src │ └── main │ │ ├── docker │ │ ├── Dockerfile │ │ └── runboot.sh │ │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ui │ │ │ ├── UiApplication.java │ │ │ ├── controller │ │ │ └── UiController.java │ │ │ ├── domain │ │ │ └── Person.java │ │ │ └── service │ │ │ ├── PersonHystrixService.java │ │ │ ├── PersonService.java │ │ │ └── SomeHystrixService.java │ │ └── resources │ │ ├── application.yml │ │ ├── bootstrap.yml │ │ └── static │ │ ├── css │ │ └── application.css │ │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ │ ├── index.html │ │ ├── js │ │ └── app.js │ │ └── tpl │ │ ├── person.html │ │ └── some.html │ ├── target │ ├── classes │ │ └── com │ │ │ └── wisely │ │ │ └── ui │ │ │ ├── UiApplication.class │ │ │ ├── controller │ │ │ └── UiController.class │ │ │ ├── domain │ │ │ └── Person.class │ │ │ └── service │ │ │ ├── PersonHystrixService.class │ │ │ ├── PersonService.class │ │ │ └── SomeHystrixService.class │ └── maven-status │ │ └── maven-compiler-plugin │ │ ├── compile │ │ └── default-compile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── testCompile │ │ └── default-testCompile │ │ └── inputFiles.lst │ └── ui.iml ├── ch5_2_2 ├── ch5_2_2.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch5_2_2 │ │ │ └── Ch522Application.java │ └── resources │ │ ├── application.properties │ │ ├── application.xx │ │ └── banner.txt │ └── test │ └── java │ └── com │ └── wisely │ └── ch5_2_2 │ └── Ch522ApplicationTests.java ├── ch5_2_3 ├── ch5_2_3.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch5_2_3 │ │ │ └── Ch523Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch5_2_3 │ └── Ch523ApplicationTests.java ├── ch6_2_3 ├── ch6_2_3.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch6_2_3 │ │ │ ├── Ch623Application.java │ │ │ └── config │ │ │ └── AuthorSettings.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch6_2_3 │ └── Ch623ApplicationTests.java ├── ch6_4 ├── ch6_4.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch6_4 │ │ │ └── Ch64Application.java │ └── resources │ │ ├── application-dev.properties │ │ ├── application-prod.properties │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch6_4 │ └── Ch64ApplicationTests.java ├── ch6_5 ├── ch6_5.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch6_5 │ │ │ └── Ch65Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch6_5 │ └── Ch65ApplicationTests.java ├── ch7_2 ├── ch7_2.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ ├── Ch72Application.java │ │ │ ├── Person.java │ │ │ └── WebMvcConfig.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ ├── bootstrap │ │ │ ├── css │ │ │ │ ├── bootstrap-theme.css │ │ │ │ ├── bootstrap-theme.css.map │ │ │ │ ├── bootstrap-theme.min.css │ │ │ │ ├── bootstrap.css │ │ │ │ ├── bootstrap.css.map │ │ │ │ └── bootstrap.min.css │ │ │ ├── fonts │ │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ │ └── glyphicons-halflings-regular.woff2 │ │ │ └── js │ │ │ │ ├── bootstrap.js │ │ │ │ ├── bootstrap.min.js │ │ │ │ └── npm.js │ │ ├── jquery-1.10.2.min.js │ │ └── jquery-1.10.2.min.map │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── com │ └── wisely │ └── Ch72ApplicationTests.java ├── ch7_4 ├── .keystore ├── ch7_4.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch7_4 │ │ │ ├── Ch74Application.java │ │ │ └── CustomServletContainer.java │ └── resources │ │ ├── application.properties │ │ └── static │ │ ├── 404.html │ │ ├── favicon.ico │ │ └── index.html │ └── test │ └── java │ └── com │ └── wisely │ └── ch7_4 │ └── Ch74ApplicationTests.java ├── ch7_6 ├── ch7_6.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch7_6 │ │ │ ├── Ch76Application.java │ │ │ ├── WebMvcConfig.java │ │ │ ├── WebSecurityConfig.java │ │ │ ├── WebSocketConfig.java │ │ │ ├── domain │ │ │ ├── WiselyMessage.java │ │ │ └── WiselyResponse.java │ │ │ └── web │ │ │ └── WsController.java │ └── resources │ │ ├── application.properties │ │ ├── static │ │ ├── jquery.js │ │ ├── sockjs.min.js │ │ └── stomp.min.js │ │ └── templates │ │ ├── chat.html │ │ ├── login.html │ │ └── ws.html │ └── test │ └── java │ └── com │ └── wisely │ └── ch7_6 │ └── Ch76ApplicationTests.java ├── ch7_7 ├── ch7_7.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch7_7 │ │ │ ├── Ch77Application.java │ │ │ └── Person.java │ └── resources │ │ ├── application.properties │ │ └── static │ │ ├── action.html │ │ ├── angularjs.html │ │ ├── bootstrap.html │ │ ├── bootstrap │ │ ├── css │ │ │ ├── bootstrap-theme.css │ │ │ ├── bootstrap-theme.css.map │ │ │ ├── bootstrap-theme.min.css │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.css.map │ │ │ └── bootstrap.min.css │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ └── glyphicons-halflings-regular.woff2 │ │ └── js │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.min.js │ │ │ └── npm.js │ │ ├── jqueryui │ │ ├── images │ │ │ ├── ui-bg_diagonals-thick_18_b81900_40x40.png │ │ │ ├── ui-bg_diagonals-thick_20_666666_40x40.png │ │ │ ├── ui-bg_flat_10_000000_40x100.png │ │ │ ├── ui-bg_glass_100_f6f6f6_1x400.png │ │ │ ├── ui-bg_glass_100_fdf5ce_1x400.png │ │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ │ ├── ui-bg_gloss-wave_35_f6a828_500x100.png │ │ │ ├── ui-bg_highlight-soft_100_eeeeee_1x100.png │ │ │ ├── ui-bg_highlight-soft_75_ffe45c_1x100.png │ │ │ ├── ui-icons_222222_256x240.png │ │ │ ├── ui-icons_228ef1_256x240.png │ │ │ ├── ui-icons_ef8c08_256x240.png │ │ │ ├── ui-icons_ffd27a_256x240.png │ │ │ └── ui-icons_ffffff_256x240.png │ │ ├── jquery-ui.min.css │ │ └── jquery-ui.min.js │ │ ├── js-action │ │ ├── app.js │ │ ├── controllers.js │ │ ├── directives.js │ │ └── services.js │ │ ├── js │ │ ├── angular-route.min.js │ │ ├── angular.min.js │ │ ├── html5shiv.min.js │ │ ├── jquery.min.js │ │ └── respond.min.js │ │ └── views │ │ ├── view1.html │ │ └── view2.html │ └── test │ └── java │ └── com │ └── wisely │ └── ch7_7 │ └── Ch77ApplicationTests.java ├── ch8_2 ├── ch8_2.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ ├── Ch82Application.java │ │ │ ├── dao │ │ │ └── PersonRepository.java │ │ │ ├── domain │ │ │ └── Person.java │ │ │ ├── specs │ │ │ └── CustomerSpecs.java │ │ │ ├── support │ │ │ ├── CustomRepository.java │ │ │ ├── CustomRepositoryFactoryBean.java │ │ │ └── CustomRepositoryImpl.java │ │ │ └── web │ │ │ └── DataController.java │ └── resources │ │ ├── application.properties │ │ └── data.sql │ └── test │ └── java │ └── com │ └── wisely │ └── Ch82ApplicationTests.java ├── ch8_3 ├── ch8_3.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch8_3 │ │ │ ├── Ch83Application.java │ │ │ ├── dao │ │ │ └── PersonRepository.java │ │ │ └── domain │ │ │ └── Person.java │ └── resources │ │ ├── application.properties │ │ ├── data--.sql │ │ └── postman.crx │ └── test │ └── java │ └── com │ └── wisely │ └── ch8_3 │ └── Ch83ApplicationTests.java ├── ch8_4 ├── ch8_4.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch8_4 │ │ │ ├── Ch84Application.java │ │ │ ├── dao │ │ │ └── PersonRepository.java │ │ │ ├── domain │ │ │ └── Person.java │ │ │ ├── service │ │ │ ├── DemoService.java │ │ │ └── impl │ │ │ │ └── DemoServiceImpl.java │ │ │ └── web │ │ │ └── MyController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch8_4 │ └── Ch84ApplicationTests.java ├── ch8_5 ├── ch8_5.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch8_5 │ │ │ ├── AppConfig.java │ │ │ ├── Ch85Application.java │ │ │ ├── dao │ │ │ └── PersonRepository.java │ │ │ ├── domain │ │ │ └── Person.java │ │ │ ├── service │ │ │ ├── DemoService.java │ │ │ └── impl │ │ │ │ └── DemoServiceImpl.java │ │ │ └── web │ │ │ └── CacheController.java │ └── resources │ │ ├── application.properties │ │ └── ehcache.xml │ └── test │ └── java │ └── com │ └── wisely │ └── ch8_5 │ └── Ch85ApplicationTests.java ├── ch8_6_1 ├── ch8_6_1.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch8_6_1 │ │ │ ├── Ch861Application.java │ │ │ ├── dao │ │ │ └── PersonRepository.java │ │ │ ├── domain │ │ │ ├── Location.java │ │ │ └── Person.java │ │ │ └── web │ │ │ └── DataController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch8_6_1 │ └── Ch861ApplicationTests.java ├── ch8_6_2 ├── ch8_6_2.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch8_6_2 │ │ │ ├── Ch862Application.java │ │ │ ├── dao │ │ │ └── Person.java │ │ │ ├── domain │ │ │ └── PersonDao.java │ │ │ └── web │ │ │ └── DataController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch8_6_2 │ └── Ch862ApplicationTests.java ├── ch9_1 ├── ch9_1.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch9_1 │ │ │ ├── Ch91Application.java │ │ │ ├── config │ │ │ ├── WebMvcConfig.java │ │ │ └── WebSecurityConfig.java │ │ │ ├── dao │ │ │ └── SysUserRepository.java │ │ │ ├── domain │ │ │ ├── Msg.java │ │ │ ├── SysRole.java │ │ │ └── SysUser.java │ │ │ ├── security │ │ │ └── CustomUserService.java │ │ │ └── web │ │ │ └── HomeController.java │ └── resources │ │ ├── application.properties │ │ ├── data--.sql │ │ ├── static │ │ └── css │ │ │ └── bootstrap.min.css │ │ └── templates │ │ ├── home.html │ │ └── login.html │ └── test │ └── java │ └── com │ └── wisely │ └── ch9_1 │ └── Ch91ApplicationTests.java ├── ch9_2 ├── ch9_2.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch9_2 │ │ │ ├── Ch92Application.java │ │ │ ├── batch │ │ │ ├── CsvBatchConfig.java │ │ │ ├── CsvBeanValidator.java │ │ │ ├── CsvItemProcessor.java │ │ │ ├── CsvJobListener.java │ │ │ └── TriggerBatchConfig.java │ │ │ ├── domain │ │ │ └── Person.java │ │ │ └── web │ │ │ └── DemoController.java │ └── resources │ │ ├── application.properties │ │ ├── people.csv │ │ └── schema.sql │ └── test │ └── java │ └── com │ └── wisely │ └── ch9_2 │ └── Ch92ApplicationTests.java ├── ch9_3_4 ├── ch9_3_4.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch9_3_4 │ │ │ ├── Ch934Application.java │ │ │ ├── Msg.java │ │ │ └── Receiver.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch9_3_4 │ └── Ch934ApplicationTests.java ├── ch9_3_5 ├── ch9_3_5.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch9_3_5 │ │ │ ├── Ch935Application.java │ │ │ └── Receiver.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch9_3_5 │ └── Ch935ApplicationTests.java ├── ch9_4 ├── ch9_4.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── wisely │ │ │ └── ch9_4 │ │ │ └── Ch94Application.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── wisely │ └── ch9_4 │ └── Ch94ApplicationTests.java ├── highlight_spring4 ├── highlight_spring4.iml ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── wisely │ │ └── highlight_spring4 │ │ ├── ch1 │ │ ├── aop │ │ │ ├── Action.java │ │ │ ├── AopConfig.java │ │ │ ├── DemoAnnotationService.java │ │ │ ├── DemoMethodService.java │ │ │ ├── LogAspect.java │ │ │ └── Main.java │ │ ├── di │ │ │ ├── DiConfig.java │ │ │ ├── FunctionService.java │ │ │ ├── Main.java │ │ │ └── UseFunctionService.java │ │ └── javaconfig │ │ │ ├── FunctionService.java │ │ │ ├── JavaConfig.java │ │ │ ├── Main.java │ │ │ └── UseFunctionService.java │ │ ├── ch2 │ │ ├── el │ │ │ ├── DemoService.java │ │ │ ├── ElConfig.java │ │ │ ├── Main.java │ │ │ ├── test.properties │ │ │ └── test.txt │ │ ├── event │ │ │ ├── DemoEvent.java │ │ │ ├── DemoListener.java │ │ │ ├── DemoPublisher.java │ │ │ ├── EventConfig.java │ │ │ └── Main.java │ │ ├── prepost │ │ │ ├── BeanWayService.java │ │ │ ├── JSR250WayService.java │ │ │ ├── Main.java │ │ │ └── PrePostConfig.java │ │ ├── profile │ │ │ ├── DemoBean.java │ │ │ ├── Main.java │ │ │ └── ProfileConfig.java │ │ └── scope │ │ │ ├── DemoPrototypeService.java │ │ │ ├── DemoSingletonService.java │ │ │ ├── Main.java │ │ │ └── ScopeConfig.java │ │ └── ch3 │ │ ├── annotation │ │ ├── DemoConfig.java │ │ ├── DemoService.java │ │ ├── Main.java │ │ └── WiselyConfiguration.java │ │ ├── aware │ │ ├── AwareConfig.java │ │ ├── AwareService.java │ │ ├── Main.java │ │ └── test.txt │ │ ├── conditional │ │ ├── ConditionConifg.java │ │ ├── LinuxCondition.java │ │ ├── LinuxListService.java │ │ ├── ListService.java │ │ ├── Main.java │ │ ├── WindowsCondition.java │ │ └── WindowsListService.java │ │ ├── fortest │ │ ├── TestBean.java │ │ └── TestConfig.java │ │ ├── taskexecutor │ │ ├── AsyncTaskService.java │ │ ├── Main.java │ │ └── TaskExecutorConfig.java │ │ └── taskscheduler │ │ ├── Main.java │ │ ├── ScheduledTaskService.java │ │ └── TaskSchedulerConfig.java │ └── test │ └── java │ └── com │ └── wisely │ └── highlight_spring4 │ └── ch3 │ └── fortest │ └── DemoBeanIntegrationTests.java └── highlight_springmvc4 ├── highlight_springmvc4.iml ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── wisely │ │ └── highlight_springmvc4 │ │ ├── MyMvcConfig.java │ │ ├── WebInitializer.java │ │ ├── advice │ │ └── ExceptionHandlerAdvice.java │ │ ├── domain │ │ └── DemoObj.java │ │ ├── interceptor │ │ └── DemoInterceptor.java │ │ ├── messageconverter │ │ └── MyMessageConverter.java │ │ ├── service │ │ ├── DemoService.java │ │ └── PushService.java │ │ └── web │ │ ├── HelloController.java │ │ ├── ch4_3 │ │ ├── DemoAnnoController.java │ │ └── DemoRestController.java │ │ ├── ch4_4 │ │ └── AdviceController.java │ │ ├── ch4_5 │ │ ├── AysncController.java │ │ ├── ContentController.java │ │ ├── ConverterController.java │ │ ├── SseController.java │ │ └── UploadController.java │ │ └── ch4_6 │ │ ├── MyRestController.java │ │ └── NormalController.java └── resources │ ├── assets │ └── js │ │ └── jquery.js │ ├── logback.xml │ └── views │ ├── async.jsp │ ├── converter.jsp │ ├── error.jsp │ ├── index.jsp │ ├── page.jsp │ ├── sse.jsp │ └── upload.jsp └── test └── java └── com └── wisely └── highlight_springmvc4 └── web └── ch4_6 └── TestControllerIntegrationTests.java /README.md: -------------------------------------------------------------------------------- 1 | # springboot-wyf-sourcecode 2 | 《Spring Boot 实战》示例源码(作者:汪云飞) 3 | -------------------------------------------------------------------------------- /ch10/src/main/java/com/wisely/ch10/Ch10Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch10Application{ 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch10Application.class, args); 11 | } 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch10/src/main/java/com/wisely/ch10/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class DemoController { 8 | @RequestMapping("/") 9 | public String index(){ 10 | return "index"; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /ch10/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #spring.thymeleaf.cache=false -------------------------------------------------------------------------------- /ch10/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | test 6 | 7 | 8 | 9 |
10 | 123456111222 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ch10/src/test/java/com/wisely/ch10/Ch10ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch10Application.class) 11 | @WebAppConfiguration 12 | public class Ch10ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch10_4/src/main/java/com/wisely/ch10_4/Ch104Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10_4; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch104Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch104Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch10_4/src/main/java/com/wisely/ch10_4/dao/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10_4.dao; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.wisely.ch10_4.domain.Person; 6 | 7 | public interface PersonRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch10_4/src/main/java/com/wisely/ch10_4/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10_4.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | @Entity 8 | public class Person { 9 | @Id 10 | @GeneratedValue 11 | private Long id; 12 | private String name; 13 | 14 | public Person() { 15 | super(); 16 | } 17 | public Person(String name) { 18 | super(); 19 | this.name = name; 20 | } 21 | public Long getId() { 22 | return id; 23 | } 24 | public void setId(Long id) { 25 | this.id = id; 26 | } 27 | public String getName() { 28 | return name; 29 | } 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /ch10_4/src/main/java/com/wisely/ch10_4/web/PersonController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10_4.web; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.wisely.ch10_4.dao.PersonRepository; 12 | import com.wisely.ch10_4.domain.Person; 13 | 14 | @RestController 15 | @RequestMapping("/person") 16 | public class PersonController { 17 | @Autowired 18 | PersonRepository personRepository; 19 | 20 | @RequestMapping(method = RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE} ) 21 | public List findAll(){ 22 | return personRepository.findAll(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ch10_4/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch10_4/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch10docker/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | 3 | MAINTAINER wyf 4 | 5 | ADD ch10docker-0.0.1-SNAPSHOT.jar app.jar 6 | 7 | EXPOSE 8080 8 | 9 | ENTRYPOINT ["java","-jar","/app.jar"] -------------------------------------------------------------------------------- /ch10docker/src/main/java/com/wisely/Ch10dockerApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @SpringBootApplication 9 | @RestController 10 | public class Ch10dockerApplication { 11 | @RequestMapping("/") 12 | public String home() { 13 | return "Hello Docker!!"; 14 | } 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(Ch10dockerApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ch10docker/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch10docker/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch10docker/src/test/java/com/wisely/Ch10dockerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch10dockerApplication.class) 11 | @WebAppConfiguration 12 | public class Ch10dockerApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch10war/src/main/java/com/wisely/ch10war/Ch10warApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10war; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch10warApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch10warApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch10war/src/main/java/com/wisely/ch10war/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10war; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class DemoController { 8 | @RequestMapping("/") 9 | public String index(){ 10 | return "index"; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /ch10war/src/main/java/com/wisely/ch10war/ServletInitializer.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10war; 2 | 3 | import org.springframework.boot.builder.SpringApplicationBuilder; 4 | import org.springframework.boot.context.web.SpringBootServletInitializer; 5 | 6 | public class ServletInitializer extends SpringBootServletInitializer { 7 | 8 | @Override 9 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 10 | return application.sources(Ch10warApplication.class); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /ch10war/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch10war/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch10war/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | test 6 | 7 | 8 | 9 |
10 | 123456111222 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ch10war/src/test/java/com/wisely/ch10war/Ch10warApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch10war; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch10warApplication.class) 11 | @WebAppConfiguration 12 | public class Ch10warApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch11_1/src/main/java/com/wisely/ch11_1/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch11_1; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.actuate.endpoint.Endpoint; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @SpringBootApplication 12 | @RestController 13 | public class DemoApplication { 14 | @Autowired 15 | StatusService statusService; 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(DemoApplication.class, args); 19 | } 20 | 21 | @Bean 22 | public Endpoint status() { 23 | Endpoint status = new StatusEndPoint(); 24 | return status; 25 | } 26 | @RequestMapping("/change") 27 | public String changeStatus(String status){ 28 | statusService.setStatus(status); 29 | return "OK"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ch11_1/src/main/java/com/wisely/ch11_1/StatusEndPoint.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch11_1; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.boot.actuate.endpoint.AbstractEndpoint; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.ApplicationContextAware; 8 | 9 | 10 | @ConfigurationProperties(prefix = "endpoints.status", ignoreUnknownFields = false) //1 11 | public class StatusEndPoint extends AbstractEndpoint implements ApplicationContextAware{//2 12 | 13 | ApplicationContext context; 14 | 15 | public StatusEndPoint() { 16 | super("status"); 17 | } 18 | 19 | @Override 20 | public String invoke() { //3 21 | StatusService statusService = context.getBean(StatusService.class); 22 | 23 | return "The Current Status is :"+statusService.getStatus(); 24 | } 25 | 26 | @Override 27 | public void setApplicationContext(ApplicationContext arg0) throws BeansException { 28 | this.context = arg0; 29 | 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ch11_1/src/main/java/com/wisely/ch11_1/StatusHealth.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch11_1; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.actuate.health.Health; 5 | import org.springframework.boot.actuate.health.HealthIndicator; 6 | import org.springframework.stereotype.Component; 7 | @Component 8 | public class StatusHealth implements HealthIndicator {//1 9 | @Autowired 10 | StatusService statusService; 11 | 12 | @Override 13 | public Health health() { 14 | String status = statusService.getStatus(); 15 | if(status == null||!status.equals("running")){ 16 | return Health.down().withDetail("Error", "Not Running").build(); //2 17 | } 18 | return Health.up().build(); //3 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /ch11_1/src/main/java/com/wisely/ch11_1/StatusService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch11_1; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class StatusService { 7 | 8 | private String status; 9 | 10 | public String getStatus() { 11 | return status; 12 | } 13 | 14 | public void setStatus(String status) { 15 | this.status = status; 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ch11_1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | endpoints.shutdown.enabled=true 2 | #endpoints.beans.id=mybeans 3 | #endpoints.beans.enabled=false 4 | #endpoints.enabled=false 5 | #endpoints.beans.enabled=true 6 | #management.context-path=/manage 7 | #management.port=8081 8 | #management.port=-1 9 | -------------------------------------------------------------------------------- /ch11_1/src/test/java/com/wisely/ch12_1/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch12_1; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | 7 | import com.wisely.ch11_1.DemoApplication; 8 | 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @SpringApplicationConfiguration(classes = DemoApplication.class) 14 | @WebAppConfiguration 15 | public class DemoApplicationTests { 16 | 17 | @Test 18 | public void contextLoads() { 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /ch11_3/src/main/java/com/wisely/ch11_3/Ch123Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch11_3; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch123Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch123Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch11_3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | shell.auth.simple.user.name=wyf 2 | shell.auth.simple.user.password=wyf 3 | -------------------------------------------------------------------------------- /ch11_3/src/main/resources/commands/hello.groovy: -------------------------------------------------------------------------------- 1 | package commands 2 | import org.crsh.cli.Command 3 | import org.crsh.cli.Usage 4 | import org.crsh.command.InvocationContext 5 | class hello { 6 | @Usage("Say Hello") 7 | @Command 8 | def main(InvocationContext context) { 9 | 10 | def bootVersion = context.attributes['spring.boot.version']; 11 | def springVersion = context.attributes['spring.version'] 12 | 13 | return "Hello,your Spring Boot version is "+bootVersion +",your Spring Framework version is "+springVersion 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /ch11_3/src/test/java/com/wisely/ch12_3/Ch123ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch12_3; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | import com.wisely.ch11_3.Ch123Application; 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = Ch123Application.class) 12 | public class Ch123ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch12/config/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | RUN mkdir /app 4 | ADD config-1.0.0-SNAPSHOT.jar /app/app.jar 5 | ADD runboot.sh /app/ 6 | RUN bash -c 'touch /app/app.jar' 7 | WORKDIR /app 8 | RUN chmod a+x runboot.sh 9 | EXPOSE 8888 10 | CMD /app/runboot.sh -------------------------------------------------------------------------------- /ch12/config/src/main/docker/runboot.sh: -------------------------------------------------------------------------------- 1 | sleep 10 2 | java -Djava.security.egd=file:/dev/./urandom -jar /app/app.jar -------------------------------------------------------------------------------- /ch12/config/src/main/java/com/wisely/config/ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableConfigServer //1 10 | @EnableEurekaClient //2 11 | public class ConfigApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ConfigApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ch12/config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | server: 5 | native: 6 | search-locations: classpath:/config #1 7 | 8 | server: 9 | port: 8888 10 | -------------------------------------------------------------------------------- /ch12/config/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: config #1 4 | profiles: 5 | active: native #2 6 | 7 | eureka: 8 | instance: 9 | non-secure-port: ${server.port:8888} #3 10 | metadata-map: 11 | instanceId: ${spring.application.name}:${random.value} #4 12 | client: 13 | service-url: 14 | defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/ #5 15 | 16 | -------------------------------------------------------------------------------- /ch12/config/src/main/resources/config/person-docker.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | database: POSTGRESQL 4 | datasource: 5 | platform: postgres 6 | url: jdbc:postgresql://postgres:5432/postgres 7 | username: postgres 8 | password: postgres 9 | driver-class-name: org.postgresql.Driver -------------------------------------------------------------------------------- /ch12/config/src/main/resources/config/person.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | database: HSQL -------------------------------------------------------------------------------- /ch12/config/src/main/resources/config/some-docker.yml: -------------------------------------------------------------------------------- 1 | my: 2 | message: Message from Production -------------------------------------------------------------------------------- /ch12/config/src/main/resources/config/some.yml: -------------------------------------------------------------------------------- 1 | my: 2 | message: Message from Development 3 | -------------------------------------------------------------------------------- /ch12/config/target/classes/com/wisely/config/ConfigApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/config/target/classes/com/wisely/config/ConfigApplication.class -------------------------------------------------------------------------------- /ch12/config/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/wisely/config/ConfigApplication.class 2 | -------------------------------------------------------------------------------- /ch12/config/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/config/src/main/java/com/wisely/config/ConfigApplication.java 2 | -------------------------------------------------------------------------------- /ch12/discovery/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | RUN mkdir /app 4 | ADD discovery-1.0.0-SNAPSHOT.jar /app/app.jar 5 | ADD runboot.sh /app/ 6 | RUN bash -c 'touch /app/app.jar' 7 | WORKDIR /app 8 | RUN chmod a+x runboot.sh 9 | EXPOSE 8761 10 | CMD /app/runboot.sh -------------------------------------------------------------------------------- /ch12/discovery/src/main/docker/runboot.sh: -------------------------------------------------------------------------------- 1 | java -Djava.security.egd=file:/dev/./urandom -jar /app/app.jar -------------------------------------------------------------------------------- /ch12/discovery/src/main/java/com/wisely/discovery/DiscoveryApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.discovery; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer //1 9 | public class DiscoveryApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DiscoveryApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch12/discovery/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | register-with-eureka: false 9 | fetch-registry: false 10 | -------------------------------------------------------------------------------- /ch12/discovery/target/classes/com/wisely/discovery/DiscoveryApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/discovery/target/classes/com/wisely/discovery/DiscoveryApplication.class -------------------------------------------------------------------------------- /ch12/discovery/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/wisely/discovery/DiscoveryApplication.class 2 | -------------------------------------------------------------------------------- /ch12/discovery/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/discovery/src/main/java/com/wisely/discovery/DiscoveryApplication.java 2 | -------------------------------------------------------------------------------- /ch12/discovery/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/discovery/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst -------------------------------------------------------------------------------- /ch12/monitor/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | RUN mkdir /app 4 | ADD monitor-1.0.0-SNAPSHOT.jar /app/app.jar 5 | ADD runboot.sh /app/ 6 | RUN bash -c 'touch /app/app.jar' 7 | WORKDIR /app 8 | RUN chmod a+x runboot.sh 9 | EXPOSE 8989 10 | CMD /app/runboot.sh -------------------------------------------------------------------------------- /ch12/monitor/src/main/docker/runboot.sh: -------------------------------------------------------------------------------- 1 | sleep 100 2 | java -Djava.security.egd=file:/dev/./urandom -jar /app/app.jar -------------------------------------------------------------------------------- /ch12/monitor/src/main/java/com/wisely/monitor/MonitorApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.monitor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 7 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 8 | 9 | @SpringBootApplication 10 | @EnableEurekaClient 11 | @EnableHystrixDashboard 12 | @EnableTurbine 13 | public class MonitorApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(MonitorApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ch12/monitor/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8989 3 | 4 | -------------------------------------------------------------------------------- /ch12/monitor/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: monitor 4 | 5 | eureka: 6 | instance: 7 | nonSecurePort: ${server.port:8989} 8 | client: 9 | serviceUrl: 10 | defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/ -------------------------------------------------------------------------------- /ch12/monitor/target/classes/com/wisely/monitor/MonitorApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/monitor/target/classes/com/wisely/monitor/MonitorApplication.class -------------------------------------------------------------------------------- /ch12/monitor/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/wisely/monitor/MonitorApplication.class 2 | -------------------------------------------------------------------------------- /ch12/monitor/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/monitor/src/main/java/com/wisely/monitor/MonitorApplication.java 2 | -------------------------------------------------------------------------------- /ch12/monitor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/monitor/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst -------------------------------------------------------------------------------- /ch12/person/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | RUN mkdir /app 4 | ADD person-1.0.0-SNAPSHOT.jar /app/app.jar 5 | ADD runboot.sh /app/ 6 | RUN bash -c 'touch /app/app.jar' 7 | WORKDIR /app 8 | RUN chmod a+x runboot.sh 9 | EXPOSE 8082 10 | CMD /app/runboot.sh -------------------------------------------------------------------------------- /ch12/person/src/main/docker/runboot.sh: -------------------------------------------------------------------------------- 1 | sleep 90 2 | java -Djava.security.egd=file:/dev/./urandom -jar /app/app.jar -------------------------------------------------------------------------------- /ch12/person/src/main/java/com/wisely/person/PersonApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.person; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class PersonApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(PersonApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch12/person/src/main/java/com/wisely/person/controller/PersonController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.person.controller; 2 | 3 | 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.PageRequest; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import com.wisely.person.dao.PersonRepository; 14 | import com.wisely.person.domain.Person; 15 | 16 | @RestController 17 | public class PersonController { 18 | @Autowired 19 | PersonRepository personRepository; 20 | 21 | @RequestMapping(value = "/save", method = RequestMethod.POST) 22 | public List savePerson(@RequestBody String personName) { 23 | Person p = new Person(personName); 24 | personRepository.save(p); 25 | List people = personRepository.findAll(new PageRequest(0, 10)).getContent(); 26 | return people; 27 | } 28 | 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /ch12/person/src/main/java/com/wisely/person/dao/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.person.dao; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.wisely.person.domain.Person; 6 | 7 | public interface PersonRepository extends JpaRepository{ 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch12/person/src/main/java/com/wisely/person/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.person.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | @Entity 8 | public class Person { 9 | @Id 10 | @GeneratedValue 11 | private Long id; 12 | 13 | private String name; 14 | 15 | 16 | 17 | 18 | public Person() { 19 | super(); 20 | } 21 | 22 | public Person(String name) { 23 | super(); 24 | this.name = name; 25 | } 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /ch12/person/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 3 | 4 | 5 | spring: 6 | jpa: 7 | hibernate: 8 | ddl-auto: update 9 | 10 | -------------------------------------------------------------------------------- /ch12/person/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: person 4 | cloud: 5 | config: 6 | enabled: true 7 | discovery: 8 | enabled: true 9 | service-id: CONFIG #1 10 | eureka: 11 | instance: 12 | non-secure-port: ${server.port:8082} 13 | client: 14 | service-url: 15 | defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/ -------------------------------------------------------------------------------- /ch12/person/target/classes/com/wisely/person/PersonApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/person/target/classes/com/wisely/person/PersonApplication.class -------------------------------------------------------------------------------- /ch12/person/target/classes/com/wisely/person/controller/PersonController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/person/target/classes/com/wisely/person/controller/PersonController.class -------------------------------------------------------------------------------- /ch12/person/target/classes/com/wisely/person/dao/PersonRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/person/target/classes/com/wisely/person/dao/PersonRepository.class -------------------------------------------------------------------------------- /ch12/person/target/classes/com/wisely/person/domain/Person.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/person/target/classes/com/wisely/person/domain/Person.class -------------------------------------------------------------------------------- /ch12/person/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/wisely/person/dao/PersonRepository.class 2 | com/wisely/person/domain/Person.class 3 | com/wisely/person/controller/PersonController.class 4 | com/wisely/person/PersonApplication.class 5 | -------------------------------------------------------------------------------- /ch12/person/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/person/src/main/java/com/wisely/person/domain/Person.java 2 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/person/src/main/java/com/wisely/person/controller/PersonController.java 3 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/person/src/main/java/com/wisely/person/dao/PersonRepository.java 4 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/person/src/main/java/com/wisely/person/PersonApplication.java 5 | -------------------------------------------------------------------------------- /ch12/person/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/person/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst -------------------------------------------------------------------------------- /ch12/some/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | RUN mkdir /app 4 | ADD some-1.0.0-SNAPSHOT.jar /app/app.jar 5 | ADD runboot.sh /app/ 6 | RUN bash -c 'touch /app/app.jar' 7 | WORKDIR /app 8 | RUN chmod a+x runboot.sh 9 | EXPOSE 8083 10 | CMD /app/runboot.sh -------------------------------------------------------------------------------- /ch12/some/src/main/docker/runboot.sh: -------------------------------------------------------------------------------- 1 | sleep 90 2 | java -Djava.security.egd=file:/dev/./urandom -jar /app/app.jar -------------------------------------------------------------------------------- /ch12/some/src/main/java/com/wisely/some/SomeApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.some; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | @RestController 13 | public class SomeApplication { 14 | @Value("${my.message}") //1 15 | private String message; 16 | 17 | @RequestMapping(value = "/getsome") 18 | public String getsome(){ 19 | return message; 20 | } 21 | public static void main(String[] args) { 22 | SpringApplication.run(SomeApplication.class, args); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ch12/some/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | -------------------------------------------------------------------------------- /ch12/some/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: some 4 | cloud: 5 | config: 6 | enabled: true 7 | discovery: 8 | enabled: true 9 | service-id: CONFIG 10 | eureka: 11 | instance: 12 | non-secure-port: ${server.port:8083} 13 | client: 14 | service-url: 15 | defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/ -------------------------------------------------------------------------------- /ch12/some/target/classes/com/wisely/some/SomeApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/some/target/classes/com/wisely/some/SomeApplication.class -------------------------------------------------------------------------------- /ch12/some/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/wisely/some/SomeApplication.class 2 | -------------------------------------------------------------------------------- /ch12/some/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/some/src/main/java/com/wisely/some/SomeApplication.java 2 | -------------------------------------------------------------------------------- /ch12/some/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/some/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst -------------------------------------------------------------------------------- /ch12/ui/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | RUN mkdir /app 4 | ADD ui-1.0.0-SNAPSHOT.jar /app/app.jar 5 | ADD runboot.sh /app/ 6 | RUN bash -c 'touch /app/app.jar' 7 | WORKDIR /app 8 | RUN chmod a+x runboot.sh 9 | EXPOSE 80 10 | CMD /app/runboot.sh -------------------------------------------------------------------------------- /ch12/ui/src/main/docker/runboot.sh: -------------------------------------------------------------------------------- 1 | sleep 10 2 | java -Djava.security.egd=file:/dev/./urandom -jar /app/app.jar -------------------------------------------------------------------------------- /ch12/ui/src/main/java/com/wisely/ui/UiApplication.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ui; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 8 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 9 | 10 | @SpringBootApplication 11 | @EnableEurekaClient 12 | @EnableFeignClients //1 13 | @EnableCircuitBreaker //2 14 | @EnableZuulProxy //3 15 | public class UiApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(UiApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ch12/ui/src/main/java/com/wisely/ui/controller/UiController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ui.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.wisely.ui.domain.Person; 12 | import com.wisely.ui.service.PersonHystrixService; 13 | import com.wisely.ui.service.SomeHystrixService; 14 | 15 | @RestController 16 | public class UiController { 17 | @Autowired 18 | private SomeHystrixService someHystrixService; 19 | 20 | @Autowired 21 | private PersonHystrixService personHystrixService; 22 | 23 | @RequestMapping("/dispatch") 24 | public List sendMessage(@RequestBody String personName) { 25 | return personHystrixService.save(personName); 26 | } 27 | 28 | @RequestMapping(value = "/getsome",produces={MediaType.TEXT_PLAIN_VALUE}) 29 | public String getSome(){ 30 | return someHystrixService.getSome(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ch12/ui/src/main/java/com/wisely/ui/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ui.domain; 2 | 3 | 4 | public class Person { 5 | private Long id; 6 | 7 | private String name; 8 | 9 | 10 | public Person() { 11 | super(); 12 | } 13 | 14 | public Person(String name) { 15 | super(); 16 | this.name = name; 17 | } 18 | 19 | public Long getId() { 20 | return id; 21 | } 22 | 23 | public void setId(Long id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /ch12/ui/src/main/java/com/wisely/ui/service/PersonHystrixService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ui.service; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 9 | import com.wisely.ui.domain.Person; 10 | 11 | @Service 12 | public class PersonHystrixService { 13 | 14 | @Autowired 15 | PersonService personService; 16 | 17 | @HystrixCommand(fallbackMethod = "fallbackSave") //1 18 | public List save(String name) { 19 | return personService.save(name); 20 | } 21 | 22 | public List fallbackSave(String name){ 23 | List list = new ArrayList<>(); 24 | Person p = new Person(name+"没有保存成功,Person Service 故障"); 25 | list.add(p); 26 | return list; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ch12/ui/src/main/java/com/wisely/ui/service/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ui.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.cloud.netflix.feign.FeignClient; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import com.wisely.ui.domain.Person; 13 | 14 | @FeignClient("person") 15 | public interface PersonService { 16 | @RequestMapping(method = RequestMethod.POST, value = "/save", 17 | produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) 18 | @ResponseBody List save(@RequestBody String name); 19 | } 20 | -------------------------------------------------------------------------------- /ch12/ui/src/main/java/com/wisely/ui/service/SomeHystrixService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ui.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 8 | 9 | @Service 10 | public class SomeHystrixService { 11 | 12 | @Autowired 13 | RestTemplate restTemplate; //1 14 | 15 | @HystrixCommand(fallbackMethod = "fallbackSome") //2 16 | public String getSome() { 17 | return restTemplate.getForObject("http://some/getsome", String.class); 18 | } 19 | 20 | public String fallbackSome(){ 21 | return "some service模块故障"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: ui 4 | 5 | eureka: 6 | instance: 7 | non-secure-port: ${server.port:80} 8 | client: 9 | service-url: 10 | defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/ -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/css/application.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 60px; 3 | } 4 | 5 | h1, h2, h3, h4, h5, h6 { 6 | font-family: microsoft yahei; 7 | } 8 | p, div { 9 | font-family: microsoft yahei; 10 | font-size: 12px; 11 | } 12 | 13 | .longtext { 14 | word-break:break-all; 15 | } 16 | -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/src/main/resources/static/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/src/main/resources/static/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/src/main/resources/static/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 原生云应用 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 30 |
31 |
32 |
33 |
34 |
35 | 36 | -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/js/app.js: -------------------------------------------------------------------------------- 1 | var uiApp = angular.module("uiApp", ["ui.router"]); 2 | 3 | uiApp.config(function ($stateProvider, $urlRouterProvider) { 4 | $urlRouterProvider.otherwise("person"); 5 | 6 | $stateProvider 7 | .state('person', { 8 | url: '/person', 9 | templateUrl: '/tpl/person.html', 10 | controller: 'PersonController' 11 | }) 12 | .state('some',{ 13 | url:'/some', 14 | templateUrl: '/tpl/some.html', 15 | controller: 'SomeController' 16 | }); 17 | }); 18 | 19 | 20 | uiApp.controller("PersonController", function ($scope, $http) { 21 | 22 | $scope.people = ""; 23 | $scope.errorMessage = ""; 24 | 25 | $scope.getMessageResponse = function(personName) { 26 | $http.post('/dispatch', personName).success(function(data){ 27 | $scope.people = data; 28 | $scope.errorMessage = ""; 29 | }).error(function() { 30 | $scope.errorMessage = "错误"; 31 | }); 32 | } 33 | 34 | }); 35 | 36 | 37 | uiApp.controller("SomeController", function ($scope, $http) { 38 | $scope.str = ""; 39 | $scope.errorMessage = ""; 40 | 41 | $scope.getSome = function(){ 42 | $http.get('/getsome').success(function(data){ 43 | $scope.str = data; 44 | $scope.errorMessage = ""; 45 | }).error(function() { 46 | $scope.errorMessage = "错误"; 47 | }); 48 | } 49 | }); -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/tpl/person.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |

通过Person Service保存person

6 |
7 |
8 |
9 |
10 |
11 |
12 |

13 | 14 |

15 |
16 |
17 |
18 |
19 |
20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 |
28 | 29 |
30 |
31 | 32 |
33 |
34 |
35 | -------------------------------------------------------------------------------- /ch12/ui/src/main/resources/static/tpl/some.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |

从 Some Service获得字符

6 |
7 |
8 |
9 |
10 |
11 |
12 |

13 | 14 |

15 |
16 |
17 |
18 | 19 |
20 | 21 |
22 | 23 |
24 |
25 |
26 |
27 |
28 | -------------------------------------------------------------------------------- /ch12/ui/target/classes/com/wisely/ui/UiApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/target/classes/com/wisely/ui/UiApplication.class -------------------------------------------------------------------------------- /ch12/ui/target/classes/com/wisely/ui/controller/UiController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/target/classes/com/wisely/ui/controller/UiController.class -------------------------------------------------------------------------------- /ch12/ui/target/classes/com/wisely/ui/domain/Person.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/target/classes/com/wisely/ui/domain/Person.class -------------------------------------------------------------------------------- /ch12/ui/target/classes/com/wisely/ui/service/PersonHystrixService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/target/classes/com/wisely/ui/service/PersonHystrixService.class -------------------------------------------------------------------------------- /ch12/ui/target/classes/com/wisely/ui/service/PersonService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/target/classes/com/wisely/ui/service/PersonService.class -------------------------------------------------------------------------------- /ch12/ui/target/classes/com/wisely/ui/service/SomeHystrixService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/target/classes/com/wisely/ui/service/SomeHystrixService.class -------------------------------------------------------------------------------- /ch12/ui/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/wisely/ui/service/PersonService.class 2 | com/wisely/ui/service/PersonHystrixService.class 3 | com/wisely/ui/UiApplication.class 4 | com/wisely/ui/service/SomeHystrixService.class 5 | com/wisely/ui/controller/UiController.class 6 | com/wisely/ui/domain/Person.class 7 | -------------------------------------------------------------------------------- /ch12/ui/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/ui/src/main/java/com/wisely/ui/service/PersonHystrixService.java 2 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/ui/src/main/java/com/wisely/ui/domain/Person.java 3 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/ui/src/main/java/com/wisely/ui/service/SomeHystrixService.java 4 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/ui/src/main/java/com/wisely/ui/service/PersonService.java 5 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/ui/src/main/java/com/wisely/ui/controller/UiController.java 6 | /home/wxd/workspace/idea/springboot-SourceCode/ch12/ui/src/main/java/com/wisely/ui/UiApplication.java 7 | -------------------------------------------------------------------------------- /ch12/ui/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch12/ui/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst -------------------------------------------------------------------------------- /ch5_2_2/src/main/java/com/wisely/ch5_2_2/Ch522Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch5_2_2; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | @SpringBootApplication 11 | public class Ch522Application { 12 | 13 | @Value("${book.author}") 14 | private String bookAuthor; 15 | @Value("${book.name}") 16 | private String bookName; 17 | 18 | @RequestMapping("/") 19 | String index() { 20 | 21 | return "book name is:"+bookName+" and book author is:" + bookAuthor; 22 | } 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(Ch522Application.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ch5_2_2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9090 2 | server.CONTEXT_PATH=/helloboot 3 | 4 | book.author=wangyunfei 5 | book.name=spring boot 6 | 7 | logging.file=D:/mylog/log.log 8 | logging.level.org.springframework.web: DEBUG 9 | -------------------------------------------------------------------------------- /ch5_2_2/src/main/resources/application.xx: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9090 3 | contextPath: /helloboot -------------------------------------------------------------------------------- /ch5_2_2/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | '##:::::'##:'####::'######::'########:'##:::::::'##:::'##: 2 | ##:'##: ##:. ##::'##... ##: ##.....:: ##:::::::. ##:'##:: 3 | ##: ##: ##:: ##:: ##:::..:: ##::::::: ##::::::::. ####::: 4 | ##: ##: ##:: ##::. ######:: ######::: ##:::::::::. ##:::: 5 | ##: ##: ##:: ##:::..... ##: ##...:::: ##:::::::::: ##:::: 6 | ##: ##: ##:: ##::'##::: ##: ##::::::: ##:::::::::: ##:::: 7 | . ###. ###::'####:. ######:: ########: ########:::: ##:::: 8 | :...::...:::....:::......:::........::........:::::..::::: -------------------------------------------------------------------------------- /ch5_2_2/src/test/java/com/wisely/ch5_2_2/Ch522ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch5_2_2; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch522Application.class) 11 | @WebAppConfiguration 12 | public class Ch522ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch5_2_3/src/main/java/com/wisely/ch5_2_3/Ch523Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch5_2_3; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | @Controller 9 | @SpringBootApplication 10 | public class Ch523Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Ch523Application.class, args); 14 | } 15 | 16 | @RequestMapping("/") 17 | String home() { 18 | return "Hello Spring Boot!"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ch5_2_3/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch5_2_3/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch5_2_3/src/test/java/com/wisely/ch5_2_3/Ch523ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch5_2_3; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch523Application.class) 11 | @WebAppConfiguration 12 | public class Ch523ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch6_2_3/src/main/java/com/wisely/ch6_2_3/Ch623Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch6_2_3; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.wisely.ch6_2_3.config.AuthorSettings; 10 | @RestController 11 | @SpringBootApplication 12 | public class Ch623Application { 13 | 14 | @Autowired 15 | private AuthorSettings authorSettings; //1 16 | 17 | @RequestMapping("/") 18 | public String index(){ 19 | return "author name is "+ authorSettings.getName()+" and author age is "+authorSettings.getAge(); 20 | } 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(Ch623Application.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ch6_2_3/src/main/java/com/wisely/ch6_2_3/config/AuthorSettings.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch6_2_3.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.stereotype.Component; 5 | @Component 6 | @ConfigurationProperties(prefix = "author") //1 7 | public class AuthorSettings { 8 | private String name; 9 | private Long age; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public Long getAge() { 20 | return age; 21 | } 22 | 23 | public void setAge(Long age) { 24 | this.age = age; 25 | } 26 | } -------------------------------------------------------------------------------- /ch6_2_3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | author.name=wyf 2 | author.age=32 -------------------------------------------------------------------------------- /ch6_2_3/src/test/java/com/wisely/ch6_2_3/Ch623ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch6_2_3; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch623Application.class) 11 | @WebAppConfiguration 12 | public class Ch623ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch6_4/src/main/java/com/wisely/ch6_4/Ch64Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch6_4; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch64Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch64Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch6_4/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | server.port=8888 -------------------------------------------------------------------------------- /ch6_4/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | server.port=80 2 | debug=true -------------------------------------------------------------------------------- /ch6_4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=prod -------------------------------------------------------------------------------- /ch6_4/src/test/java/com/wisely/ch6_4/Ch64ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch6_4; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch64Application.class) 11 | @WebAppConfiguration 12 | public class Ch64ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch6_5/src/main/java/com/wisely/ch6_5/Ch65Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch6_5; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.wisely.spring_boot_starter_hello.HelloService; 10 | @RestController 11 | @SpringBootApplication 12 | public class Ch65Application { 13 | 14 | @Autowired 15 | HelloService helloService; 16 | 17 | @RequestMapping("/") 18 | public String index(){ 19 | return helloService.sayHello(); 20 | } 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(Ch65Application.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ch6_5/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | hello.msg= wangyunfei 2 | debug=true -------------------------------------------------------------------------------- /ch6_5/src/test/java/com/wisely/ch6_5/Ch65ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch6_5; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch65Application.class) 11 | @WebAppConfiguration 12 | public class Ch65ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch7_2/src/main/java/com/wisely/Ch72Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.ui.Model; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | @Controller 12 | @SpringBootApplication 13 | public class Ch72Application { 14 | 15 | @RequestMapping("/") 16 | public String index(Model model){ 17 | Person single = new Person("aa",11); 18 | 19 | List people = new ArrayList(); 20 | Person p1 = new Person("xx",11); 21 | Person p2 = new Person("yy",22); 22 | Person p3 = new Person("zz",33); 23 | people.add(p1); 24 | people.add(p2); 25 | people.add(p3); 26 | 27 | model.addAttribute("singlePerson", single); 28 | model.addAttribute("people", people); 29 | 30 | return "index"; 31 | } 32 | 33 | // @RequestMapping(value = "/json",produces={MediaType.APPLICATION_JSON_VALUE}) 34 | // public String json(Model model) { 35 | // Person single = new Person("aa",11); 36 | // model.addAttribute("single", single); 37 | // return "jsonView"; 38 | // } 39 | // 40 | // @Bean 41 | // public MappingJackson2JsonView jsonView(){ 42 | // MappingJackson2JsonView jsonView = new MappingJackson2JsonView(); 43 | // return jsonView; 44 | // } 45 | 46 | public static void main(String[] args) { 47 | SpringApplication.run(Ch72Application.class, args); 48 | } 49 | 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ch7_2/src/main/java/com/wisely/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | public class Person { 4 | private String name; 5 | private Integer age; 6 | 7 | public Person() { 8 | super(); 9 | } 10 | public Person(String name, Integer age) { 11 | super(); 12 | this.name = name; 13 | this.age = age; 14 | } 15 | public String getName() { 16 | return name; 17 | } 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | public Integer getAge() { 22 | return age; 23 | } 24 | public void setAge(Integer age) { 25 | this.age = age; 26 | } 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /ch7_2/src/main/java/com/wisely/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | @Configuration 8 | public class WebMvcConfig extends WebMvcConfigurerAdapter{ 9 | 10 | @Override 11 | public void addViewControllers(ViewControllerRegistry registry) { 12 | registry.addViewController("/xx").setViewName("/xx"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch7_2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.web = DEBUG -------------------------------------------------------------------------------- /ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_2/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /ch7_2/src/main/resources/static/bootstrap/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /ch7_2/src/test/java/com/wisely/Ch72ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch72Application.class) 11 | @WebAppConfiguration 12 | public class Ch72ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch7_4/.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_4/.keystore -------------------------------------------------------------------------------- /ch7_4/src/main/java/com/wisely/ch7_4/CustomServletContainer.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_4; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; 6 | import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; 7 | import org.springframework.boot.context.embedded.ErrorPage; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.stereotype.Component; 10 | 11 | @Component 12 | public class CustomServletContainer implements EmbeddedServletContainerCustomizer{ 13 | 14 | @Override 15 | public void customize(ConfigurableEmbeddedServletContainer container) { 16 | container.setPort(8888); 17 | container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html")); 18 | container.setSessionTimeout(10,TimeUnit.MINUTES); 19 | 20 | } 21 | 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /ch7_4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #server.port = 8443 2 | #server.ssl.key-store = .keystore 3 | #server.ssl.key-store-password= 111111 4 | #server.ssl.keyStoreType= JKS 5 | #server.ssl.keyAlias: tomcat 6 | # 7 | #logging.level.org.springframework.web = DEBUG 8 | 9 | #spring.mvc.favicon.enabled=false -------------------------------------------------------------------------------- /ch7_4/src/main/resources/static/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | page not found 9 | 10 | -------------------------------------------------------------------------------- /ch7_4/src/main/resources/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_4/src/main/resources/static/favicon.ico -------------------------------------------------------------------------------- /ch7_4/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | index page 9 | 10 | -------------------------------------------------------------------------------- /ch7_4/src/test/java/com/wisely/ch7_4/Ch74ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_4; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch74Application.class) 11 | @WebAppConfiguration 12 | public class Ch74ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch7_6/src/main/java/com/wisely/ch7_6/Ch76Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_6; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch76Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch76Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch7_6/src/main/java/com/wisely/ch7_6/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_6; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | @Configuration 8 | public class WebMvcConfig extends WebMvcConfigurerAdapter{ 9 | 10 | @Override 11 | public void addViewControllers(ViewControllerRegistry registry) { 12 | registry.addViewController("/ws").setViewName("/ws"); 13 | registry.addViewController("/login").setViewName("/login"); 14 | registry.addViewController("/chat").setViewName("/chat"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ch7_6/src/main/java/com/wisely/ch7_6/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_6; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer; 6 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 7 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 8 | 9 | @Configuration 10 | @EnableWebSocketMessageBroker 11 | public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer{ 12 | 13 | @Override 14 | public void registerStompEndpoints(StompEndpointRegistry registry) { 15 | registry.addEndpoint("/endpointWisely").withSockJS(); 16 | registry.addEndpoint("/endpointChat").withSockJS();//1 17 | } 18 | 19 | 20 | @Override 21 | public void configureMessageBroker(MessageBrokerRegistry registry) { 22 | registry.enableSimpleBroker("/queue","/topic"); //2 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ch7_6/src/main/java/com/wisely/ch7_6/domain/WiselyMessage.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_6.domain; 2 | 3 | public class WiselyMessage { 4 | private String name; 5 | 6 | public String getName(){ 7 | return name; 8 | } 9 | } -------------------------------------------------------------------------------- /ch7_6/src/main/java/com/wisely/ch7_6/domain/WiselyResponse.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_6.domain; 2 | 3 | public class WiselyResponse { 4 | private String responseMessage; 5 | public WiselyResponse(String responseMessage){ 6 | this.responseMessage = responseMessage; 7 | } 8 | public String getResponseMessage(){ 9 | return responseMessage; 10 | } 11 | } -------------------------------------------------------------------------------- /ch7_6/src/main/java/com/wisely/ch7_6/web/WsController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_6.web; 2 | 3 | import java.security.Principal; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.messaging.handler.annotation.MessageMapping; 7 | import org.springframework.messaging.handler.annotation.SendTo; 8 | import org.springframework.messaging.simp.SimpMessagingTemplate; 9 | import org.springframework.stereotype.Controller; 10 | 11 | import com.wisely.ch7_6.domain.WiselyMessage; 12 | import com.wisely.ch7_6.domain.WiselyResponse; 13 | 14 | @Controller 15 | public class WsController { 16 | 17 | @MessageMapping("/welcome") 18 | @SendTo("/topic/getResponse") 19 | public WiselyResponse say(WiselyMessage message) throws Exception { 20 | Thread.sleep(3000); 21 | return new WiselyResponse("Welcome, " + message.getName() + "!"); 22 | } 23 | 24 | @Autowired 25 | private SimpMessagingTemplate messagingTemplate;//1 26 | 27 | @MessageMapping("/chat") 28 | public void handleChat(Principal principal, String msg) { //2 29 | if (principal.getName().equals("wyf")) {//3 30 | messagingTemplate.convertAndSendToUser("wisely", 31 | "/queue/notifications", principal.getName() + "-send:" 32 | + msg); 33 | } else { 34 | messagingTemplate.convertAndSendToUser("wyf", 35 | "/queue/notifications", principal.getName() + "-send:" 36 | + msg); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /ch7_6/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_6/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch7_6/src/main/resources/templates/chat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Home 7 | 8 | 9 | 10 | 11 | 12 |

13 | 聊天室 14 |

15 | 16 |
17 | 18 | 19 |
20 | 21 | 45 | 46 |
47 | 48 | -------------------------------------------------------------------------------- /ch7_6/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 登陆页面 7 | 8 | 9 |
10 | 无效的账号和密码 11 |
12 |
13 | 你已注销 14 |
15 |
16 |
17 |
18 |
19 |
20 | 21 | -------------------------------------------------------------------------------- /ch7_6/src/test/java/com/wisely/ch7_6/Ch76ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_6; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch76Application.class) 11 | @WebAppConfiguration 12 | public class Ch76ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch7_7/src/main/java/com/wisely/ch7_7/Ch77Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_7; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | @SpringBootApplication 11 | public class Ch77Application { 12 | 13 | @RequestMapping(value="/search",produces={MediaType.APPLICATION_JSON_VALUE}) 14 | public Person search(String personName){ 15 | 16 | return new Person(personName, 32, "hefei"); 17 | 18 | } 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(Ch77Application.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ch7_7/src/main/java/com/wisely/ch7_7/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_7; 2 | 3 | public class Person { 4 | private String name; 5 | private Integer age; 6 | private String address; 7 | 8 | 9 | public Person() { 10 | super(); 11 | } 12 | public Person(String name, Integer age, String address) { 13 | super(); 14 | this.name = name; 15 | this.age = age; 16 | this.address = address; 17 | } 18 | public String getName() { 19 | return name; 20 | } 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | public Integer getAge() { 25 | return age; 26 | } 27 | public void setAge(Integer age) { 28 | this.age = age; 29 | } 30 | public String getAddress() { 31 | return address; 32 | } 33 | public void setAddress(String address) { 34 | this.address = address; 35 | } 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /ch7_7/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/angularjs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 |
12 |

你好 {{yourName}}!

13 |
14 | 15 | -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/bootstrap/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/bootstrap/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_diagonals-thick_18_b81900_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_diagonals-thick_18_b81900_40x40.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_diagonals-thick_20_666666_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_diagonals-thick_20_666666_40x40.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_flat_10_000000_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_flat_10_000000_40x100.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_glass_100_f6f6f6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_glass_100_f6f6f6_1x400.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_glass_100_fdf5ce_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_glass_100_fdf5ce_1x400.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_gloss-wave_35_f6a828_500x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_gloss-wave_35_f6a828_500x100.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_highlight-soft_100_eeeeee_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_highlight-soft_100_eeeeee_1x100.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-bg_highlight-soft_75_ffe45c_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-bg_highlight-soft_75_ffe45c_1x100.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-icons_228ef1_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-icons_228ef1_256x240.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-icons_ef8c08_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-icons_ef8c08_256x240.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-icons_ffd27a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-icons_ffd27a_256x240.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/jqueryui/images/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch7_7/src/main/resources/static/jqueryui/images/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/js-action/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | 5 | var actionApp = angular.module('actionApp',['ngRoute']); 6 | 7 | 8 | 9 | 10 | actionApp.config(['$routeProvider' , function($routeProvider) { 11 | 12 | $routeProvider.when('/oper', { 13 | controller: 'View1Controller', 14 | templateUrl: 'views/view1.html', 15 | }).when('/directive', { 16 | controller: 'View2Controller', 17 | templateUrl: 'views/view2.html', 18 | }); 19 | 20 | }]); 21 | -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/js-action/controllers.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | 5 | actionApp.controller('View1Controller', ['$rootScope', '$scope', '$http', function($rootScope, $scope,$http) { 6 | $scope.$on('$viewContentLoaded', function() { 7 | console.log('页面加载完成'); 8 | }); 9 | 10 | 11 | $scope.search = function(){ 12 | personName = $scope.personName; 13 | $http.get('search',{ 14 | params:{personName:personName} 15 | }).success(function(data){ 16 | $scope.person=data; 17 | });; 18 | 19 | }; 20 | }]); 21 | 22 | actionApp.controller('View2Controller', ['$rootScope', '$scope', function($rootScope, $scope) { 23 | $scope.$on('$viewContentLoaded', function() { 24 | console.log('页面加载完成'); 25 | }); 26 | }]); 27 | 28 | 29 | -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/js-action/directives.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | 5 | actionApp.directive('datePicker',function(){ 6 | return { 7 | restrict: 'AC', 8 | link:function(scope,elem,attrs){ 9 | // scope.treeObj = $.fn.zTree.init(elem, scope.settings); 10 | 11 | elem.datepicker(); 12 | } 13 | }; 14 | }); 15 | 16 | 17 | -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/js-action/services.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/views/view1.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |
6 |
7 | 8 |
9 |
10 | 11 |
12 |
13 |
    14 |
  • 名字: {{person.name}}
  • 15 |
  • 年龄: {{person.age}}
  • 16 |
  • 地址: {{person.address}}
  • 17 |
18 |
19 |
20 | 21 | -------------------------------------------------------------------------------- /ch7_7/src/main/resources/static/views/view2.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |
6 |
7 | 8 |
9 | 10 |
11 | 12 |
13 |
14 | 15 | -------------------------------------------------------------------------------- /ch7_7/src/test/java/com/wisely/ch7_7/Ch77ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch7_7; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch77Application.class) 11 | @WebAppConfiguration 12 | public class Ch77ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch8_2/src/main/java/com/wisely/Ch82Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | import com.wisely.dao.PersonRepository; 9 | import com.wisely.support.CustomRepositoryFactoryBean; 10 | 11 | @SpringBootApplication 12 | @EnableJpaRepositories(repositoryFactoryBeanClass = CustomRepositoryFactoryBean.class) 13 | public class Ch82Application { 14 | @Autowired 15 | PersonRepository personRepository; 16 | 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(Ch82Application.class, args); 20 | 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /ch8_2/src/main/java/com/wisely/dao/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.query.Param; 7 | 8 | import com.wisely.domain.Person; 9 | import com.wisely.support.CustomRepository; 10 | 11 | public interface PersonRepository extends CustomRepository { 12 | List findByAddress(String address); 13 | 14 | Person findByNameAndAddress(String name,String address); 15 | 16 | @Query("select p from Person p where p.name= :name and p.address= :address") 17 | 18 | Person withNameAndAddressQuery(@Param("name")String name,@Param("address")String address); 19 | 20 | Person withNameAndAddressNamedQuery(String name,String address); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /ch8_2/src/main/java/com/wisely/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | import javax.persistence.NamedQuery; 7 | 8 | @Entity //1 9 | @NamedQuery(name = "Person.withNameAndAddressNamedQuery", 10 | query = "select p from Person p where p.name=?1 and address=?2") 11 | public class Person { 12 | @Id //2 13 | @GeneratedValue //3 14 | private Long id; 15 | 16 | private String name; 17 | 18 | private Integer age; 19 | 20 | private String address; 21 | 22 | 23 | 24 | public Person() { 25 | super(); 26 | } 27 | public Person(Long id, String name, Integer age, String address) { 28 | super(); 29 | this.id = id; 30 | this.name = name; 31 | this.age = age; 32 | this.address = address; 33 | } 34 | public Long getId() { 35 | return id; 36 | } 37 | public void setId(Long id) { 38 | this.id = id; 39 | } 40 | public String getName() { 41 | return name; 42 | } 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | public Integer getAge() { 47 | return age; 48 | } 49 | public void setAge(Integer age) { 50 | this.age = age; 51 | } 52 | public String getAddress() { 53 | return address; 54 | } 55 | public void setAddress(String address) { 56 | this.address = address; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /ch8_2/src/main/java/com/wisely/support/CustomRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.support; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.data.jpa.repository.JpaRepository; 8 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 9 | import org.springframework.data.repository.NoRepositoryBean; 10 | 11 | @NoRepositoryBean 12 | public interface CustomRepositoryextends JpaRepository ,JpaSpecificationExecutor{ 13 | 14 | Page findByAuto(T example,Pageable pageable); 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ch8_2/src/main/java/com/wisely/support/CustomRepositoryImpl.java: -------------------------------------------------------------------------------- 1 | package com.wisely.support; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.EntityManager; 6 | 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.data.jpa.repository.support.SimpleJpaRepository; 10 | 11 | import static com.wisely.specs.CustomerSpecs.*; 12 | 13 | public class CustomRepositoryImpl 14 | extends SimpleJpaRepository implements CustomRepository { 15 | 16 | private final EntityManager entityManager; 17 | 18 | public CustomRepositoryImpl(Class domainClass, EntityManager entityManager) { 19 | super(domainClass, entityManager); 20 | this.entityManager = entityManager; 21 | } 22 | 23 | @Override 24 | public Page findByAuto(T example, Pageable pageable) { 25 | return findAll(byAuto(entityManager, example),pageable); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ch8_2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=oracle.jdbc.OracleDriver 2 | spring.datasource.url=jdbc\:oracle\:thin\:@localhost\:1521\:xe 3 | spring.datasource.username=boot 4 | spring.datasource.password=boot 5 | 6 | #1 7 | spring.jpa.hibernate.ddl-auto=update 8 | #2 9 | spring.jpa.show-sql=true 10 | 11 | 12 | spring.jackson.serialization.indent_output=true -------------------------------------------------------------------------------- /ch8_2/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'汪云飞',32,'合肥'); 2 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'xx',31,'北京'); 3 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'yy',30,'上海'); 4 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'zz',29,'南京'); 5 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'aa',28,'武汉'); 6 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'bb',27,'合肥'); -------------------------------------------------------------------------------- /ch8_2/src/test/java/com/wisely/Ch82ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch82Application.class) 11 | @WebAppConfiguration 12 | public class Ch82ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch8_3/src/main/java/com/wisely/ch8_3/Ch83Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_3; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch83Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch83Application.class, args); 11 | } 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch8_3/src/main/java/com/wisely/ch8_3/dao/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_3.dao; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.repository.query.Param; 5 | import org.springframework.data.rest.core.annotation.RepositoryRestResource; 6 | import org.springframework.data.rest.core.annotation.RestResource; 7 | 8 | import com.wisely.ch8_3.domain.Person; 9 | 10 | @RepositoryRestResource(path = "people") 11 | public interface PersonRepository extends JpaRepository { 12 | 13 | @RestResource(path = "nameStartsWith", rel = "nameStartsWith") 14 | Person findByNameStartsWith(@Param("name")String name); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch8_3/src/main/java/com/wisely/ch8_3/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_3.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | @Entity 8 | public class Person { 9 | @Id 10 | @GeneratedValue 11 | private Long id; 12 | 13 | private String name; 14 | 15 | private Integer age; 16 | 17 | private String address; 18 | 19 | 20 | 21 | public Person() { 22 | super(); 23 | } 24 | public Person(Long id, String name, Integer age, String address) { 25 | super(); 26 | this.id = id; 27 | this.name = name; 28 | this.age = age; 29 | this.address = address; 30 | } 31 | public Long getId() { 32 | return id; 33 | } 34 | public void setId(Long id) { 35 | this.id = id; 36 | } 37 | public String getName() { 38 | return name; 39 | } 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | public Integer getAge() { 44 | return age; 45 | } 46 | public void setAge(Integer age) { 47 | this.age = age; 48 | } 49 | public String getAddress() { 50 | return address; 51 | } 52 | public void setAddress(String address) { 53 | this.address = address; 54 | } 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /ch8_3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=oracle.jdbc.OracleDriver 2 | spring.datasource.url=jdbc\:oracle\:thin\:@localhost\:1521\:xe 3 | spring.datasource.username=boot 4 | spring.datasource.password=boot 5 | 6 | #1 7 | spring.jpa.hibernate.ddl-auto=update 8 | #2 9 | spring.jpa.show-sql=true 10 | 11 | 12 | spring.jackson.serialization.indent_output=true 13 | 14 | spring.data.rest.base-path= /api 15 | 16 | debug=true -------------------------------------------------------------------------------- /ch8_3/src/main/resources/data--.sql: -------------------------------------------------------------------------------- 1 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'汪云飞',32,'合肥'); 2 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'xx',31,'北京'); 3 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'yy',30,'上海'); 4 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'zz',29,'南京'); 5 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'aa',28,'武汉'); 6 | insert into person(id,name,age,address) values(hibernate_sequence.nextval,'bb',27,'合肥'); -------------------------------------------------------------------------------- /ch8_3/src/main/resources/postman.crx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch8_3/src/main/resources/postman.crx -------------------------------------------------------------------------------- /ch8_3/src/test/java/com/wisely/ch8_3/Ch83ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_3; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @SpringApplicationConfiguration(classes = Ch83Application.class) 10 | public class Ch83ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch8_4/src/main/java/com/wisely/ch8_4/Ch84Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_4; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch84Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch84Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch8_4/src/main/java/com/wisely/ch8_4/dao/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_4.dao; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.wisely.ch8_4.domain.Person; 6 | 7 | public interface PersonRepository extends JpaRepository { 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /ch8_4/src/main/java/com/wisely/ch8_4/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_4.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | @Entity 8 | public class Person { 9 | @Id 10 | @GeneratedValue 11 | private Long id; 12 | 13 | private String name; 14 | 15 | private Integer age; 16 | 17 | private String address; 18 | 19 | 20 | public Person() { 21 | super(); 22 | } 23 | public Person(Long id, String name, Integer age, String address) { 24 | super(); 25 | this.id = id; 26 | this.name = name; 27 | this.age = age; 28 | this.address = address; 29 | } 30 | public Long getId() { 31 | return id; 32 | } 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | public String getName() { 37 | return name; 38 | } 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | public Integer getAge() { 43 | return age; 44 | } 45 | public void setAge(Integer age) { 46 | this.age = age; 47 | } 48 | public String getAddress() { 49 | return address; 50 | } 51 | public void setAddress(String address) { 52 | this.address = address; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /ch8_4/src/main/java/com/wisely/ch8_4/service/DemoService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_4.service; 2 | 3 | import com.wisely.ch8_4.domain.Person; 4 | 5 | public interface DemoService { 6 | public Person savePersonWithRollBack(Person person); 7 | public Person savePersonWithoutRollBack(Person person); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ch8_4/src/main/java/com/wisely/ch8_4/service/impl/DemoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_4.service.impl; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import com.wisely.ch8_4.dao.PersonRepository; 9 | import com.wisely.ch8_4.domain.Person; 10 | import com.wisely.ch8_4.service.DemoService; 11 | @Service 12 | public class DemoServiceImpl implements DemoService { 13 | @Autowired 14 | PersonRepository personRepository; //1 15 | 16 | @Transactional(rollbackFor={IllegalArgumentException.class}) //2 17 | public Person savePersonWithRollBack(Person person){ 18 | Person p =personRepository.save(person); 19 | 20 | if(person.getName().equals("汪云飞")){ 21 | throw new IllegalArgumentException("汪云飞已存在,数据将回滚"); //3 22 | } 23 | return p; 24 | } 25 | 26 | @Transactional(noRollbackFor={IllegalArgumentException.class}) //4 27 | public Person savePersonWithoutRollBack(Person person){ 28 | Person p =personRepository.save(person); 29 | 30 | if(person.getName().equals("汪云飞")){ 31 | throw new IllegalArgumentException("汪云飞虽已存在,数据将不会回滚"); 32 | } 33 | return p; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ch8_4/src/main/java/com/wisely/ch8_4/web/MyController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_4.web; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import com.wisely.ch8_4.domain.Person; 8 | import com.wisely.ch8_4.service.DemoService; 9 | 10 | @RestController 11 | public class MyController { 12 | @Autowired 13 | DemoService demoService; 14 | 15 | @RequestMapping("/rollback") 16 | public Person rollback(Person person){ //1 17 | 18 | return demoService.savePersonWithRollBack(person); 19 | } 20 | 21 | @RequestMapping("/norollback") 22 | public Person noRollback(Person person){//2 23 | 24 | return demoService.savePersonWithoutRollBack(person); 25 | 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ch8_4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=oracle.jdbc.OracleDriver 2 | spring.datasource.url=jdbc\:oracle\:thin\:@localhost\:1521\:xe 3 | spring.datasource.username=boot 4 | spring.datasource.password=boot 5 | 6 | #1 7 | spring.jpa.hibernate.ddl-auto=update 8 | #2 9 | spring.jpa.show-sql=true 10 | 11 | 12 | spring.jackson.serialization.indent_output=true -------------------------------------------------------------------------------- /ch8_4/src/test/java/com/wisely/ch8_4/Ch84ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_4; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch84Application.class) 11 | @WebAppConfiguration 12 | public class Ch84ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch8_5/src/main/java/com/wisely/ch8_5/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5; 2 | 3 | import org.springframework.cache.annotation.EnableCaching; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @EnableCaching 8 | public class AppConfig { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /ch8_5/src/main/java/com/wisely/ch8_5/Ch85Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cache.annotation.EnableCaching; 6 | 7 | @SpringBootApplication 8 | @EnableCaching 9 | public class Ch85Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Ch85Application.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ch8_5/src/main/java/com/wisely/ch8_5/dao/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5.dao; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.wisely.ch8_5.domain.Person; 6 | 7 | public interface PersonRepository extends JpaRepository { 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /ch8_5/src/main/java/com/wisely/ch8_5/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | @Entity 8 | public class Person { 9 | @Id 10 | @GeneratedValue 11 | private Long id; 12 | 13 | private String name; 14 | 15 | private Integer age; 16 | 17 | private String address; 18 | 19 | 20 | public Person() { 21 | super(); 22 | } 23 | public Person(Long id, String name, Integer age, String address) { 24 | super(); 25 | this.id = id; 26 | this.name = name; 27 | this.age = age; 28 | this.address = address; 29 | } 30 | public Long getId() { 31 | return id; 32 | } 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | public String getName() { 37 | return name; 38 | } 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | public Integer getAge() { 43 | return age; 44 | } 45 | public void setAge(Integer age) { 46 | this.age = age; 47 | } 48 | public String getAddress() { 49 | return address; 50 | } 51 | public void setAddress(String address) { 52 | this.address = address; 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /ch8_5/src/main/java/com/wisely/ch8_5/service/DemoService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5.service; 2 | 3 | import com.wisely.ch8_5.domain.Person; 4 | 5 | public interface DemoService { 6 | public Person save(Person person); 7 | 8 | public void remove(Long id); 9 | 10 | public Person findOne(Person person); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /ch8_5/src/main/java/com/wisely/ch8_5/service/impl/DemoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5.service.impl; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.cache.annotation.CacheEvict; 5 | import org.springframework.cache.annotation.CachePut; 6 | import org.springframework.cache.annotation.Cacheable; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.wisely.ch8_5.dao.PersonRepository; 10 | import com.wisely.ch8_5.domain.Person; 11 | import com.wisely.ch8_5.service.DemoService; 12 | 13 | 14 | @Service 15 | public class DemoServiceImpl implements DemoService { 16 | 17 | @Autowired 18 | PersonRepository personRepository; 19 | 20 | @Override 21 | @CachePut(value = "people", key = "#person.id") 22 | public Person save(Person person) { 23 | Person p = personRepository.save(person); 24 | System.out.println("为id、key为:"+p.getId()+"数据做了缓存"); 25 | return p; 26 | } 27 | 28 | @Override 29 | @CacheEvict(value = "people")//2 30 | public void remove(Long id) { 31 | System.out.println("删除了id、key为"+id+"的数据缓存"); 32 | //这里不做实际删除操作 33 | } 34 | 35 | @Override 36 | @Cacheable(value = "people", key = "#person.id")//3 37 | public Person findOne(Person person) { 38 | Person p = personRepository.findOne(person.getId()); 39 | System.out.println("为id、key为:"+p.getId()+"数据做了缓存"); 40 | return p; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ch8_5/src/main/java/com/wisely/ch8_5/web/CacheController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5.web; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import com.wisely.ch8_5.domain.Person; 8 | import com.wisely.ch8_5.service.DemoService; 9 | 10 | @RestController 11 | public class CacheController { 12 | 13 | @Autowired 14 | DemoService demoService; 15 | 16 | 17 | 18 | 19 | @RequestMapping("/put") 20 | public Person put(Person person){ 21 | return demoService.save(person); 22 | 23 | } 24 | 25 | 26 | @RequestMapping("/able") 27 | public Person cacheable(Person person){ 28 | 29 | 30 | return demoService.findOne(person); 31 | 32 | } 33 | 34 | @RequestMapping("/evit") 35 | public String evit(Long id){ 36 | demoService.remove(id); 37 | return "ok"; 38 | 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /ch8_5/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=oracle.jdbc.OracleDriver 2 | spring.datasource.url=jdbc\:oracle\:thin\:@localhost\:1521\:xe 3 | spring.datasource.username=boot 4 | spring.datasource.password=boot 5 | 6 | spring.jpa.hibernate.ddl-auto=update 7 | spring.jpa.show-sql=true 8 | 9 | 10 | spring.jackson.serialization.indent_output=true -------------------------------------------------------------------------------- /ch8_5/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ch8_5/src/test/java/com/wisely/ch8_5/Ch85ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_5; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch85Application.class) 11 | @WebAppConfiguration 12 | public class Ch85ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch8_6_1/src/main/java/com/wisely/ch8_6_1/Ch861Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_1; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch861Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch861Application.class, args); 11 | } 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch8_6_1/src/main/java/com/wisely/ch8_6_1/dao/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_1.dao; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.mongodb.repository.MongoRepository; 6 | import org.springframework.data.mongodb.repository.Query; 7 | 8 | import com.wisely.ch8_6_1.domain.Person; 9 | 10 | public interface PersonRepository extends MongoRepository { 11 | 12 | Person findByName(String name); 13 | 14 | @Query("{'age': ?0}") 15 | List withQueryFindByAge(Integer age); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ch8_6_1/src/main/java/com/wisely/ch8_6_1/domain/Location.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_1.domain; 2 | 3 | public class Location { 4 | 5 | private String place; 6 | 7 | private String year; 8 | 9 | 10 | 11 | public Location(String place, String year) { 12 | super(); 13 | this.place = place; 14 | this.year = year; 15 | } 16 | 17 | public String getPlace() { 18 | return place; 19 | } 20 | 21 | public void setPlace(String place) { 22 | this.place = place; 23 | } 24 | 25 | public String getYear() { 26 | return year; 27 | } 28 | 29 | public void setYear(String year) { 30 | this.year = year; 31 | } 32 | 33 | 34 | 35 | 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /ch8_6_1/src/main/java/com/wisely/ch8_6_1/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_1.domain; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedHashSet; 5 | 6 | import org.springframework.data.annotation.Id; 7 | import org.springframework.data.mongodb.core.mapping.Document; 8 | import org.springframework.data.mongodb.core.mapping.Field; 9 | 10 | @Document //1 11 | public class Person { 12 | @Id 13 | private String id; 14 | private String name; 15 | private Integer age; 16 | @Field("locs") 17 | private Collection locations = new LinkedHashSet(); 18 | 19 | 20 | public Person(String name, Integer age) { 21 | super(); 22 | this.name = name; 23 | this.age = age; 24 | } 25 | 26 | public String getId() { 27 | return id; 28 | } 29 | 30 | public void setId(String id) { 31 | this.id = id; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public Integer getAge() { 43 | return age; 44 | } 45 | 46 | public void setAge(Integer age) { 47 | this.age = age; 48 | } 49 | 50 | public Collection getLocations() { 51 | return locations; 52 | } 53 | 54 | public void setLocations(Collection locations) { 55 | this.locations = locations; 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /ch8_6_1/src/main/java/com/wisely/ch8_6_1/web/DataController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_1.web; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedHashSet; 5 | import java.util.List; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.wisely.ch8_6_1.dao.PersonRepository; 12 | import com.wisely.ch8_6_1.domain.Location; 13 | import com.wisely.ch8_6_1.domain.Person; 14 | 15 | @RestController 16 | public class DataController { 17 | 18 | @Autowired 19 | PersonRepository personRepository; 20 | 21 | @RequestMapping("/save") 22 | public Person save(){ 23 | Person p = new Person("wyf",32); 24 | Collection locations = new LinkedHashSet(); 25 | Location loc1 = new Location("上海","2009"); 26 | Location loc2 = new Location("合肥","2010"); 27 | Location loc3 = new Location("广州","2011"); 28 | Location loc4 = new Location("马鞍山","2012"); 29 | locations.add(loc1); 30 | locations.add(loc2); 31 | locations.add(loc3); 32 | locations.add(loc4); 33 | p.setLocations(locations); 34 | 35 | return personRepository.save(p); 36 | } 37 | 38 | @RequestMapping("/q1") 39 | public Person q1(String name){ 40 | return personRepository.findByName(name); 41 | } 42 | 43 | @RequestMapping("/q2") 44 | public List q2(Integer age){ 45 | return personRepository.withQueryFindByAge(age); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /ch8_6_1/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch8_6_1/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch8_6_1/src/test/java/com/wisely/ch8_6_1/Ch861ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_1; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch861Application.class) 11 | @WebAppConfiguration 12 | public class Ch861ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch8_6_2/src/main/java/com/wisely/ch8_6_2/dao/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_2.dao; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Person implements Serializable{ 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String id; 10 | private String name; 11 | private Integer age; 12 | 13 | public Person() { 14 | super(); 15 | } 16 | public Person(String id,String name, Integer age) { 17 | super(); 18 | this.id = id; 19 | this.name = name; 20 | this.age = age; 21 | } 22 | public String getId() { 23 | return id; 24 | } 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | public String getName() { 29 | return name; 30 | } 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | public Integer getAge() { 35 | return age; 36 | } 37 | public void setAge(Integer age) { 38 | this.age = age; 39 | } 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /ch8_6_2/src/main/java/com/wisely/ch8_6_2/domain/PersonDao.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_2.domain; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.core.StringRedisTemplate; 8 | import org.springframework.data.redis.core.ValueOperations; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import com.wisely.ch8_6_2.dao.Person; 12 | 13 | @Repository 14 | public class PersonDao { 15 | 16 | @Autowired 17 | StringRedisTemplate stringRedisTemplate; //1 18 | 19 | @Resource(name="stringRedisTemplate") 20 | ValueOperations valOpsStr; //3 21 | 22 | 23 | @Autowired 24 | RedisTemplate redisTemplate; //2 25 | 26 | @Resource(name="redisTemplate") 27 | ValueOperations valOps; //4 28 | 29 | public void stringRedisTemplateDemo(){ //5 30 | valOpsStr.set("xx", "yy"); 31 | } 32 | 33 | 34 | public void save(Person person){ //6 35 | valOps.set(person.getId(),person); 36 | } 37 | 38 | public String getString(){//7 39 | return valOpsStr.get("xx"); 40 | } 41 | 42 | public Person getPerson(){//8 43 | return (Person) valOps.get("1"); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /ch8_6_2/src/main/java/com/wisely/ch8_6_2/web/DataController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_2.web; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import com.wisely.ch8_6_2.dao.Person; 8 | import com.wisely.ch8_6_2.domain.PersonDao; 9 | 10 | @RestController 11 | public class DataController { 12 | 13 | @Autowired 14 | PersonDao personDao; 15 | 16 | @RequestMapping("/set") //1 17 | public void set(){ 18 | Person person = new Person("1","wyf", 32); 19 | personDao.save(person); 20 | personDao.stringRedisTemplateDemo(); 21 | } 22 | 23 | @RequestMapping("/getStr") //2 24 | public String getStr(){ 25 | return personDao.getString(); 26 | } 27 | 28 | @RequestMapping("/getPerson") //3 29 | public Person getPerson(){ 30 | return personDao.getPerson(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ch8_6_2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.data = DEBUG -------------------------------------------------------------------------------- /ch8_6_2/src/test/java/com/wisely/ch8_6_2/Ch862ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch8_6_2; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch862Application.class) 11 | @WebAppConfiguration 12 | public class Ch862ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/Ch91Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch91Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch91Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | @Configuration 8 | public class WebMvcConfig extends WebMvcConfigurerAdapter{ 9 | 10 | @Override 11 | public void addViewControllers(ViewControllerRegistry registry) { 12 | registry.addViewController("/login").setViewName("login"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/config/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | 10 | import com.wisely.ch9_1.security.CustomUserService; 11 | 12 | @Configuration 13 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter{//1 14 | 15 | @Bean 16 | UserDetailsService customUserService(){ //2 17 | return new CustomUserService(); 18 | } 19 | 20 | @Override 21 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 22 | auth.userDetailsService(customUserService()); //3 23 | 24 | } 25 | 26 | @Override 27 | protected void configure(HttpSecurity http) throws Exception { 28 | http.authorizeRequests() 29 | .anyRequest().authenticated() //4 30 | .and() 31 | .formLogin() 32 | .loginPage("/login") 33 | .failureUrl("/login?error") 34 | .permitAll() //5 35 | .and() 36 | .logout().permitAll(); //6 37 | 38 | 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/dao/SysUserRepository.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1.dao; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.wisely.ch9_1.domain.SysUser; 6 | 7 | public interface SysUserRepository extends JpaRepository{ 8 | 9 | SysUser findByUsername(String username); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/domain/Msg.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1.domain; 2 | 3 | public class Msg { 4 | private String title; 5 | private String content; 6 | private String etraInfo; 7 | 8 | public Msg(String title, String content, String etraInfo) { 9 | super(); 10 | this.title = title; 11 | this.content = content; 12 | this.etraInfo = etraInfo; 13 | } 14 | public String getTitle() { 15 | return title; 16 | } 17 | public void setTitle(String title) { 18 | this.title = title; 19 | } 20 | public String getContent() { 21 | return content; 22 | } 23 | public void setContent(String content) { 24 | this.content = content; 25 | } 26 | public String getEtraInfo() { 27 | return etraInfo; 28 | } 29 | public void setEtraInfo(String etraInfo) { 30 | this.etraInfo = etraInfo; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/domain/SysRole.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | @Entity 8 | public class SysRole { 9 | @Id 10 | @GeneratedValue 11 | private Long id; 12 | private String name; 13 | public Long getId() { 14 | return id; 15 | } 16 | public void setId(Long id) { 17 | this.id = id; 18 | } 19 | public String getName() { 20 | return name; 21 | } 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/security/CustomUserService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.security.core.userdetails.UserDetails; 5 | import org.springframework.security.core.userdetails.UserDetailsService; 6 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 7 | 8 | import com.wisely.ch9_1.dao.SysUserRepository; 9 | import com.wisely.ch9_1.domain.SysUser; 10 | 11 | public class CustomUserService implements UserDetailsService { //1 12 | @Autowired 13 | SysUserRepository userRepository; 14 | 15 | @Override 16 | public UserDetails loadUserByUsername(String username) { //2 17 | 18 | SysUser user = userRepository.findByUsername(username); 19 | if(user == null){ 20 | throw new UsernameNotFoundException("用户名不存在"); 21 | } 22 | 23 | return user; //3 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ch9_1/src/main/java/com/wisely/ch9_1/web/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | import com.wisely.ch9_1.domain.Msg; 8 | 9 | @Controller 10 | public class HomeController { 11 | 12 | @RequestMapping("/") 13 | public String index(Model model){ 14 | Msg msg = new Msg("测试标题","测试内容","额外信息,只对管理员显示"); 15 | model.addAttribute("msg", msg); 16 | return "home"; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /ch9_1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=oracle.jdbc.OracleDriver 2 | spring.datasource.url=jdbc\:oracle\:thin\:@localhost\:1521\:xe 3 | spring.datasource.username=boot 4 | spring.datasource.password=boot 5 | 6 | logging.level.org.springframework.security= INFO 7 | 8 | spring.thymeleaf.cache=false 9 | 10 | spring.jpa.hibernate.ddl-auto=update 11 | spring.jpa.show-sql=true 12 | -------------------------------------------------------------------------------- /ch9_1/src/main/resources/data--.sql: -------------------------------------------------------------------------------- 1 | insert into SYS_USER (id,username, password) values (1,'wyf', 'wyf'); 2 | insert into SYS_USER (id,username, password) values (2,'wisely', 'wisely'); 3 | 4 | insert into SYS_ROLE(id,name) values(1,'ROLE_ADMIN'); 5 | insert into SYS_ROLE(id,name) values(2,'ROLE_USER'); 6 | 7 | insert into SYS_USER_ROLES(SYS_USER_ID,ROLES_ID) values(1,1); 8 | insert into SYS_USER_ROLES(SYS_USER_ID,ROLES_ID) values(2,2); -------------------------------------------------------------------------------- /ch9_1/src/test/java/com/wisely/ch9_1/Ch91ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_1; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch91Application.class) 11 | @WebAppConfiguration 12 | public class Ch91ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch9_2/src/main/java/com/wisely/ch9_2/Ch92Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_2; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Ch92Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Ch92Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ch9_2/src/main/java/com/wisely/ch9_2/batch/CsvBeanValidator.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_2.batch; 2 | 3 | import java.util.Set; 4 | 5 | import javax.validation.ConstraintViolation; 6 | import javax.validation.Validation; 7 | import javax.validation.ValidatorFactory; 8 | 9 | import org.springframework.batch.item.validator.ValidationException; 10 | import org.springframework.batch.item.validator.Validator; 11 | import org.springframework.beans.factory.InitializingBean; 12 | 13 | public class CsvBeanValidator implements Validator,InitializingBean { 14 | private javax.validation.Validator validator; 15 | @Override 16 | public void afterPropertiesSet() throws Exception { //1 17 | ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); 18 | validator = validatorFactory.usingContext().getValidator(); 19 | } 20 | 21 | @Override 22 | public void validate(T value) throws ValidationException { 23 | Set> constraintViolations = validator.validate(value); //2 24 | if(constraintViolations.size()>0){ 25 | 26 | StringBuilder message = new StringBuilder(); 27 | for (ConstraintViolation constraintViolation : constraintViolations) { 28 | message.append(constraintViolation.getMessage() + "\n"); 29 | } 30 | throw new ValidationException(message.toString()); 31 | 32 | } 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /ch9_2/src/main/java/com/wisely/ch9_2/batch/CsvItemProcessor.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_2.batch; 2 | 3 | import org.springframework.batch.item.validator.ValidatingItemProcessor; 4 | import org.springframework.batch.item.validator.ValidationException; 5 | 6 | import com.wisely.ch9_2.domain.Person; 7 | 8 | public class CsvItemProcessor extends ValidatingItemProcessor{ 9 | 10 | @Override 11 | public Person process(Person item) throws ValidationException { 12 | super.process(item); //1 13 | 14 | if(item.getNation().equals("汉族")){ //2 15 | item.setNation("01"); 16 | }else{ 17 | item.setNation("02"); 18 | } 19 | return item; 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ch9_2/src/main/java/com/wisely/ch9_2/batch/CsvJobListener.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_2.batch; 2 | 3 | import org.springframework.batch.core.JobExecution; 4 | import org.springframework.batch.core.JobExecutionListener; 5 | 6 | public class CsvJobListener implements JobExecutionListener{ 7 | 8 | long startTime; 9 | long endTime; 10 | @Override 11 | public void beforeJob(JobExecution jobExecution) { 12 | startTime = System.currentTimeMillis(); 13 | System.out.println("任务处理开始"); 14 | } 15 | 16 | @Override 17 | public void afterJob(JobExecution jobExecution) { 18 | endTime = System.currentTimeMillis(); 19 | System.out.println("任务处理结束"); 20 | System.out.println("耗时:" + (endTime - startTime) + "ms"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /ch9_2/src/main/java/com/wisely/ch9_2/domain/Person.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_2.domain; 2 | 3 | import javax.validation.constraints.Size; 4 | 5 | public class Person { 6 | 7 | @Size(max=4,min=2) //1 8 | private String name; 9 | 10 | private int age; 11 | 12 | private String nation; 13 | 14 | private String address; 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | public int getAge() { 25 | return age; 26 | } 27 | 28 | public void setAge(int age) { 29 | this.age = age; 30 | } 31 | 32 | public String getNation() { 33 | return nation; 34 | } 35 | 36 | public void setNation(String nation) { 37 | this.nation = nation; 38 | } 39 | 40 | public String getAddress() { 41 | return address; 42 | } 43 | 44 | public void setAddress(String address) { 45 | this.address = address; 46 | } 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /ch9_2/src/main/java/com/wisely/ch9_2/web/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_2.web; 2 | 3 | import org.springframework.batch.core.Job; 4 | import org.springframework.batch.core.JobParameters; 5 | import org.springframework.batch.core.JobParametersBuilder; 6 | import org.springframework.batch.core.launch.JobLauncher; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @RestController 12 | public class DemoController { 13 | 14 | @Autowired 15 | JobLauncher jobLauncher; 16 | 17 | @Autowired 18 | Job importJob; 19 | public JobParameters jobParameters; 20 | 21 | @RequestMapping("/read") 22 | public String imp(String fileName) throws Exception{ 23 | 24 | String path = fileName+".csv"; 25 | jobParameters = new JobParametersBuilder() 26 | .addLong("time", System.currentTimeMillis()) 27 | .addString("input.file.name", path) 28 | .toJobParameters(); 29 | jobLauncher.run(importJob,jobParameters); 30 | return "ok"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /ch9_2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driverClassName=oracle.jdbc.OracleDriver 2 | spring.datasource.url=jdbc\:oracle\:thin\:@localhost\:1521\:xe 3 | spring.datasource.username=boot 4 | spring.datasource.password=boot 5 | 6 | spring.batch.job.enabled=false 7 | 8 | logging.level.org.springframework.web = DEBUG 9 | 10 | 11 | -------------------------------------------------------------------------------- /ch9_2/src/main/resources/people.csv: -------------------------------------------------------------------------------- 1 | 汪某某,11,汉族,合肥 2 | 张某某,12,汉族,上海 3 | 李某某,13,非汉族,武汉 4 | 刘某,14,非汉族,南京 5 | 欧阳某某,115,汉族,北京 6 | -------------------------------------------------------------------------------- /ch9_2/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | 2 | create table PERSON 3 | ( 4 | id NUMBER not null primary key, 5 | name VARCHAR2(20), 6 | age NUMBER, 7 | nation VARCHAR2(20), 8 | address VARCHAR2(20) 9 | ); 10 | 11 | -------------------------------------------------------------------------------- /ch9_2/src/test/java/com/wisely/ch9_2/Ch92ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_2; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Ch92Application.class) 11 | @WebAppConfiguration 12 | public class Ch92ApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /ch9_3_4/src/main/java/com/wisely/ch9_3_4/Ch934Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_3_4; 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.jms.core.JmsTemplate; 8 | 9 | @SpringBootApplication 10 | public class Ch934Application implements CommandLineRunner{ //1 11 | 12 | @Autowired 13 | JmsTemplate jmsTemplate; //2 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(Ch934Application.class, args); 17 | 18 | } 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | jmsTemplate.send("my-destination", new Msg()); //3 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ch9_3_4/src/main/java/com/wisely/ch9_3_4/Msg.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_3_4; 2 | 3 | import javax.jms.JMSException; 4 | import javax.jms.Message; 5 | import javax.jms.Session; 6 | 7 | import org.springframework.jms.core.MessageCreator; 8 | 9 | public class Msg implements MessageCreator{ 10 | 11 | @Override 12 | public Message createMessage(Session session) throws JMSException { 13 | return session.createTextMessage("测试消息"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch9_3_4/src/main/java/com/wisely/ch9_3_4/Receiver.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_3_4; 2 | 3 | import org.springframework.jms.annotation.JmsListener; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class Receiver { 8 | 9 | @JmsListener(destination = "my-destination") //1 10 | public void receiveMessage(String message) { 11 | System.out.println("接受到: <" + message + ">"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch9_3_4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.activemq.broker-url=tcp://localhost:61616 -------------------------------------------------------------------------------- /ch9_3_4/src/test/java/com/wisely/ch9_3_4/Ch934ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_3_4; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @SpringApplicationConfiguration(classes = Ch934Application.class) 10 | public class Ch934ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch9_3_5/src/main/java/com/wisely/ch9_3_5/Ch935Application.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_3_5; 2 | 3 | import org.springframework.amqp.core.Queue; 4 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 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.context.annotation.Bean; 10 | 11 | @SpringBootApplication 12 | public class Ch935Application implements CommandLineRunner{ 13 | @Autowired 14 | RabbitTemplate rabbitTemplate; //1 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(Ch935Application.class, args); 18 | } 19 | 20 | @Bean //2 21 | public Queue wiselyQueue(){ 22 | return new Queue("my-queue"); 23 | } 24 | 25 | 26 | @Override 27 | public void run(String... args) throws Exception { 28 | rabbitTemplate.convertAndSend("my-queue", "来自RabbitMQ的问候"); //3 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ch9_3_5/src/main/java/com/wisely/ch9_3_5/Receiver.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_3_5; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class Receiver { 8 | 9 | @RabbitListener(queues = "my-queue") 10 | public void receiveMessage(String message) { 11 | System.out.println("Received <" + message + ">"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ch9_3_5/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch9_3_5/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch9_3_5/src/test/java/com/wisely/ch9_3_5/Ch935ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_3_5; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @SpringApplicationConfiguration(classes = Ch935Application.class) 10 | public class Ch935ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ch9_4/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/ch9_4/src/main/resources/application.properties -------------------------------------------------------------------------------- /ch9_4/src/test/java/com/wisely/ch9_4/Ch94ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.ch9_4; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.SpringApplicationConfiguration; 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @SpringApplicationConfiguration(classes = Ch94Application.class) 10 | public class Ch94ApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/Action.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.aop; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target(ElementType.METHOD) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented 12 | public @interface Action { 13 | String name(); 14 | } 15 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/AopConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.aop; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 6 | 7 | @Configuration 8 | @ComponentScan("com.wisely.highlight_spring4.ch1.aop") 9 | @EnableAspectJAutoProxy //1 10 | public class AopConfig { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/DemoAnnotationService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/DemoAnnotationService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/DemoMethodService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.aop; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class DemoMethodService { 7 | public void add(){} 8 | } 9 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/LogAspect.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/LogAspect.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/aop/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.aop; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | AnnotationConfigApplicationContext context = 8 | new AnnotationConfigApplicationContext(AopConfig.class); //1 9 | 10 | DemoAnnotationService demoAnnotationService = context.getBean(DemoAnnotationService.class); 11 | 12 | DemoMethodService demoMethodService = context.getBean(DemoMethodService.class); 13 | 14 | demoAnnotationService.add(); 15 | 16 | demoMethodService.add(); 17 | 18 | context.close(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/di/DiConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.di; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration //1 7 | @ComponentScan("com.wisely.highlight_spring4.ch1.di") //2 8 | public class DiConfig { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/di/FunctionService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.di; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service //1 6 | public class FunctionService { 7 | public String sayHello(String word){ 8 | return "Hello " + word +" !"; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/di/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.di; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | AnnotationConfigApplicationContext context = 8 | new AnnotationConfigApplicationContext(DiConfig.class); //1 9 | 10 | UseFunctionService useFunctionService = context.getBean(UseFunctionService.class); //2 11 | 12 | System.out.println(useFunctionService.SayHello("world")); 13 | 14 | context.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/di/UseFunctionService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.di; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service //1 7 | public class UseFunctionService { 8 | @Autowired //2 9 | FunctionService functionService; 10 | 11 | public String SayHello(String word){ 12 | return functionService.sayHello(word); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/javaconfig/FunctionService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.javaconfig; 2 | //1 3 | public class FunctionService { 4 | 5 | public String sayHello(String word){ 6 | return "Hello " + word +" !"; 7 | } 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/javaconfig/JavaConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.javaconfig; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration //1 7 | public class JavaConfig { 8 | @Bean //2 9 | public FunctionService functionService(){ 10 | return new FunctionService(); 11 | } 12 | 13 | @Bean 14 | public UseFunctionService useFunctionService(){ 15 | UseFunctionService useFunctionService = new UseFunctionService(); 16 | useFunctionService.setFunctionService(functionService()); //3 17 | return useFunctionService; 18 | 19 | } 20 | 21 | // @Bean 22 | // public UseFunctionService useFunctionService(FunctionService functionService){//4 23 | // UseFunctionService useFunctionService = new UseFunctionService(); 24 | // useFunctionService.setFunctionService(functionService); 25 | // return useFunctionService; 26 | // } 27 | } 28 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/javaconfig/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.javaconfig; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | AnnotationConfigApplicationContext context = 8 | new AnnotationConfigApplicationContext(JavaConfig.class); 9 | 10 | UseFunctionService useFunctionService = context.getBean(UseFunctionService.class); 11 | 12 | System.out.println(useFunctionService.SayHello("java config")); 13 | 14 | context.close(); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch1/javaconfig/UseFunctionService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch1.javaconfig; 2 | 3 | import com.wisely.highlight_spring4.ch1.javaconfig.FunctionService; 4 | //1 5 | public class UseFunctionService { 6 | //2 7 | FunctionService functionService; 8 | 9 | public void setFunctionService(FunctionService functionService) { 10 | this.functionService = functionService; 11 | } 12 | 13 | public String SayHello(String word){ 14 | return functionService.sayHello(word); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/el/DemoService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/el/DemoService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/el/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.el; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | AnnotationConfigApplicationContext context = 9 | new AnnotationConfigApplicationContext(ElConfig.class); 10 | 11 | ElConfig resourceService = context.getBean(ElConfig.class); 12 | 13 | resourceService.outputResource(); 14 | 15 | context.close(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/el/test.properties: -------------------------------------------------------------------------------- 1 | book.author=wangyunfei 2 | book.name=spring boot -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/el/test.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/el/test.txt -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/event/DemoEvent.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.event; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | public class DemoEvent extends ApplicationEvent{ 6 | private static final long serialVersionUID = 1L; 7 | private String msg; 8 | 9 | public DemoEvent(Object source,String msg) { 10 | super(source); 11 | this.msg = msg; 12 | } 13 | 14 | public String getMsg() { 15 | return msg; 16 | } 17 | 18 | public void setMsg(String msg) { 19 | this.msg = msg; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/event/DemoListener.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/event/DemoListener.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/event/DemoPublisher.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.event; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class DemoPublisher { 9 | @Autowired 10 | ApplicationContext applicationContext; 11 | 12 | public void publish(String msg){ 13 | applicationContext.publishEvent(new DemoEvent(this, msg)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/event/EventConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.event; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ComponentScan("com.wisely.highlight_spring4.ch2.event") 8 | public class EventConfig { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/event/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.event; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | AnnotationConfigApplicationContext context = 8 | new AnnotationConfigApplicationContext(EventConfig.class); 9 | 10 | DemoPublisher demoPublisher = context.getBean(DemoPublisher.class); 11 | 12 | demoPublisher.publish("hello application event"); 13 | 14 | context.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/prepost/BeanWayService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/prepost/BeanWayService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/prepost/JSR250WayService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/prepost/JSR250WayService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/prepost/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.prepost; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | AnnotationConfigApplicationContext context = 9 | new AnnotationConfigApplicationContext(PrePostConfig.class); 10 | 11 | BeanWayService beanWayService = context.getBean(BeanWayService.class); 12 | JSR250WayService jsr250WayService = context.getBean(JSR250WayService.class); 13 | 14 | context.close(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/prepost/PrePostConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.prepost; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | @ComponentScan("com.wisely.highlight_spring4.ch2.prepost") 9 | public class PrePostConfig { 10 | 11 | @Bean(initMethod="init",destroyMethod="destroy") //1 12 | BeanWayService beanWayService(){ 13 | return new BeanWayService(); 14 | } 15 | 16 | @Bean 17 | JSR250WayService jsr250WayService(){ 18 | return new JSR250WayService(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/profile/DemoBean.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.profile; 2 | 3 | 4 | public class DemoBean { 5 | 6 | private String content; 7 | 8 | public DemoBean(String content) { 9 | super(); 10 | this.content = content; 11 | } 12 | 13 | public String getContent() { 14 | return content; 15 | } 16 | 17 | public void setContent(String content) { 18 | this.content = content; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/profile/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.profile; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | AnnotationConfigApplicationContext context = 9 | new AnnotationConfigApplicationContext(); 10 | 11 | context.getEnvironment().setActiveProfiles("dev"); //1 12 | context.register(ProfileConfig.class);//2 13 | context.refresh(); //3 14 | 15 | DemoBean demoBean = context.getBean(DemoBean.class); 16 | 17 | System.out.println(demoBean.getContent()); 18 | 19 | context.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/profile/ProfileConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.profile; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | 7 | @Configuration 8 | public class ProfileConfig { 9 | @Bean 10 | @Profile("dev") //1 11 | public DemoBean devDemoBean() { 12 | return new DemoBean("from development profile"); 13 | } 14 | 15 | @Bean 16 | @Profile("prod") //2 17 | public DemoBean prodDemoBean() { 18 | return new DemoBean("from production profile"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/scope/DemoPrototypeService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.scope; 2 | 3 | import org.springframework.context.annotation.Scope; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | @Scope("prototype")//1 8 | public class DemoPrototypeService { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/scope/DemoSingletonService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.scope; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service //1 6 | public class DemoSingletonService { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/scope/Main.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/scope/Main.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch2/scope/ScopeConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch2.scope; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ComponentScan("com.wisely.highlight_spring4.ch2.scope") 8 | public class ScopeConfig { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/annotation/DemoConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.annotation; 2 | 3 | @WiselyConfiguration("com.wisely.highlight_spring4.ch3.annotation") 4 | public class DemoConfig { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/annotation/DemoService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/annotation/DemoService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/annotation/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.annotation; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | AnnotationConfigApplicationContext context = 9 | new AnnotationConfigApplicationContext(DemoConfig.class); 10 | 11 | DemoService demoService = context.getBean(DemoService.class); 12 | 13 | demoService.outputResult(); 14 | 15 | context.close(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/annotation/WiselyConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import org.springframework.context.annotation.ComponentScan; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Documented 15 | @Configuration //1 16 | @ComponentScan //2 17 | public @interface WiselyConfiguration { 18 | 19 | String[] value() default {}; //3 20 | 21 | } 22 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/aware/AwareConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.aware; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | @Configuration 6 | @ComponentScan("com.wisely.highlight_spring4.ch2.aware") 7 | public class AwareConfig { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/aware/AwareService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/aware/AwareService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/aware/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.aware; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | 8 | AnnotationConfigApplicationContext context = 9 | new AnnotationConfigApplicationContext(AwareConfig.class); 10 | 11 | AwareService awareService = context.getBean(AwareService.class); 12 | awareService.outputResult(); 13 | 14 | context.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/aware/test.txt: -------------------------------------------------------------------------------- 1 | 111111 -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/ConditionConifg.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.conditional; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Conditional; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class ConditionConifg { 9 | @Bean 10 | @Conditional(WindowsCondition.class) //1 11 | public ListService windowsListService() { 12 | return new WindowsListService(); 13 | } 14 | 15 | @Bean 16 | @Conditional(LinuxCondition.class) //2 17 | public ListService linuxListService() { 18 | return new LinuxListService(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/LinuxCondition.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.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 LinuxCondition implements Condition { 8 | 9 | public boolean matches(ConditionContext context, 10 | AnnotatedTypeMetadata metadata) { 11 | return context.getEnvironment().getProperty("os.name").contains("Linux"); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/LinuxListService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.conditional; 2 | 3 | public class LinuxListService implements ListService{ 4 | 5 | @Override 6 | public String showListCmd() { 7 | return "ls"; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/ListService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.conditional; 2 | 3 | public interface ListService { 4 | public String showListCmd(); 5 | } 6 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/Main.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/Main.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/WindowsCondition.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.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 WindowsCondition implements Condition { 8 | 9 | public boolean matches(ConditionContext context, 10 | AnnotatedTypeMetadata metadata) { 11 | return context.getEnvironment().getProperty("os.name").contains("Windows"); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/conditional/WindowsListService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.conditional; 2 | 3 | public class WindowsListService implements ListService { 4 | 5 | @Override 6 | public String showListCmd() { 7 | return "dir"; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/fortest/TestBean.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.fortest; 2 | 3 | public class TestBean { 4 | private String content; 5 | 6 | public TestBean(String content) { 7 | super(); 8 | this.content = content; 9 | } 10 | 11 | public String getContent() { 12 | return content; 13 | } 14 | 15 | public void setContent(String content) { 16 | this.content = content; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/fortest/TestConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.fortest; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | @Configuration 7 | public class TestConfig { 8 | @Bean 9 | @Profile("dev") 10 | public TestBean devTestBean() { 11 | return new TestBean("from development profile"); 12 | } 13 | 14 | @Bean 15 | @Profile("prod") 16 | public TestBean prodTestBean() { 17 | return new TestBean("from production profile"); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskexecutor/AsyncTaskService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskexecutor/AsyncTaskService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskexecutor/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.taskexecutor; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | AnnotationConfigApplicationContext context = 9 | new AnnotationConfigApplicationContext(TaskExecutorConfig.class); 10 | 11 | AsyncTaskService asyncTaskService = context.getBean(AsyncTaskService.class); 12 | 13 | for(int i =0 ;i<10;i++){ 14 | asyncTaskService.executeAsyncTask(i); 15 | asyncTaskService.executeAsyncTaskPlus(i); 16 | } 17 | context.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskexecutor/TaskExecutorConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.taskexecutor; 2 | 3 | import java.util.concurrent.Executor; 4 | 5 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.scheduling.annotation.AsyncConfigurer; 9 | import org.springframework.scheduling.annotation.EnableAsync; 10 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 11 | @Configuration 12 | @ComponentScan("com.wisely.highlight_spring4.ch3.taskexecutor") 13 | @EnableAsync //1 14 | public class TaskExecutorConfig implements AsyncConfigurer{//2 15 | 16 | @Override 17 | public Executor getAsyncExecutor() {//2 18 | ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); 19 | taskExecutor.setCorePoolSize(5); 20 | taskExecutor.setMaxPoolSize(10); 21 | taskExecutor.setQueueCapacity(25); 22 | taskExecutor.initialize(); 23 | return taskExecutor; 24 | } 25 | 26 | @Override 27 | public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { 28 | return null; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskscheduler/Main.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.taskscheduler; 2 | 3 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | AnnotationConfigApplicationContext context = 8 | new AnnotationConfigApplicationContext(TaskSchedulerConfig.class); 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskscheduler/ScheduledTaskService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangxiaodong0120/springboot-wyf-sourcecode/777a264ccc01f2cd76dd4adc4db6914bf9c0266b/highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskscheduler/ScheduledTaskService.java -------------------------------------------------------------------------------- /highlight_spring4/src/main/java/com/wisely/highlight_spring4/ch3/taskscheduler/TaskSchedulerConfig.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.taskscheduler; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | @Configuration 8 | @ComponentScan("com.wisely.highlight_spring4.ch3.taskscheduler") 9 | @EnableScheduling //1 10 | public class TaskSchedulerConfig { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /highlight_spring4/src/test/java/com/wisely/highlight_spring4/ch3/fortest/DemoBeanIntegrationTests.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_spring4.ch3.fortest; 2 | 3 | 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.test.context.ActiveProfiles; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | @RunWith(SpringJUnit4ClassRunner.class) //1 13 | @ContextConfiguration(classes = {TestConfig.class}) //2 14 | @ActiveProfiles("prod") //3 15 | public class DemoBeanIntegrationTests { 16 | @Autowired //4 17 | private TestBean testBean; 18 | 19 | @Test //5 20 | public void prodBeanShouldInject(){ 21 | String expected = "from production profile"; 22 | String actual = testBean.getContent(); 23 | Assert.assertEquals(expected, actual); 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/WebInitializer.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4; 2 | 3 | import javax.servlet.ServletContext; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.ServletRegistration.Dynamic; 6 | 7 | import org.springframework.web.WebApplicationInitializer; 8 | import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; 9 | import org.springframework.web.servlet.DispatcherServlet; 10 | 11 | public class WebInitializer implements WebApplicationInitializer {//1 12 | 13 | @Override 14 | public void onStartup(ServletContext servletContext) 15 | throws ServletException { 16 | AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); 17 | ctx.register(MyMvcConfig.class); 18 | ctx.setServletContext(servletContext); //2 19 | 20 | Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); //3 21 | servlet.addMapping("/"); 22 | servlet.setLoadOnStartup(1); 23 | servlet.setAsyncSupported(true);//1 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/advice/ExceptionHandlerAdvice.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.advice; 2 | 3 | import org.springframework.ui.Model; 4 | import org.springframework.web.bind.WebDataBinder; 5 | import org.springframework.web.bind.annotation.ControllerAdvice; 6 | import org.springframework.web.bind.annotation.ExceptionHandler; 7 | import org.springframework.web.bind.annotation.InitBinder; 8 | import org.springframework.web.bind.annotation.ModelAttribute; 9 | import org.springframework.web.context.request.WebRequest; 10 | import org.springframework.web.servlet.ModelAndView; 11 | 12 | @ControllerAdvice //1 13 | public class ExceptionHandlerAdvice { 14 | 15 | @ExceptionHandler(value = Exception.class)//2 16 | public ModelAndView exception(Exception exception, WebRequest request) { 17 | ModelAndView modelAndView = new ModelAndView("error");// error页面 18 | modelAndView.addObject("errorMessage", exception.getMessage()); 19 | return modelAndView; 20 | } 21 | 22 | @ModelAttribute //3 23 | public void addAttributes(Model model) { 24 | model.addAttribute("msg", "额外信息"); //3 25 | } 26 | 27 | @InitBinder //4 28 | public void initBinder(WebDataBinder webDataBinder) { 29 | webDataBinder.setDisallowedFields("id"); //5 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/domain/DemoObj.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.domain; 2 | 3 | public class DemoObj { 4 | private Long id; 5 | private String name; 6 | 7 | public DemoObj() { 8 | super(); 9 | } 10 | public DemoObj(Long id, String name) { 11 | super(); 12 | this.id = id; 13 | this.name = name; 14 | } 15 | public Long getId() { 16 | return id; 17 | } 18 | public void setId(Long id) { 19 | this.id = id; 20 | } 21 | public String getName() { 22 | return name; 23 | } 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/interceptor/DemoInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.interceptor; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.web.servlet.ModelAndView; 7 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 8 | 9 | public class DemoInterceptor extends HandlerInterceptorAdapter {//1 10 | 11 | @Override 12 | public boolean preHandle(HttpServletRequest request, //2 13 | HttpServletResponse response, Object handler) throws Exception { 14 | long startTime = System.currentTimeMillis(); 15 | request.setAttribute("startTime", startTime); 16 | return true; 17 | } 18 | 19 | @Override 20 | public void postHandle(HttpServletRequest request, //3 21 | HttpServletResponse response, Object handler, 22 | ModelAndView modelAndView) throws Exception { 23 | long startTime = (Long) request.getAttribute("startTime"); 24 | request.removeAttribute("startTime"); 25 | long endTime = System.currentTimeMillis(); 26 | System.out.println("本次请求处理时间为:" + new Long(endTime - startTime)+"ms"); 27 | request.setAttribute("handlingTime", endTime - startTime); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/service/DemoService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.service; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class DemoService { 7 | 8 | public String saySomething(){ 9 | return "hello"; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/service/PushService.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.service; 2 | 3 | import org.springframework.scheduling.annotation.Scheduled; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.context.request.async.DeferredResult; 6 | 7 | @Service 8 | public class PushService { 9 | private DeferredResult deferredResult; //1 10 | 11 | public DeferredResult getAsyncUpdate() { 12 | deferredResult = new DeferredResult(); 13 | return deferredResult; 14 | } 15 | 16 | @Scheduled(fixedDelay = 5000) 17 | public void refresh() { 18 | if (deferredResult != null) { 19 | deferredResult.setResult(new Long(System.currentTimeMillis()) 20 | .toString()); 21 | } 22 | } 23 | 24 | 25 | } -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller//1 7 | public class HelloController { 8 | 9 | // @RequestMapping("/index")//2 10 | // public String hello(){ 11 | // 12 | // return "index"; 13 | // } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_3/DemoRestController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_3; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import com.wisely.highlight_springmvc4.domain.DemoObj; 7 | 8 | @RestController //1 9 | @RequestMapping("/rest") 10 | public class DemoRestController { 11 | 12 | @RequestMapping(value = "/getjson", 13 | produces={"application/json;charset=UTF-8"}) //2 14 | public DemoObj getjson (DemoObj obj){ 15 | return new DemoObj(obj.getId()+1, obj.getName()+"yy");//3 16 | } 17 | @RequestMapping(value = "/getxml", 18 | produces={"application/xml;charset=UTF-8"})//4 19 | public DemoObj getxml(DemoObj obj){ 20 | return new DemoObj(obj.getId()+1, obj.getName()+"yy"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_4/AdviceController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_4; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.ModelAttribute; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | import com.wisely.highlight_springmvc4.domain.DemoObj; 8 | 9 | @Controller 10 | public class AdviceController { 11 | @RequestMapping("/advice") 12 | public String getSomething(@ModelAttribute("msg") String msg,DemoObj obj){//1 13 | 14 | throw new IllegalArgumentException("非常抱歉,参数有误/"+"来自@ModelAttribute:"+ msg); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_5/AysncController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_5; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | import org.springframework.web.context.request.async.DeferredResult; 8 | 9 | import com.wisely.highlight_springmvc4.service.PushService; 10 | 11 | @Controller 12 | public class AysncController { 13 | @Autowired 14 | PushService pushService; //1 15 | 16 | @RequestMapping("/defer") 17 | @ResponseBody 18 | public DeferredResult deferredCall() { //2 19 | return pushService.getAsyncUpdate(); 20 | } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_5/ContentController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_5; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | import com.wisely.highlight_springmvc4.domain.DemoObj; 8 | 9 | @Controller 10 | public class ContentController { 11 | @RequestMapping(value = "/getdemo") 12 | public String getDemo(Model model){ 13 | DemoObj demoObj = new DemoObj(333l, "WYF"); 14 | model.addAttribute("demoObj",demoObj); 15 | return "demoObj"; 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_5/ConverterController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_5; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestBody; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | 8 | import com.wisely.highlight_springmvc4.domain.DemoObj; 9 | 10 | @Controller 11 | public class ConverterController { 12 | 13 | @RequestMapping(value = "/convert", produces = { "application/x-wisely" }) //1 14 | public @ResponseBody DemoObj convert(@RequestBody DemoObj demoObj) { 15 | 16 | return demoObj; 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_5/SseController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_5; 2 | 3 | import java.util.Random; 4 | 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | 9 | @Controller 10 | public class SseController { 11 | 12 | @RequestMapping(value="/push",produces="text/event-stream") //1 13 | public @ResponseBody String push(){ 14 | Random r = new Random(); 15 | try { 16 | Thread.sleep(5000); 17 | } catch (InterruptedException e) { 18 | e.printStackTrace(); 19 | } 20 | return "data:Testing 1,2,3" + r.nextInt() +"\n\n"; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_5/UploadController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_5; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | import org.springframework.web.multipart.MultipartFile; 12 | 13 | @Controller 14 | public class UploadController { 15 | 16 | @RequestMapping(value = "/upload",method = RequestMethod.POST) 17 | public @ResponseBody String upload(MultipartFile file) {//1 18 | 19 | try { 20 | FileUtils.writeByteArrayToFile(new File("e:/upload/"+file.getOriginalFilename()), 21 | file.getBytes()); //2 22 | return "ok"; 23 | } catch (IOException e) { 24 | e.printStackTrace(); 25 | return "wrong"; 26 | } 27 | 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_6/MyRestController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_6; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.ResponseBody; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.wisely.highlight_springmvc4.service.DemoService; 9 | 10 | //@RestController 11 | public class MyRestController { 12 | 13 | @Autowired 14 | DemoService demoService; 15 | 16 | @RequestMapping(value = "/testRest" ,produces="text/plain;charset=UTF-8") 17 | public @ResponseBody String testRest(){ 18 | return demoService.saySomething(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/java/com/wisely/highlight_springmvc4/web/ch4_6/NormalController.java: -------------------------------------------------------------------------------- 1 | package com.wisely.highlight_springmvc4.web.ch4_6; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.ui.Model; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | import com.wisely.highlight_springmvc4.service.DemoService; 9 | 10 | //@Controller 11 | public class NormalController { 12 | @Autowired 13 | DemoService demoService; 14 | 15 | 16 | 17 | @RequestMapping("/normal") 18 | public String testPage(Model model){ 19 | model.addAttribute("msg", demoService.saySomething()); 20 | return "page"; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | logbak: %d{HH:mm:ss.SSS} %logger{36} - %msg%n 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/views/async.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | servlet async support 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 28 | 29 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/views/converter.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | HttpMessageConverter Demo 8 | 9 | 10 |
11 | 12 | 26 | 27 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/views/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page language="java" contentType="text/html; charset=UTF-8" 3 | pageEncoding="UTF-8"%> 4 | 5 | 6 | 7 | 8 | @ControllerAdvice Demo 9 | 10 | 11 | ${errorMessage} 12 | 13 | 14 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/views/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |
11 | 		Welcome to Spring MVC world
12 | 	
13 | 14 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/views/page.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Test page 8 | 9 | 10 |
11 | 		Welcome to Spring MVC world
12 | 	
13 | 14 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/views/sse.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 2 | <%@ page language="java" contentType="text/html; charset=UTF-8" 3 | pageEncoding="UTF-8"%> 4 | 5 | 6 | 7 | 8 | SSE Demo 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 43 | 44 | -------------------------------------------------------------------------------- /highlight_springmvc4/src/main/resources/views/upload.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | upload page 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | 17 |
18 |
19 | 20 | 21 | 22 | --------------------------------------------------------------------------------