├── .gitmodules ├── Chapter1 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── web │ │ │ └── HelloController.java │ │ │ └── Chapter1Application.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── Chapter1ApplicationTests.java └── pom.xml ├── Chapter3-1-1 ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ ├── web │ │ └── HelloController.java │ │ └── domain │ │ └── User.java └── pom.xml ├── Chapter3-1-2 └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── templates │ │ │ └── index.html │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter3-1-3 └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── templates │ │ │ └── index.ftl │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter3-1-4 └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── templates │ │ │ └── index.vm │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter3-1-5 └── src │ └── main │ ├── resources │ └── application.properties │ └── java │ └── com │ └── didispace │ ├── Application.java │ ├── web │ └── HelloController.java │ ├── domain │ └── User.java │ └── Swagger2.java ├── Chapter3-1-6 ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ ├── index.html │ │ │ │ └── error.html │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── exception │ │ │ ├── MyException.java │ │ │ └── GlobalExceptionHandler.java │ │ │ ├── Application.java │ │ │ ├── web │ │ │ └── HelloController.java │ │ │ └── dto │ │ │ └── ErrorInfo.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter4-1-1 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── task │ │ │ └── ScheduledTasks.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter4-1-2 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── async │ │ │ └── Task.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter4-2-2 ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── log4j.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── Application.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter4-2-4 └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── log4j.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter4-2-5 └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── log4j.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter4-3-1 └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── templates │ │ │ ├── index.html │ │ │ ├── hello.html │ │ │ └── login.html │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ ├── web │ │ └── HelloController.java │ │ └── WebSecurityConfig.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter9-1-4 ├── config-repo │ ├── didispace-dev.properties │ ├── didispace-prod.properties │ ├── didispace-test.properties │ └── didispace.properties ├── config-server │ └── src │ │ └── main │ │ ├── resources │ │ ├── didispace.properties │ │ ├── didispace-dev.properties │ │ ├── didispace-prod.properties │ │ ├── didispace-test.properties │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ └── Application.java └── config-client │ └── src │ └── main │ ├── resources │ └── bootstrap.properties │ └── java │ └── com │ └── didispace │ ├── Application.java │ └── web │ └── TestController.java ├── Chapter4-2-3 ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ ├── application-dev.properties │ │ │ ├── application-prod.properties │ │ │ ├── application-test.properties │ │ │ └── log4j.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── Application.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter2-1-1 ├── src │ ├── main │ │ ├── resources │ │ │ ├── application-dev.properties │ │ │ ├── application-prod.properties │ │ │ ├── application-test.properties │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── web │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter6-2-1 └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter4-2-6 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── DemoApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── DemoApplicationTests.java └── pom.xml ├── Chapter6-1-1 ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Events.java │ │ ├── States.java │ │ ├── Application.java │ │ └── EventConfig.java └── pom.xml ├── Chapter4-5-1 ├── weixin.jpg ├── src │ └── main │ │ ├── resources │ │ ├── templates │ │ │ └── template.vm │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ └── Application.java └── pom.xml ├── Chapter3-2-6 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── domain │ │ │ ├── UserRepository.java │ │ │ └── User.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter9-2-2 ├── consumer │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── dubbo.xml │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── Application.java │ │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── compute-service │ ├── compute-api-server │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── dubbo.xml │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── service │ │ │ └── impl │ │ │ │ └── ComputeServiceImpl.java │ │ │ └── Application.java │ │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java │ ├── compute-api │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── service │ │ │ ├── ComputeService.java │ │ │ └── impl │ │ │ └── ComputeServiceImpl.java │ └── pom.xml │ └── pom.xml ├── Chapter9-2-1 ├── compute-service │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── dubbo.xml │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── service │ │ │ ├── ComputeService.java │ │ │ └── impl │ │ │ │ └── ComputeServiceImpl.java │ │ │ └── Application.java │ │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── consumer │ └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── dubbo.xml │ └── java │ │ └── com │ │ └── didispace │ │ ├── service │ │ └── ComputeService.java │ │ └── Application.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter9-1-2 ├── eureka-feign │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── FeignApplication.java │ │ ├── service │ │ └── ComputeClient.java │ │ └── web │ │ └── ConsumerController.java └── eureka-ribbon │ └── src │ └── main │ ├── resources │ └── application.properties │ └── java │ └── com │ └── didispace │ ├── web │ └── ConsumerController.java │ └── RibbonApplication.java ├── Chapter9-1-5 ├── service-A │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── didispace │ │ │ │ ├── ComputeServiceApplication.java │ │ │ │ └── web │ │ │ │ └── ComputeController.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── ApplicationTests.java │ └── pom.xml ├── service-B │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── didispace │ │ │ │ ├── ComputeServiceApplication.java │ │ │ │ └── web │ │ │ │ └── ComputeController.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── ApplicationTests.java │ └── pom.xml ├── eureka-server │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ └── Application.java └── api-gateway │ ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── filter │ │ └── AccessFilter.java │ └── pom.xml ├── Chapter9-1-1 ├── compute-service │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── ComputeServiceApplication.java │ │ │ └── web │ │ │ └── ComputeController.java │ │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── eureka-server │ └── src │ └── main │ ├── resources │ └── application.properties │ └── java │ └── com │ └── didispace │ └── Application.java ├── Chapter9-1-3 ├── compute-service │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── ComputeServiceApplication.java │ │ │ └── web │ │ │ └── ComputeController.java │ │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java ├── eureka-server │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ └── Application.java ├── eureka-feign │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── service │ │ ├── ComputeClientHystrix.java │ │ └── ComputeClient.java │ │ ├── FeignApplication.java │ │ └── web │ │ └── ConsumerController.java └── eureka-ribbon │ └── src │ └── main │ └── java │ └── com │ └── didispace │ ├── service │ └── ComputeService.java │ ├── web │ └── ConsumerController.java │ └── RibbonApplication.java ├── Chapter3-2-1 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter3-2-7 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── domain │ │ │ ├── UserMapper.java │ │ │ └── User.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter3-2-8 ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── domain │ │ ├── User.java │ │ └── UserMapper.java └── pom.xml ├── Chapter5-2-1 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── HelloApplication.java │ │ │ └── rabbit │ │ │ ├── RabbitConfig.java │ │ │ ├── Sender.java │ │ │ └── Receiver.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── HelloApplicationTests.java └── pom.xml ├── Chapter3-2-2 ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── domain │ │ ├── UserRepository.java │ │ └── User.java └── pom.xml ├── Chapter3-3-1 ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ ├── service │ │ └── UserService.java │ │ └── domain │ │ ├── UserRepository.java │ │ └── User.java └── pom.xml ├── Chapter4-4-1 └── src │ ├── main │ ├── resources │ │ ├── ehcache.xml │ │ └── application.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── domain │ │ ├── UserRepository.java │ │ └── User.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter3-2-5 ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── didispace │ │ │ │ ├── Application.java │ │ │ │ ├── domain │ │ │ │ └── User.java │ │ │ │ ├── RedisConfig.java │ │ │ │ └── RedisObjectSerializer.java │ │ └── resources │ │ │ └── application.properties │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── Chapter3-2-4 └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── didispace │ │ │ ├── domain │ │ │ ├── s │ │ │ │ ├── MessageRepository.java │ │ │ │ └── Message.java │ │ │ └── p │ │ │ │ ├── UserRepository.java │ │ │ │ └── User.java │ │ │ ├── Application.java │ │ │ └── DataSourceConfig.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── Chapter3-2-3 ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── DataSourceConfig.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml └── Chapter4-4-2 └── src ├── main ├── resources │ └── application.properties └── java │ └── com │ └── didispace │ ├── Application.java │ └── domain │ ├── UserRepository.java │ └── User.java └── test └── java └── com └── didispace └── ApplicationTests.java /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter3-1-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter3-1-2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter3-1-3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter3-1-4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter3-1-5/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter4-1-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter4-1-2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter4-2-2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter4-2-4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter4-2-5/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter4-3-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter9-1-4/config-repo/didispace-dev.properties: -------------------------------------------------------------------------------- 1 | from=git-dev-1.0 -------------------------------------------------------------------------------- /Chapter9-1-4/config-repo/didispace-prod.properties: -------------------------------------------------------------------------------- 1 | from=git-prod-1.0 -------------------------------------------------------------------------------- /Chapter9-1-4/config-repo/didispace-test.properties: -------------------------------------------------------------------------------- 1 | from=git-test-1.0 -------------------------------------------------------------------------------- /Chapter9-1-4/config-repo/didispace.properties: -------------------------------------------------------------------------------- 1 | from=git-default-1.0 2 | -------------------------------------------------------------------------------- /Chapter9-1-4/config-server/src/main/resources/didispace.properties: -------------------------------------------------------------------------------- 1 | from=local -------------------------------------------------------------------------------- /Chapter4-2-3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=dev -------------------------------------------------------------------------------- /Chapter2-1-1/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | # 服务端口 2 | server.port=1111 -------------------------------------------------------------------------------- /Chapter2-1-1/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | # 服务端口 2 | server.port=3333 -------------------------------------------------------------------------------- /Chapter2-1-1/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | # 服务端口 2 | server.port=2222 -------------------------------------------------------------------------------- /Chapter6-2-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #management.info.git.mode=full -------------------------------------------------------------------------------- /Chapter9-1-4/config-server/src/main/resources/didispace-dev.properties: -------------------------------------------------------------------------------- 1 | from=local-dev -------------------------------------------------------------------------------- /Chapter9-1-4/config-server/src/main/resources/didispace-prod.properties: -------------------------------------------------------------------------------- 1 | from=local-prod -------------------------------------------------------------------------------- /Chapter9-1-4/config-server/src/main/resources/didispace-test.properties: -------------------------------------------------------------------------------- 1 | from=local-test -------------------------------------------------------------------------------- /Chapter4-2-3/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.didispace=INFO -------------------------------------------------------------------------------- /Chapter4-2-3/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.didispace=INFO -------------------------------------------------------------------------------- /Chapter4-2-3/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.didispace=DEBUG -------------------------------------------------------------------------------- /Chapter4-2-6/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | management.security.enabled=false 2 | -------------------------------------------------------------------------------- /Chapter6-1-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=statemachine 2 | 3 | -------------------------------------------------------------------------------- /Chapter4-5-1/weixin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/SpringBoot-Learning/HEAD/Chapter4-5-1/weixin.jpg -------------------------------------------------------------------------------- /Chapter3-2-6/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.mongodb.uri=mongodb://name:pass@localhost:27017/test 2 | 3 | 4 | -------------------------------------------------------------------------------- /Chapter4-5-1/src/main/resources/templates/template.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 |

你好, ${username}, 这是一封模板邮件!

4 | 5 | -------------------------------------------------------------------------------- /Chapter9-2-2/consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=localhost:2181 3 | 4 | 5 | logging.level.root=INFO -------------------------------------------------------------------------------- /Chapter9-2-1/compute-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=localhost:2181 3 | 4 | logging.level.root=DEBUG -------------------------------------------------------------------------------- /Chapter9-2-1/consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=localhost:2181 3 | 4 | 5 | logging.level.root=DEBUG -------------------------------------------------------------------------------- /Chapter6-1-1/src/main/java/com/didispace/Events.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | public enum Events { 4 | PAY, // 支付 5 | RECEIVE // 收货 6 | } -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=localhost:2181 3 | 4 | logging.level.root=DEBUG -------------------------------------------------------------------------------- /Chapter9-1-4/config-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SpringForAll/SpringBoot-Learning/HEAD/Chapter9-1-4/config-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter9-1-2/eureka-feign/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=feign-consumer 2 | server.port=3333 3 | 4 | eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ 5 | 6 | -------------------------------------------------------------------------------- /Chapter9-1-5/service-A/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=service-A 2 | 3 | server.port=2222 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ 6 | 7 | -------------------------------------------------------------------------------- /Chapter9-1-5/service-B/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=service-B 2 | 3 | server.port=3333 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ 6 | 7 | -------------------------------------------------------------------------------- /Chapter9-1-2/eureka-ribbon/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=ribbon-consumer 2 | server.port=3333 3 | 4 | eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ 5 | 6 | -------------------------------------------------------------------------------- /Chapter9-1-1/compute-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=compute-service 2 | 3 | server.port=2222 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ 6 | 7 | -------------------------------------------------------------------------------- /Chapter9-1-3/compute-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=compute-service 2 | 3 | server.port=2222 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ 6 | 7 | -------------------------------------------------------------------------------- /Chapter6-1-1/src/main/java/com/didispace/States.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | public enum States { 4 | UNPAID, // 待支付 5 | WAITING_FOR_RECEIVE, // 待收货 6 | DONE // 结束 7 | } 8 | -------------------------------------------------------------------------------- /Chapter3-1-4/src/main/resources/templates/index.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Velocity模板 9 |

${host}

10 | 11 | -------------------------------------------------------------------------------- /Chapter3-2-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/test 2 | spring.datasource.username=root 3 | spring.datasource.password=root 4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver -------------------------------------------------------------------------------- /Chapter3-2-7/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/test 2 | spring.datasource.username=root 3 | spring.datasource.password=123456 4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver -------------------------------------------------------------------------------- /Chapter3-2-8/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/test 2 | spring.datasource.username=root 3 | spring.datasource.password=123456 4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver -------------------------------------------------------------------------------- /Chapter5-2-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=rabbitmq-hello 2 | 3 | spring.rabbitmq.host=localhost 4 | spring.rabbitmq.port=5672 5 | spring.rabbitmq.username=springcloud 6 | spring.rabbitmq.password=123456 7 | -------------------------------------------------------------------------------- /Chapter3-1-3/src/main/resources/templates/index.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | FreeMarker模板引擎 9 |

${host}

10 | 11 | -------------------------------------------------------------------------------- /Chapter9-1-4/config-client/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=didispace 2 | spring.cloud.config.profile=dev 3 | spring.cloud.config.uri=http://localhost:7001/ 4 | 5 | server.port=7002 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter3-1-2/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Hello World

9 | 10 | -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Hello World

9 | 10 | -------------------------------------------------------------------------------- /Chapter9-2-1/consumer/src/main/java/com/didispace/service/ComputeService.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | /** 4 | * Created by zhaiyc on 2016/7/14. 5 | */ 6 | public interface ComputeService { 7 | 8 | Integer add(int a, int b); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Chapter9-2-1/compute-service/src/main/java/com/didispace/service/ComputeService.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | /** 4 | * Created by zhaiyc on 2016/7/14. 5 | */ 6 | public interface ComputeService { 7 | 8 | Integer add(int a, int b); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/ComputeService.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | /** 4 | * Created by zhaiyc on 2016/7/14. 5 | */ 6 | public interface ComputeService { 7 | 8 | Integer add(int a, int b); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Chapter9-1-1/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=1111 2 | #eureka.instance.hostname=localhost 3 | 4 | eureka.client.register-with-eureka=false 5 | eureka.client.fetch-registry=false 6 | eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/ -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=1111 2 | #eureka.instance.hostname=localhost 3 | 4 | eureka.client.register-with-eureka=false 5 | eureka.client.fetch-registry=false 6 | eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/ -------------------------------------------------------------------------------- /Chapter9-1-5/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=1111 2 | #eureka.instance.hostname=localhost 3 | 4 | eureka.client.register-with-eureka=false 5 | eureka.client.fetch-registry=false 6 | eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/ -------------------------------------------------------------------------------- /Chapter3-2-2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/test 2 | spring.datasource.username=root 3 | spring.datasource.password=root 4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 5 | 6 | spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop -------------------------------------------------------------------------------- /Chapter3-3-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/test 2 | spring.datasource.username=root 3 | spring.datasource.password=123456 4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 5 | 6 | spring.jpa.properties.hibernate.hbm2ddl.auto=create -------------------------------------------------------------------------------- /Chapter4-4-1/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Chapter4-5-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.mail.host=smtp.qq.com 2 | spring.mail.username=username@qq.com 3 | spring.mail.password=password 4 | spring.mail.properties.mail.smtp.auth=true 5 | spring.mail.properties.mail.smtp.starttls.enable=true 6 | spring.mail.properties.mail.smtp.starttls.required=true -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 统一异常处理 6 | 7 | 8 |

Error Handler

9 |
10 |
11 | 12 | -------------------------------------------------------------------------------- /Chapter4-4-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/test 2 | spring.datasource.username=root 3 | spring.datasource.password=123456 4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 5 | 6 | spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop 7 | spring.jpa.properties.hibernate.show_sql=true -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/java/com/didispace/exception/MyException.java: -------------------------------------------------------------------------------- 1 | package com.didispace.exception; 2 | 3 | /** 4 | * @author 程序猿DD 5 | * @version 1.0.0 6 | * @date 16/5/2 上午10:50. 7 | * @blog http://blog.didispace.com 8 | */ 9 | public class MyException extends Exception { 10 | 11 | public MyException(String message) { 12 | super(message); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter3-2-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter3-2-2/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter3-2-5/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter3-2-6/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter3-2-7/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter3-2-8/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter3-3-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter4-2-4/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter4-2-5/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter4-5-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter1/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class HelloController { 8 | 9 | @RequestMapping("/hello") 10 | public String index() { 11 | return "Hello World"; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Chapter3-2-4/src/main/java/com/didispace/domain/s/MessageRepository.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain.s; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | 6 | /** 7 | * @author 程序猿DD 8 | * @version 1.0.0 9 | * @date 16/3/23 下午2:34. 10 | * @blog http://blog.didispace.com 11 | */ 12 | public interface MessageRepository extends JpaRepository { 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter4-3-1/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | Spring Security入门 6 | 7 | 8 |

欢迎使用Spring Security!

9 | 10 |

点击 这里 打个招呼吧

11 | 12 | -------------------------------------------------------------------------------- /Chapter5-2-1/src/main/java/com/didispace/HelloApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HelloApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HelloApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter1/src/main/java/com/didispace/Chapter1Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Chapter1Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Chapter1Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter9-2-1/compute-service/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service.impl; 2 | 3 | import com.didispace.service.ComputeService; 4 | 5 | /** 6 | * Created by zhaiyc on 2016/7/14. 7 | */ 8 | public class ComputeServiceImpl implements ComputeService { 9 | 10 | @Override 11 | public Integer add(int a, int b) { 12 | return a + b; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service.impl; 2 | 3 | import com.didispace.service.ComputeService; 4 | 5 | /** 6 | * Created by zhaiyc on 2016/7/14. 7 | */ 8 | public class ComputeServiceImpl implements ComputeService { 9 | 10 | @Override 11 | public Integer add(int a, int b) { 12 | return a + b; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter3-2-6/src/main/java/com/didispace/domain/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.springframework.data.mongodb.repository.MongoRepository; 4 | 5 | /** 6 | * @author 程序猿DD 7 | * @version 1.0.0 8 | * @date 16/4/27 下午10:16. 9 | * @blog http://blog.didispace.com 10 | */ 11 | public interface UserRepository extends MongoRepository { 12 | 13 | User findByUsername(String username); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/service/impl/ComputeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service.impl; 2 | 3 | import com.didispace.service.ComputeService; 4 | 5 | /** 6 | * Created by zhaiyc on 2016/7/14. 7 | */ 8 | public class ComputeServiceImpl implements ComputeService { 9 | 10 | @Override 11 | public Integer add(int a, int b) { 12 | return a + b; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-1-4/config-client/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | new SpringApplicationBuilder(Application.class).web(true).run(args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter6-2-1/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.junit.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | 7 | /** 8 | * 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @blog http://blog.didispace.com 12 | * 13 | */ 14 | @SpringBootTest 15 | public class ApplicationTests { 16 | 17 | @Test 18 | public void test1() throws Exception { 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter4-2-6/src/test/java/com/didispace/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter3-2-7/src/main/java/com/didispace/domain/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | 5 | @Mapper 6 | public interface UserMapper { 7 | 8 | @Select("SELECT * FROM USER WHERE NAME = #{name}") 9 | User findByName(@Param("name") String name); 10 | 11 | @Insert("INSERT INTO USER(NAME, AGE) VALUES(#{name}, #{age})") 12 | int insert(@Param("name") String name, @Param("age") Integer age); 13 | 14 | } -------------------------------------------------------------------------------- /Chapter4-1-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | @SpringBootApplication 8 | @EnableScheduling 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter4-3-1/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | Hello World! 6 | 7 | 8 |

Hello [[${#httpServletRequest.remoteUser}]]!

9 |
10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClientHystrix.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.web.bind.annotation.RequestParam; 5 | 6 | @Component 7 | public class ComputeClientHystrix implements ComputeClient { 8 | 9 | @Override 10 | public Integer add(@RequestParam(value = "a") Integer a, @RequestParam(value = "b") Integer b) { 11 | return -9999; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Chapter3-2-3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1 2 | spring.datasource.primary.username=root 3 | spring.datasource.primary.password=root 4 | spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver 5 | 6 | spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2 7 | spring.datasource.secondary.username=root 8 | spring.datasource.secondary.password=root 9 | spring.datasource.secondary.driver-class-name=com.mysql.jdbc.Driver 10 | -------------------------------------------------------------------------------- /Chapter9-1-5/api-gateway/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=api-gateway 2 | server.port=5555 3 | 4 | # routes to serviceId 5 | zuul.routes.api-a.path=/api-a/** 6 | zuul.routes.api-a.serviceId=service-A 7 | 8 | zuul.routes.api-b.path=/api-b/** 9 | zuul.routes.api-b.serviceId=service-B 10 | 11 | # routes to url 12 | zuul.routes.api-a-url.path=/api-a-url/** 13 | zuul.routes.api-a-url.url=http://localhost:2222/ 14 | 15 | eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ -------------------------------------------------------------------------------- /Chapter3-2-4/src/main/java/com/didispace/domain/p/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain.p; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.data.repository.query.Param; 6 | 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/23 下午2:34. 12 | * @blog http://blog.didispace.com 13 | */ 14 | public interface UserRepository extends JpaRepository { 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter2-1-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter3-1-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter3-1-2/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter3-1-3/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter3-1-4/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter3-1-5/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter4-3-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter6-2-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication.run(Application.class, args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter2-1-1/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @RestController 14 | public class HelloController { 15 | 16 | @RequestMapping("/hello") 17 | public String index() { 18 | return "Hello World"; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Chapter3-1-1/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @RestController 14 | public class HelloController { 15 | 16 | @RequestMapping("/hello") 17 | public String index() { 18 | return "Hello World"; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Chapter6-2-1/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @blog http://blog.didispace.com 11 | * 12 | */ 13 | @RestController 14 | public class HelloController { 15 | 16 | @RequestMapping("/hello") 17 | public String index() { 18 | return "Hello World"; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Chapter4-1-1/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 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 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = Application.class) 11 | public class ApplicationTests { 12 | 13 | 14 | @Test 15 | public void getHello() throws Exception { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Chapter5-2-1/src/main/java/com/didispace/rabbit/RabbitConfig.java: -------------------------------------------------------------------------------- 1 | package com.didispace.rabbit; 2 | 3 | import org.springframework.amqp.core.Queue; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author 翟永超 9 | * @create 2016/9/25. 10 | * @blog http://blog.didispace.com 11 | */ 12 | @Configuration 13 | public class RabbitConfig { 14 | 15 | @Bean 16 | public Queue helloQueue() { 17 | return new Queue("hello"); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter9-1-4/config-server/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @EnableConfigServer 8 | @SpringBootApplication 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(Application.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-2-2/consumer/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ImportResource; 6 | 7 | @SpringBootApplication 8 | @ImportResource({"classpath:dubbo.xml"}) 9 | public class Application { 10 | 11 | public static void main(String[] args) throws InterruptedException { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-1-1/eureka-server/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(Application.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-server/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(Application.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-1-5/eureka-server/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(Application.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter4-1-2/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | import org.springframework.scheduling.annotation.EnableScheduling; 7 | 8 | @SpringBootApplication 9 | @EnableAsync 10 | public class Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter4-2-4/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author 程序猿DD 7 | * @version 1.0.0 8 | * @date 16/5/19 下午1:27. 9 | * @blog http://blog.didispace.com 10 | */ 11 | @RestController 12 | public class HelloController { 13 | 14 | @RequestMapping(value = "/hello", method = RequestMethod.GET) 15 | @ResponseBody 16 | public String hello(@RequestParam String name) { 17 | return "Hello " + name; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter4-2-5/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author 程序猿DD 7 | * @version 1.0.0 8 | * @date 16/5/19 下午1:27. 9 | * @blog http://blog.didispace.com 10 | */ 11 | @RestController 12 | public class HelloController { 13 | 14 | @RequestMapping(value = "/hello", method = RequestMethod.GET) 15 | @ResponseBody 16 | public String hello(@RequestParam String name) { 17 | return "Hello " + name; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter3-2-5/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # REDIS (RedisProperties) 2 | # Redis数据库索引(默认为0) 3 | spring.redis.database=0 4 | # Redis服务器地址 5 | spring.redis.host=localhost 6 | # Redis服务器连接端口 7 | spring.redis.port=6379 8 | # Redis服务器连接密码(默认为空) 9 | spring.redis.password= 10 | # 连接池最大连接数(使用负值表示没有限制) 11 | spring.redis.pool.max-active=8 12 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 13 | spring.redis.pool.max-wait=-1 14 | # 连接池中的最大空闲连接 15 | spring.redis.pool.max-idle=8 16 | # 连接池中的最小空闲连接 17 | spring.redis.pool.min-idle=0 18 | # 连接超时时间(毫秒) 19 | spring.redis.timeout=0 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter4-4-2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/test 2 | spring.datasource.username=root 3 | spring.datasource.password=123456 4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 5 | 6 | spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop 7 | spring.jpa.properties.hibernate.show_sql=true 8 | 9 | spring.redis.host=localhost 10 | spring.redis.port=6379 11 | spring.redis.pool.max-idle=8 12 | spring.redis.pool.min-idle=0 13 | spring.redis.pool.max-active=8 14 | spring.redis.pool.max-wait=-1 15 | 16 | -------------------------------------------------------------------------------- /Chapter2-1-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | com.didispace.blog.name=程序猿DD 2 | com.didispace.blog.title=Spring Boot教程 3 | com.didispace.blog.desc=${com.didispace.blog.name}正在努力写《${com.didispace.blog.title}》 4 | 5 | # 随机字符串 6 | com.didispace.blog.value=${random.value} 7 | # 随机int 8 | com.didispace.blog.number=${random.int} 9 | # 随机long 10 | com.didispace.blog.bignumber=${random.long} 11 | # 10以内的随机数 12 | com.didispace.blog.test1=${random.int(10)} 13 | # 10-20的随机数 14 | com.didispace.blog.test2=${random.int[10,20]} 15 | 16 | # 多环境配置文件激活属性 17 | spring.profiles.active=dev -------------------------------------------------------------------------------- /Chapter4-2-2/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.scheduling.annotation.EnableAsync; 7 | import org.springframework.scheduling.annotation.EnableScheduling; 8 | 9 | @SpringBootApplication 10 | public class Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter4-2-3/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.scheduling.annotation.EnableAsync; 7 | import org.springframework.scheduling.annotation.EnableScheduling; 8 | 9 | @SpringBootApplication 10 | public class Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter3-2-4/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.primary.url=jdbc:mysql://localhost:3306/test1 2 | spring.datasource.primary.username=root 3 | spring.datasource.primary.password=52261340 4 | spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver 5 | 6 | spring.datasource.secondary.url=jdbc:mysql://localhost:3306/test2 7 | spring.datasource.secondary.username=root 8 | spring.datasource.secondary.password=52261340 9 | spring.datasource.secondary.driver-class-name=com.mysql.jdbc.Driver 10 | 11 | spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop -------------------------------------------------------------------------------- /Chapter9-1-5/service-A/src/main/java/com/didispace/ComputeServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ComputeServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(ComputeServiceApplication.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-1-5/service-B/src/main/java/com/didispace/ComputeServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ComputeServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(ComputeServiceApplication.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-1-1/compute-service/src/main/java/com/didispace/ComputeServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ComputeServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(ComputeServiceApplication.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter9-1-3/compute-service/src/main/java/com/didispace/ComputeServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class ComputeServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | new SpringApplicationBuilder(ComputeServiceApplication.class).web(true).run(args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter3-3-1/src/main/java/com/didispace/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | import com.didispace.domain.User; 4 | import org.springframework.transaction.annotation.Propagation; 5 | import org.springframework.transaction.annotation.Isolation; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | 9 | /** 10 | * Created by Administrator on 2016/5/27. 11 | */ 12 | public interface UserService { 13 | 14 | @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED) 15 | User login(String name, String password); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter4-2-5/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # LOG4J配置 2 | log4j.rootCategory=INFO, stdout 3 | log4j.logger.mongodb=INFO, mongodb 4 | 5 | # 控制台输出 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 9 | 10 | # mongodb输出 11 | log4j.appender.mongodb=com.didispace.log.MongoAppender 12 | log4j.appender.mongodb.connectionUrl=mongodb://localhost:27017 13 | log4j.appender.mongodb.databaseName=logs 14 | log4j.appender.mongodb.collectionName=logs_request 15 | -------------------------------------------------------------------------------- /Chapter4-4-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cache.annotation.EnableCaching; 6 | 7 | /** 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @date 16/3/23 下午2:34. 11 | * @blog http://blog.didispace.com 12 | */ 13 | @SpringBootApplication 14 | @EnableCaching 15 | public class Application { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter4-4-2/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cache.annotation.EnableCaching; 6 | 7 | /** 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @date 16/3/23 下午2:34. 11 | * @blog http://blog.didispace.com 12 | */ 13 | @SpringBootApplication 14 | @EnableCaching 15 | public class Application { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Chapter4-1-1/src/main/java/com/didispace/task/ScheduledTasks.java: -------------------------------------------------------------------------------- 1 | package com.didispace.task; 2 | 3 | import org.springframework.scheduling.annotation.Scheduled; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.text.SimpleDateFormat; 7 | import java.util.Date; 8 | 9 | @Component 10 | public class ScheduledTasks { 11 | 12 | private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); 13 | 14 | @Scheduled(fixedRate = 5000) 15 | public void reportCurrentTime() { 16 | System.out.println("当前时间:" + dateFormat.format(new Date())); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter9-1-2/eureka-feign/src/main/java/com/didispace/FeignApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableFeignClients 11 | public class FeignApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(FeignApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-feign/src/main/java/com/didispace/FeignApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableFeignClients 11 | public class FeignApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(FeignApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter9-1-2/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | @FeignClient("compute-service") 9 | public interface ComputeClient { 10 | 11 | @RequestMapping(method = RequestMethod.GET, value = "/add") 12 | Integer add(@RequestParam(value = "a") Integer a, @RequestParam(value = "b") Integer b); 13 | 14 | } -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 4.0.0 6 | 7 | 8 | com.didispace 9 | compute-service 10 | 1.0-SNAPSHOT 11 | 12 | 13 | compute-api 14 | compute-api 15 | jar 16 | 17 | -------------------------------------------------------------------------------- /Chapter4-2-5/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = Application.class) 12 | public class ApplicationTests { 13 | 14 | @Before 15 | public void setUp() throws Exception { 16 | 17 | 18 | } 19 | 20 | @Test 21 | public void getHello() throws Exception { 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Chapter9-2-1/compute-service/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = Application.class) 12 | public class ApplicationTests { 13 | 14 | @Before 15 | public void setUp() throws Exception { 16 | } 17 | 18 | @Test 19 | public void getHello() throws Exception { 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-feign/src/main/java/com/didispace/service/ComputeClient.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | @FeignClient(value = "compute-service", fallback = ComputeClientHystrix.class) 9 | public interface ComputeClient { 10 | 11 | @RequestMapping(method = RequestMethod.GET, value = "/add") 12 | Integer add(@RequestParam(value = "a") Integer a, @RequestParam(value = "b") Integer b); 13 | 14 | } -------------------------------------------------------------------------------- /Chapter5-2-1/src/main/java/com/didispace/rabbit/Sender.java: -------------------------------------------------------------------------------- 1 | package com.didispace.rabbit; 2 | 3 | import org.springframework.amqp.core.AmqpTemplate; 4 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Date; 9 | 10 | @Component 11 | public class Sender { 12 | 13 | @Autowired 14 | private AmqpTemplate rabbitTemplate; 15 | 16 | public void send() { 17 | String context = "hello " + new Date(); 18 | System.out.println("Sender : " + context); 19 | this.rabbitTemplate.convertAndSend("hello", context); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api-server/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = Application.class) 12 | public class ApplicationTests { 13 | 14 | @Before 15 | public void setUp() throws Exception { 16 | } 17 | 18 | @Test 19 | public void getHello() throws Exception { 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter3-2-7/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | public class User { 4 | 5 | private Long id; 6 | private String name; 7 | private Integer age; 8 | 9 | public Long getId() { 10 | return id; 11 | } 12 | 13 | public void setId(Long id) { 14 | this.id = id; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | 25 | public Integer getAge() { 26 | return age; 27 | } 28 | 29 | public void setAge(Integer age) { 30 | this.age = age; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Chapter3-1-5/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RequestMethod; 5 | import org.springframework.web.bind.annotation.RestController; 6 | import springfox.documentation.annotations.ApiIgnore; 7 | 8 | /** 9 | * 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @blog http://blog.didispace.com 13 | * 14 | */ 15 | @RestController 16 | public class HelloController { 17 | 18 | @ApiIgnore 19 | @RequestMapping(value = "/hello", method = RequestMethod.GET) 20 | public String index() { 21 | return "Hello World"; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter3-2-1/src/main/java/com/didispace/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | /** 4 | * @author 程序猿DD 5 | * @version 1.0.0 6 | * @date 16/3/17 下午7:04. 7 | * @blog http://blog.didispace.com 8 | */ 9 | public interface UserService { 10 | 11 | /** 12 | * 新增一个用户 13 | * @param name 14 | * @param age 15 | */ 16 | void create(String name, Integer age); 17 | 18 | /** 19 | * 根据name删除一个用户高 20 | * @param name 21 | */ 22 | void deleteByName(String name); 23 | 24 | /** 25 | * 获取用户总量 26 | */ 27 | Integer getAllUsers(); 28 | 29 | /** 30 | * 删除所有用户 31 | */ 32 | void deleteAllUsers(); 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Chapter5-2-1/src/main/java/com/didispace/rabbit/Receiver.java: -------------------------------------------------------------------------------- 1 | package com.didispace.rabbit; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.cache.annotation.Cacheable; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * @author 翟永超 12 | * @create 2016/9/25. 13 | * @blog http://blog.didispace.com 14 | */ 15 | @Component 16 | @RabbitListener(queues = "hello") 17 | public class Receiver { 18 | 19 | @RabbitHandler 20 | public void process(String hello) { 21 | System.out.println("Receiver : " + hello); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter9-1-2/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import com.didispace.service.ComputeClient; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class ConsumerController { 11 | 12 | @Autowired 13 | ComputeClient computeClient; 14 | 15 | @RequestMapping(value = "/add", method = RequestMethod.GET) 16 | public Integer add() { 17 | return computeClient.add(10, 20); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-feign/src/main/java/com/didispace/web/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import com.didispace.service.ComputeClient; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public class ConsumerController { 11 | 12 | @Autowired 13 | ComputeClient computeClient; 14 | 15 | @RequestMapping(value = "/add", method = RequestMethod.GET) 16 | public Integer add() { 17 | return computeClient.add(10, 20); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Chapter3-2-2/src/main/java/com/didispace/domain/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.data.repository.query.Param; 6 | 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/23 下午2:34. 12 | * @blog http://blog.didispace.com 13 | */ 14 | public interface UserRepository extends JpaRepository { 15 | 16 | User findByName(String name); 17 | 18 | User findByNameAndAge(String name, Integer age); 19 | 20 | @Query("from User u where u.name=:name") 21 | User findUser(@Param("name") String name); 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter3-3-1/src/main/java/com/didispace/domain/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.data.repository.query.Param; 6 | 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/23 下午2:34. 12 | * @blog http://blog.didispace.com 13 | */ 14 | public interface UserRepository extends JpaRepository { 15 | 16 | User findByName(String name); 17 | 18 | User findByNameAndAge(String name, Integer age); 19 | 20 | @Query("from User u where u.name=:name") 21 | User findUser(@Param("name") String name); 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter5-2-1/src/test/java/com/didispace/HelloApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.rabbit.Sender; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = HelloApplication.class) 12 | public class HelloApplicationTests { 13 | 14 | @Autowired 15 | private Sender sender; 16 | 17 | @Test 18 | public void hello() throws Exception { 19 | sender.send(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter4-2-2/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = Application.class) 12 | public class ApplicationTests { 13 | 14 | private Logger logger = Logger.getLogger(getClass()); 15 | 16 | @Test 17 | public void test() throws Exception { 18 | logger.info("输出info"); 19 | logger.debug("输出debug"); 20 | logger.error("输出error"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter4-2-3/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = Application.class) 12 | public class ApplicationTests { 13 | 14 | private Logger logger = Logger.getLogger(getClass()); 15 | 16 | @Test 17 | public void test() throws Exception { 18 | logger.info("输出info"); 19 | logger.debug("输出debug"); 20 | logger.error("输出error"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter4-2-4/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | 10 | @RunWith(SpringJUnit4ClassRunner.class) 11 | @SpringApplicationConfiguration(classes = Application.class) 12 | public class ApplicationTests { 13 | 14 | private Logger logger = Logger.getLogger(getClass()); 15 | 16 | @Test 17 | public void test() throws Exception { 18 | logger.info("输出info"); 19 | logger.debug("输出debug"); 20 | logger.error("输出error"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter9-1-5/api-gateway/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.filter.AccessFilter; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.SpringCloudApplication; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | @EnableZuulProxy 10 | @SpringCloudApplication 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | new SpringApplicationBuilder(Application.class).web(true).run(args); 15 | } 16 | 17 | @Bean 18 | public AccessFilter accessFilter() { 19 | return new AccessFilter(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter4-3-1/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Spring Security Example 7 | 8 | 9 |
10 | 用户名或密码错 11 |
12 |
13 | 您已注销成功 14 |
15 |
16 |
17 |
18 |
19 |
20 | 21 | -------------------------------------------------------------------------------- /Chapter9-2-1/consumer/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.ImportResource; 9 | 10 | import java.util.concurrent.CountDownLatch; 11 | 12 | @SpringBootApplication 13 | @ImportResource({"classpath:dubbo.xml"}) 14 | public class Application { 15 | 16 | public static void main(String[] args) throws InterruptedException { 17 | SpringApplication.run(Application.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter4-4-2/src/main/java/com/didispace/domain/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.springframework.cache.annotation.CacheConfig; 4 | import org.springframework.cache.annotation.CachePut; 5 | import org.springframework.cache.annotation.Cacheable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | 8 | 9 | /** 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @date 16/3/23 下午2:34. 13 | * @blog http://blog.didispace.com 14 | */ 15 | @CacheConfig(cacheNames = "users") 16 | public interface UserRepository extends JpaRepository { 17 | 18 | @Cacheable(key = "#p0") 19 | User findByName(String name); 20 | 21 | @CachePut(key = "#p0.name") 22 | User save(User user); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter3-2-3/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Primary; 9 | import org.springframework.jdbc.core.JdbcTemplate; 10 | 11 | import javax.sql.DataSource; 12 | 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(Application.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter3-2-4/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Primary; 9 | import org.springframework.jdbc.core.JdbcTemplate; 10 | 11 | import javax.sql.DataSource; 12 | 13 | @SpringBootApplication 14 | public class Application { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(Application.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter4-4-1/src/main/java/com/didispace/domain/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.springframework.cache.annotation.CacheConfig; 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.data.jpa.repository.JpaRepository; 8 | 9 | 10 | /** 11 | * @author 程序猿DD 12 | * @version 1.0.0 13 | * @date 16/3/23 下午2:34. 14 | * @blog http://blog.didispace.com 15 | */ 16 | @CacheConfig(cacheNames = "users") 17 | public interface UserRepository extends JpaRepository { 18 | 19 | @Cacheable(key = "#p0", condition = "#p0.length() < 10") 20 | User findByName(String name); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/web/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.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.RequestMethod; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | @RestController 10 | public class ConsumerController { 11 | 12 | @Autowired 13 | RestTemplate restTemplate; 14 | 15 | @RequestMapping(value = "/add", method = RequestMethod.GET) 16 | public String add() { 17 | return restTemplate.getForEntity("http://COMPUTE-SERVICE/add?a=10&b=20", String.class).getBody(); 18 | } 19 | 20 | 21 | } -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-ribbon/src/main/java/com/didispace/service/ComputeService.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | @Service 9 | public class ComputeService { 10 | 11 | @Autowired 12 | RestTemplate restTemplate; 13 | 14 | @HystrixCommand(fallbackMethod = "addServiceFallback") 15 | public String addService() { 16 | return restTemplate.getForEntity("http://COMPUTE-SERVICE/add?a=10&b=20", String.class).getBody(); 17 | } 18 | 19 | public String addServiceFallback() { 20 | return "error"; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter9-1-4/config-client/src/main/java/com/didispace/web/TestController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RefreshScope 9 | @RestController 10 | class TestController { 11 | 12 | @Value("${from}") 13 | private String from; 14 | 15 | @RequestMapping("/from") 16 | public String from() { 17 | 18 | return this.from; 19 | } 20 | 21 | public void setFrom(String from) { 22 | this.from = from; 23 | } 24 | 25 | public String getFrom() { 26 | return from; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /Chapter3-1-1/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | 4 | 5 | /** 6 | * 7 | * @author 程序猿DD 8 | * @version 1.0.0 9 | * @blog http://blog.didispace.com 10 | * 11 | */ 12 | public class User { 13 | 14 | private Long id; 15 | private String name; 16 | private Integer age; 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Long id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public Integer getAge() { 35 | return age; 36 | } 37 | 38 | public void setAge(Integer age) { 39 | this.age = age; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Chapter3-1-5/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | 4 | 5 | /** 6 | * 7 | * @author 程序猿DD 8 | * @version 1.0.0 9 | * @blog http://blog.didispace.com 10 | * 11 | */ 12 | public class User { 13 | 14 | private Long id; 15 | private String name; 16 | private Integer age; 17 | 18 | public Long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(Long id) { 23 | this.id = id; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public Integer getAge() { 35 | return age; 36 | } 37 | 38 | public void setAge(Integer age) { 39 | this.age = age; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Chapter9-1-2/eureka-ribbon/src/main/java/com/didispace/RibbonApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | public class RibbonApplication { 13 | 14 | @Bean 15 | @LoadBalanced 16 | RestTemplate restTemplate() { 17 | return new RestTemplate(); 18 | } 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(RibbonApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter9-2-1/consumer/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.service.ComputeService; 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.boot.test.SpringApplicationConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @SpringApplicationConfiguration(classes = Application.class) 14 | public class ApplicationTests { 15 | 16 | @Autowired 17 | ComputeService computeService; 18 | 19 | @Test 20 | public void testAdd() throws Exception { 21 | Assert.assertEquals("compute-service:add", new Integer(3), computeService.add(1, 2)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter9-2-2/consumer/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.service.ComputeService; 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.boot.test.SpringApplicationConfiguration; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @SpringApplicationConfiguration(classes = Application.class) 14 | public class ApplicationTests { 15 | 16 | @Autowired 17 | private ComputeService computeService; 18 | 19 | @Test 20 | public void testAdd() throws Exception { 21 | Assert.assertEquals("compute-service:add", new Integer(3), computeService.add(1, 2)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter3-1-3/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.ModelMap; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @blog http://blog.didispace.com 13 | * 14 | */ 15 | @Controller 16 | public class HelloController { 17 | 18 | @RequestMapping("/hello") 19 | @ResponseBody 20 | public String hello() { 21 | return "Hello World"; 22 | } 23 | 24 | @RequestMapping("/") 25 | public String index(ModelMap map) { 26 | map.addAttribute("host", "http://blog.didispace.com"); 27 | return "index"; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Chapter3-1-4/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.ModelMap; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @blog http://blog.didispace.com 13 | * 14 | */ 15 | @Controller 16 | public class HelloController { 17 | 18 | @RequestMapping("/hello") 19 | @ResponseBody 20 | public String hello() { 21 | return "Hello World"; 22 | } 23 | 24 | @RequestMapping("/") 25 | public String index(ModelMap map) { 26 | map.addAttribute("host", "http://blog.didispace.com"); 27 | return "index"; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Chapter3-1-2/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.ModelMap; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @blog http://blog.didispace.com 13 | * 14 | */ 15 | @Controller 16 | public class HelloController { 17 | 18 | @ResponseBody 19 | @RequestMapping("/hello") 20 | public String hello() { 21 | return "Hello World"; 22 | } 23 | 24 | @RequestMapping("/") 25 | public String index(ModelMap map) { 26 | map.addAttribute("host", "http://blog.didispace.com"); 27 | return "index"; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Chapter4-3-1/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.ModelMap; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | 8 | /** 9 | * 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @blog http://blog.didispace.com 13 | * 14 | */ 15 | @Controller 16 | public class HelloController { 17 | 18 | @RequestMapping("/") 19 | public String index() { 20 | return "index"; 21 | } 22 | 23 | @RequestMapping("/hello") 24 | public String hello() { 25 | return "hello"; 26 | } 27 | 28 | @RequestMapping(value = "/login", method = RequestMethod.GET) 29 | public String login() { 30 | return "login"; 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /Chapter6-1-1/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 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.statemachine.StateMachine; 8 | 9 | @SpringBootApplication 10 | public class Application implements CommandLineRunner { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | 16 | @Autowired 17 | private StateMachine stateMachine; 18 | 19 | @Override 20 | public void run(String... args) throws Exception { 21 | stateMachine.start(); 22 | stateMachine.sendEvent(Events.PAY); 23 | stateMachine.sendEvent(Events.RECEIVE); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-ribbon/src/main/java/com/didispace/web/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import com.didispace.service.ComputeService; 4 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | import java.util.Map; 12 | 13 | @RestController 14 | public class ConsumerController { 15 | 16 | @Autowired 17 | private ComputeService computeService; 18 | 19 | @RequestMapping(value = "/add", method = RequestMethod.GET) 20 | public String add() { 21 | return computeService.addService(); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Chapter3-2-5/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author 程序猿DD 7 | * @version 1.0.0 8 | * @date 16/4/15 下午1:58. 9 | * @blog http://blog.didispace.com 10 | */ 11 | public class User implements Serializable { 12 | 13 | private static final long serialVersionUID = -1L; 14 | 15 | private String username; 16 | private Integer age; 17 | 18 | public User(String username, Integer age) { 19 | this.username = username; 20 | this.age = age; 21 | } 22 | 23 | public String getUsername() { 24 | return username; 25 | } 26 | 27 | public void setUsername(String username) { 28 | this.username = username; 29 | } 30 | 31 | public Integer getAge() { 32 | return age; 33 | } 34 | 35 | public void setAge(Integer age) { 36 | this.age = age; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Chapter9-1-3/eureka-ribbon/src/main/java/com/didispace/RibbonApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 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.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | @SpringBootApplication 12 | @EnableDiscoveryClient 13 | @EnableCircuitBreaker 14 | public class RibbonApplication { 15 | 16 | @Bean 17 | @LoadBalanced 18 | RestTemplate restTemplate() { 19 | return new RestTemplate(); 20 | } 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(RibbonApplication.class, args); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 4.0.0 6 | 7 | com.didispace 8 | compute-service 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | 13 | compute-api 14 | compute-api-server 15 | 16 | 17 | 18 | true 19 | UTF-8 20 | 1.7 21 | 1.7 22 | 1.7 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter9-2-1/consumer/src/main/resources/dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter9-2-2/consumer/src/main/resources/dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter3-2-8/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | public class User { 4 | 5 | private Long id; 6 | private String name; 7 | private Integer age; 8 | 9 | public User() { 10 | } 11 | 12 | public User(Long id, String name, Integer age) { 13 | this.id = id; 14 | this.name = name; 15 | this.age = age; 16 | } 17 | 18 | public User(String name, Integer age) { 19 | this.name = name; 20 | this.age = age; 21 | } 22 | 23 | public Long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Long id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public Integer getAge() { 40 | return age; 41 | } 42 | 43 | public void setAge(Integer age) { 44 | this.age = age; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Chapter4-2-6/src/main/java/com/didispace/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 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 | @RestController 12 | @SpringBootApplication 13 | public class DemoApplication { 14 | 15 | private Logger logger = LoggerFactory.getLogger(getClass()); 16 | 17 | @RequestMapping(value = "/test", method = RequestMethod.GET) 18 | public String testLogLevel() { 19 | logger.debug("Logger Level :DEBUG"); 20 | logger.info("Logger Level :INFO"); 21 | logger.error("Logger Level :ERROR"); 22 | return ""; 23 | } 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(DemoApplication.class, args); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import com.didispace.exception.MyException; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.ui.ModelMap; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * 11 | * @author 程序猿DD 12 | * @version 1.0.0 13 | * @blog http://blog.didispace.com 14 | * 15 | */ 16 | @Controller 17 | public class HelloController { 18 | 19 | @RequestMapping("/hello") 20 | public String hello() throws Exception { 21 | throw new Exception("发生错误"); 22 | } 23 | 24 | @RequestMapping("/json") 25 | public String json() throws MyException { 26 | throw new MyException("发生错误2"); 27 | } 28 | 29 | @RequestMapping("/") 30 | public String index(ModelMap map) { 31 | map.addAttribute("host", "http://blog.didispace.com"); 32 | return "index"; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /Chapter3-2-7/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.domain.User; 4 | import com.didispace.domain.UserMapper; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.test.annotation.Rollback; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @SpringApplicationConfiguration(classes = Application.class) 17 | @Transactional 18 | public class ApplicationTests { 19 | 20 | @Autowired 21 | private UserMapper userMapper; 22 | 23 | @Test 24 | @Rollback 25 | public void findByName() throws Exception { 26 | userMapper.insert("AAA", 20); 27 | User u = userMapper.findByName("AAA"); 28 | Assert.assertEquals(20, u.getAge().intValue()); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /Chapter3-2-6/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | /** 6 | * @author 程序猿DD 7 | * @version 1.0.0 8 | * @date 16/4/27 下午10:04. 9 | * @blog http://blog.didispace.com 10 | */ 11 | public class User { 12 | 13 | @Id 14 | private Long id; 15 | 16 | private String username; 17 | private Integer age; 18 | 19 | public User(Long id, String username, Integer age) { 20 | this.id = id; 21 | this.username = username; 22 | this.age = age; 23 | } 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getUsername() { 34 | return username; 35 | } 36 | 37 | public void setUsername(String username) { 38 | this.username = username; 39 | } 40 | 41 | public Integer getAge() { 42 | return age; 43 | } 44 | 45 | public void setAge(Integer age) { 46 | this.age = age; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Chapter9-2-1/compute-service/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.ImportResource; 9 | 10 | import java.util.concurrent.CountDownLatch; 11 | 12 | @SpringBootApplication 13 | @ImportResource({"classpath:dubbo.xml"}) 14 | public class Application { 15 | 16 | private static final Logger logger = Logger.getLogger(Application.class); 17 | 18 | @Bean 19 | public CountDownLatch closeLatch() { 20 | return new CountDownLatch(1); 21 | } 22 | 23 | public static void main(String[] args) throws InterruptedException { 24 | ApplicationContext ctx = SpringApplication.run(Application.class, args); 25 | logger.info("项目启动!"); 26 | CountDownLatch closeLatch = ctx.getBean(CountDownLatch.class); 27 | closeLatch.await(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Chapter9-1-5/service-B/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.ComputeController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.mock.web.MockServletContext; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | import org.springframework.test.web.servlet.MockMvc; 12 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 13 | 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @SpringApplicationConfiguration(classes = MockServletContext.class) 17 | @WebAppConfiguration 18 | public class ApplicationTests { 19 | 20 | private MockMvc mvc; 21 | 22 | @Before 23 | public void setUp() throws Exception { 24 | mvc = MockMvcBuilders.standaloneSetup(new ComputeController()).build(); 25 | } 26 | 27 | @Test 28 | public void getHello() throws Exception { 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api-server/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.ImportResource; 9 | 10 | import java.util.concurrent.CountDownLatch; 11 | 12 | @SpringBootApplication 13 | @ImportResource({"classpath:dubbo.xml"}) 14 | public class Application { 15 | 16 | private static final Logger logger = Logger.getLogger(Application.class); 17 | 18 | @Bean 19 | public CountDownLatch closeLatch() { 20 | return new CountDownLatch(1); 21 | } 22 | 23 | public static void main(String[] args) throws InterruptedException { 24 | ApplicationContext ctx = SpringApplication.run(Application.class, args); 25 | logger.info("项目启动!"); 26 | CountDownLatch closeLatch = ctx.getBean(CountDownLatch.class); 27 | closeLatch.await(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Chapter3-2-1/src/main/java/com/didispace/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.didispace.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.jdbc.core.JdbcTemplate; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * @author 程序猿DD 9 | * @version 1.0.0 10 | * @date 16/3/17 下午6:44. 11 | * @blog http://blog.didispace.com 12 | */ 13 | @Service 14 | public class UserServiceImpl implements UserService { 15 | 16 | @Autowired 17 | private JdbcTemplate jdbcTemplate; 18 | 19 | @Override 20 | public void create(String name, Integer age) { 21 | jdbcTemplate.update("insert into USER(NAME, AGE) values(?, ?)", name, age); 22 | } 23 | 24 | @Override 25 | public void deleteByName(String name) { 26 | jdbcTemplate.update("delete from USER where NAME = ?", name); 27 | } 28 | 29 | @Override 30 | public Integer getAllUsers() { 31 | return jdbcTemplate.queryForObject("select count(1) from USER", Integer.class); 32 | } 33 | 34 | @Override 35 | public void deleteAllUsers() { 36 | jdbcTemplate.update("delete from USER"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/java/com/didispace/dto/ErrorInfo.java: -------------------------------------------------------------------------------- 1 | package com.didispace.dto; 2 | 3 | public class ErrorInfo { 4 | 5 | public static final Integer OK = 0; 6 | public static final Integer ERROR = 100; 7 | 8 | private Integer code; 9 | private String message; 10 | private String url; 11 | private T data; 12 | 13 | public String getUrl() { 14 | return url; 15 | } 16 | 17 | public void setUrl(String url) { 18 | this.url = url; 19 | } 20 | 21 | public static Integer getOK() { 22 | return OK; 23 | } 24 | 25 | public static Integer getERROR() { 26 | return ERROR; 27 | } 28 | 29 | public Integer getCode() { 30 | return code; 31 | } 32 | 33 | public void setCode(Integer code) { 34 | this.code = code; 35 | } 36 | 37 | public String getMessage() { 38 | return message; 39 | } 40 | 41 | public void setMessage(String message) { 42 | this.message = message; 43 | } 44 | 45 | public T getData() { 46 | return data; 47 | } 48 | 49 | public void setData(T data) { 50 | this.data = data; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /Chapter6-1-1/src/main/java/com/didispace/EventConfig.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.statemachine.annotation.*; 6 | 7 | /** 8 | * 该配置实现了com.didispace.StateMachineConfig类中定义的状态机监听器实现。 9 | */ 10 | @WithStateMachine 11 | public class EventConfig { 12 | 13 | private Logger logger = LoggerFactory.getLogger(getClass()); 14 | 15 | @OnTransition(target = "UNPAID") 16 | public void create() { 17 | logger.info("订单创建,待支付"); 18 | } 19 | 20 | @OnTransition(source = "UNPAID", target = "WAITING_FOR_RECEIVE") 21 | public void pay() { 22 | logger.info("用户完成支付,待收货"); 23 | } 24 | 25 | @OnTransitionStart(source = "UNPAID", target = "WAITING_FOR_RECEIVE") 26 | public void payStart() { 27 | logger.info("用户完成支付,待收货: start"); 28 | } 29 | 30 | @OnTransitionEnd(source = "UNPAID", target = "WAITING_FOR_RECEIVE") 31 | public void payEnd() { 32 | logger.info("用户完成支付,待收货: end"); 33 | } 34 | 35 | @OnTransition(source = "WAITING_FOR_RECEIVE", target = "DONE") 36 | public void receive() { 37 | logger.info("用户已收货,订单完成"); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /Chapter3-2-8/src/main/java/com/didispace/domain/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import org.apache.ibatis.annotations.*; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | @Mapper 9 | public interface UserMapper { 10 | 11 | @Select("SELECT * FROM user WHERE name = #{name}") 12 | User findByName(@Param("name") String name); 13 | 14 | @Results({ 15 | @Result(property = "name", column = "name"), 16 | @Result(property = "age", column = "age") 17 | }) 18 | @Select("SELECT name, age FROM user") 19 | List findAll(); 20 | 21 | @Insert("INSERT INTO user(name, age) VALUES(#{name}, #{age})") 22 | int insert(@Param("name") String name, @Param("age") Integer age); 23 | 24 | @Update("UPDATE user SET age=#{age} WHERE name=#{name}") 25 | void update(User user); 26 | 27 | @Delete("DELETE FROM user WHERE id =#{id}") 28 | void delete(Long id); 29 | 30 | @Insert("INSERT INTO user(name, age) VALUES(#{name}, #{age})") 31 | int insertByUser(User user); 32 | 33 | @Insert("INSERT INTO user(name, age) VALUES(#{name,jdbcType=VARCHAR}, #{age,jdbcType=INTEGER})") 34 | int insertByMap(Map map); 35 | 36 | } -------------------------------------------------------------------------------- /Chapter9-2-1/compute-service/src/main/resources/dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter9-1-1/compute-service/src/main/java/com/didispace/web/ComputeController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.cloud.client.ServiceInstance; 6 | import org.springframework.cloud.client.discovery.DiscoveryClient; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class ComputeController { 14 | 15 | private final Logger logger = Logger.getLogger(getClass()); 16 | 17 | @Autowired 18 | private DiscoveryClient client; 19 | 20 | @RequestMapping(value = "/add" ,method = RequestMethod.GET) 21 | public Integer add(@RequestParam Integer a, @RequestParam Integer b) { 22 | ServiceInstance instance = client.getLocalServiceInstance(); 23 | Integer r = a + b; 24 | logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r); 25 | return r; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /Chapter9-1-3/compute-service/src/main/java/com/didispace/web/ComputeController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.cloud.client.ServiceInstance; 6 | import org.springframework.cloud.client.discovery.DiscoveryClient; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class ComputeController { 14 | 15 | private final Logger logger = Logger.getLogger(getClass()); 16 | 17 | @Autowired 18 | private DiscoveryClient client; 19 | 20 | @RequestMapping(value = "/add" ,method = RequestMethod.GET) 21 | public Integer add(@RequestParam Integer a, @RequestParam Integer b) { 22 | ServiceInstance instance = client.getLocalServiceInstance(); 23 | Integer r = a + b; 24 | logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r); 25 | return r; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /Chapter4-1-2/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.async.Task; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 | 10 | import java.util.concurrent.Future; 11 | 12 | 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @SpringApplicationConfiguration(classes = Application.class) 15 | public class ApplicationTests { 16 | 17 | @Autowired 18 | private Task task; 19 | 20 | @Test 21 | public void test() throws Exception { 22 | 23 | long start = System.currentTimeMillis(); 24 | 25 | Future task1 = task.doTaskOne(); 26 | Future task2 = task.doTaskTwo(); 27 | Future task3 = task.doTaskThree(); 28 | 29 | while(true) { 30 | if(task1.isDone() && task2.isDone() && task3.isDone()) { 31 | // 三个任务都调用完成,退出循环等待 32 | break; 33 | } 34 | Thread.sleep(1000); 35 | } 36 | 37 | long end = System.currentTimeMillis(); 38 | 39 | System.out.println("任务全部完成,总耗时:" + (end - start) + "毫秒"); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Chapter9-2-2/compute-service/compute-api-server/src/main/resources/dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Chapter9-1-5/service-A/src/main/java/com/didispace/web/ComputeController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.cloud.client.ServiceInstance; 6 | import org.springframework.cloud.client.discovery.DiscoveryClient; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class ComputeController { 14 | 15 | private final Logger logger = Logger.getLogger(getClass()); 16 | 17 | @Autowired 18 | private DiscoveryClient client; 19 | 20 | @RequestMapping(value = "/add" ,method = RequestMethod.GET) 21 | public String add(@RequestParam Integer a, @RequestParam Integer b) { 22 | ServiceInstance instance = client.getLocalServiceInstance(); 23 | Integer r = a + b; 24 | logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r); 25 | return "From Service-A, Result is " + r; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /Chapter9-1-5/service-B/src/main/java/com/didispace/web/ComputeController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.cloud.client.ServiceInstance; 6 | import org.springframework.cloud.client.discovery.DiscoveryClient; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class ComputeController { 14 | 15 | private final Logger logger = Logger.getLogger(getClass()); 16 | 17 | @Autowired 18 | private DiscoveryClient client; 19 | 20 | @RequestMapping(value = "/add" ,method = RequestMethod.GET) 21 | public String add(@RequestParam Integer a, @RequestParam Integer b) { 22 | ServiceInstance instance = client.getLocalServiceInstance(); 23 | Integer r = a + b; 24 | logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r); 25 | return "From Service-B, Result is " + r; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /Chapter3-2-2/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/21 下午3:35. 12 | * @blog http://blog.didispace.com 13 | */ 14 | @Entity 15 | public class User { 16 | 17 | @Id 18 | @GeneratedValue 19 | private Long id; 20 | 21 | @Column(nullable = false) 22 | private String name; 23 | 24 | @Column(nullable = false) 25 | private Integer age; 26 | 27 | public User(){} 28 | 29 | public User(String name, Integer age) { 30 | this.name = name; 31 | this.age = age; 32 | } 33 | 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public Integer getAge() { 51 | return age; 52 | } 53 | 54 | public void setAge(Integer age) { 55 | this.age = age; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Chapter3-2-4/src/main/java/com/didispace/domain/p/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain.p; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/21 下午3:35. 12 | * @blog http://blog.didispace.com 13 | */ 14 | @Entity 15 | public class User { 16 | 17 | @Id 18 | @GeneratedValue 19 | private Long id; 20 | 21 | @Column(nullable = false) 22 | private String name; 23 | 24 | @Column(nullable = false) 25 | private Integer age; 26 | 27 | public User(){} 28 | 29 | public User(String name, Integer age) { 30 | this.name = name; 31 | this.age = age; 32 | } 33 | 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public Integer getAge() { 51 | return age; 52 | } 53 | 54 | public void setAge(Integer age) { 55 | this.age = age; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Chapter4-4-1/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/21 下午3:35. 12 | * @blog http://blog.didispace.com 13 | */ 14 | @Entity 15 | public class User { 16 | 17 | @Id 18 | @GeneratedValue 19 | private Long id; 20 | 21 | @Column(nullable = false) 22 | private String name; 23 | 24 | @Column(nullable = false) 25 | private Integer age; 26 | 27 | public User(){} 28 | 29 | public User(String name, Integer age) { 30 | this.name = name; 31 | this.age = age; 32 | } 33 | 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public Integer getAge() { 51 | return age; 52 | } 53 | 54 | public void setAge(Integer age) { 55 | this.age = age; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Chapter3-3-1/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/21 下午3:35. 12 | * @blog http://blog.didispace.com 13 | */ 14 | @Entity 15 | public class User { 16 | 17 | @Id 18 | @GeneratedValue 19 | private Long id; 20 | 21 | @Column(nullable = false, length = 5) 22 | private String name; 23 | 24 | @Column(nullable = false) 25 | private Integer age; 26 | 27 | public User(){} 28 | 29 | public User(String name, Integer age) { 30 | this.name = name; 31 | this.age = age; 32 | } 33 | 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public Integer getAge() { 51 | return age; 52 | } 53 | 54 | public void setAge(Integer age) { 55 | this.age = age; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Chapter3-2-4/src/main/java/com/didispace/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.beans.factory.annotation.Qualifier; 4 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Primary; 9 | 10 | import javax.sql.DataSource; 11 | 12 | /** 13 | * @author 程序猿DD 14 | * @version 1.0.0 15 | * @date 16/3/26 下午9:11. 16 | * @blog http://blog.didispace.com 17 | */ 18 | @Configuration 19 | public class DataSourceConfig { 20 | 21 | @Bean(name = "primaryDataSource") 22 | @Qualifier("primaryDataSource") 23 | @ConfigurationProperties(prefix="spring.datasource.primary") 24 | public DataSource primaryDataSource() { 25 | return DataSourceBuilder.create().build(); 26 | } 27 | 28 | @Bean(name = "secondaryDataSource") 29 | @Qualifier("secondaryDataSource") 30 | @Primary 31 | @ConfigurationProperties(prefix="spring.datasource.secondary") 32 | public DataSource secondaryDataSource() { 33 | return DataSourceBuilder.create().build(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Chapter3-2-5/src/main/java/com/didispace/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.domain.User; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.data.redis.connection.RedisConnectionFactory; 7 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | import org.springframework.data.redis.serializer.*; 10 | 11 | /** 12 | * @author 程序猿DD 13 | * @version 1.0.0 14 | * @date 16/4/15 下午3:19. 15 | * @blog http://blog.didispace.com 16 | */ 17 | @Configuration 18 | public class RedisConfig { 19 | 20 | @Bean 21 | JedisConnectionFactory jedisConnectionFactory() { 22 | return new JedisConnectionFactory(); 23 | } 24 | 25 | @Bean 26 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) { 27 | RedisTemplate template = new RedisTemplate(); 28 | template.setConnectionFactory(jedisConnectionFactory()); 29 | template.setKeySerializer(new StringRedisSerializer()); 30 | template.setValueSerializer(new RedisObjectSerializer()); 31 | return template; 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Chapter3-2-4/src/main/java/com/didispace/domain/s/Message.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain.s; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @date 16/3/21 下午3:35. 12 | * @blog http://blog.didispace.com 13 | */ 14 | @Entity 15 | public class Message { 16 | 17 | @Id 18 | @GeneratedValue 19 | private Long id; 20 | 21 | @Column(nullable = false) 22 | private String name; 23 | 24 | @Column(nullable = false) 25 | private String content; 26 | 27 | public Message(){} 28 | 29 | public Message(String name, String content) { 30 | this.name = name; 31 | this.content = content; 32 | } 33 | 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public String getContent() { 51 | return content; 52 | } 53 | 54 | public void setContent(String content) { 55 | this.content = content; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Chapter3-1-6/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.HelloController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | /** 22 | * 23 | * @author 程序猿DD 24 | * @version 1.0.0 25 | * @blog http://blog.didispace.com 26 | * 27 | */ 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @SpringApplicationConfiguration(classes = MockServletContext.class) 30 | @WebAppConfiguration 31 | public class ApplicationTests { 32 | 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Chapter4-4-2/src/main/java/com/didispace/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.didispace.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import java.io.Serializable; 8 | 9 | /** 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @date 16/3/21 下午3:35. 13 | * @blog http://blog.didispace.com 14 | */ 15 | @Entity 16 | public class User implements Serializable { 17 | 18 | @Id 19 | @GeneratedValue 20 | private Long id; 21 | 22 | @Column(nullable = false) 23 | private String name; 24 | 25 | @Column(nullable = false) 26 | private Integer age; 27 | 28 | public User(){} 29 | 30 | public User(String name, Integer age) { 31 | this.name = name; 32 | this.age = age; 33 | } 34 | 35 | public Long getId() { 36 | return id; 37 | } 38 | 39 | public void setId(Long id) { 40 | this.id = id; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public Integer getAge() { 52 | return age; 53 | } 54 | 55 | public void setAge(Integer age) { 56 | this.age = age; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Chapter3-2-1/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.service.UserService; 4 | import org.junit.Assert; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | 13 | @RunWith(SpringJUnit4ClassRunner.class) 14 | @SpringApplicationConfiguration(Application.class) 15 | public class ApplicationTests { 16 | 17 | @Autowired 18 | private UserService userSerivce; 19 | 20 | @Before 21 | public void setUp() { 22 | // 准备,清空user表 23 | userSerivce.deleteAllUsers(); 24 | } 25 | 26 | @Test 27 | public void test() throws Exception { 28 | // 插入5个用户 29 | userSerivce.create("a", 1); 30 | userSerivce.create("b", 2); 31 | userSerivce.create("c", 3); 32 | userSerivce.create("d", 4); 33 | userSerivce.create("e", 5); 34 | 35 | // 查数据库,应该有5个用户 36 | Assert.assertEquals(5, userSerivce.getAllUsers().intValue()); 37 | 38 | // 删除两个用户 39 | userSerivce.deleteByName("a"); 40 | userSerivce.deleteByName("e"); 41 | 42 | // 查数据库,应该有5个用户 43 | Assert.assertEquals(3, userSerivce.getAllUsers().intValue()); 44 | 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Chapter3-1-6/src/main/java/com/didispace/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.didispace.exception; 2 | 3 | import com.didispace.dto.ErrorInfo; 4 | import org.springframework.web.bind.annotation.ControllerAdvice; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | import org.springframework.web.servlet.ModelAndView; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | @ControllerAdvice 12 | public class GlobalExceptionHandler { 13 | 14 | @ExceptionHandler(value = Exception.class) 15 | public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception { 16 | ModelAndView mav = new ModelAndView(); 17 | mav.addObject("exception", e); 18 | mav.addObject("url", req.getRequestURL()); 19 | mav.setViewName("error"); 20 | return mav; 21 | } 22 | 23 | @ExceptionHandler(value = MyException.class) 24 | @ResponseBody 25 | public ErrorInfo jsonErrorHandler(HttpServletRequest req, MyException e) throws Exception { 26 | ErrorInfo r = new ErrorInfo<>(); 27 | r.setMessage(e.getMessage()); 28 | r.setCode(ErrorInfo.ERROR); 29 | r.setData("Some Data"); 30 | r.setUrl(req.getRequestURL().toString()); 31 | return r; 32 | } 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Chapter9-1-5/api-gateway/src/main/java/com/didispace/filter/AccessFilter.java: -------------------------------------------------------------------------------- 1 | package com.didispace.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | 10 | public class AccessFilter extends ZuulFilter { 11 | 12 | private static Logger log = LoggerFactory.getLogger(AccessFilter.class); 13 | 14 | @Override 15 | public String filterType() { 16 | return "pre"; 17 | } 18 | 19 | @Override 20 | public int filterOrder() { 21 | return 0; 22 | } 23 | 24 | @Override 25 | public boolean shouldFilter() { 26 | return true; 27 | } 28 | 29 | @Override 30 | public Object run() { 31 | RequestContext ctx = RequestContext.getCurrentContext(); 32 | HttpServletRequest request = ctx.getRequest(); 33 | 34 | log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString())); 35 | 36 | Object accessToken = request.getParameter("accessToken"); 37 | if(accessToken == null) { 38 | log.warn("access token is empty"); 39 | ctx.setSendZuulResponse(false); 40 | ctx.setResponseStatusCode(401); 41 | return null; 42 | } 43 | log.info("access token ok"); 44 | return null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Chapter3-2-5/src/main/java/com/didispace/RedisObjectSerializer.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.core.convert.converter.Converter; 4 | import org.springframework.core.serializer.support.DeserializingConverter; 5 | import org.springframework.core.serializer.support.SerializingConverter; 6 | import org.springframework.data.redis.serializer.RedisSerializer; 7 | import org.springframework.data.redis.serializer.SerializationException; 8 | 9 | public class RedisObjectSerializer implements RedisSerializer { 10 | 11 | private Converter serializer = new SerializingConverter(); 12 | private Converter deserializer = new DeserializingConverter(); 13 | 14 | static final byte[] EMPTY_ARRAY = new byte[0]; 15 | 16 | public Object deserialize(byte[] bytes) { 17 | if (isEmpty(bytes)) { 18 | return null; 19 | } 20 | 21 | try { 22 | return deserializer.convert(bytes); 23 | } catch (Exception ex) { 24 | throw new SerializationException("Cannot deserialize", ex); 25 | } 26 | } 27 | 28 | public byte[] serialize(Object object) { 29 | if (object == null) { 30 | return EMPTY_ARRAY; 31 | } 32 | 33 | try { 34 | return serializer.convert(object); 35 | } catch (Exception ex) { 36 | return EMPTY_ARRAY; 37 | } 38 | } 39 | 40 | private boolean isEmpty(byte[] data) { 41 | return (data == null || data.length == 0); 42 | } 43 | } -------------------------------------------------------------------------------- /Chapter9-1-5/service-A/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.ComputeController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | @RunWith(SpringJUnit4ClassRunner.class) 22 | @SpringApplicationConfiguration(classes = MockServletContext.class) 23 | @WebAppConfiguration 24 | public class ApplicationTests { 25 | 26 | private MockMvc mvc; 27 | 28 | @Before 29 | public void setUp() throws Exception { 30 | mvc = MockMvcBuilders.standaloneSetup(new ComputeController()).build(); 31 | } 32 | 33 | @Test 34 | public void getHello() throws Exception { 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Chapter4-3-1/src/main/java/com/didispace/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 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.EnableWebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | 10 | @Configuration 11 | @EnableWebSecurity 12 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 13 | 14 | @Override 15 | protected void configure(HttpSecurity http) throws Exception { 16 | http 17 | .authorizeRequests() 18 | .antMatchers("/", "/home").permitAll() 19 | .anyRequest().authenticated() 20 | .and() 21 | .formLogin() 22 | .loginPage("/login") 23 | .permitAll() 24 | .and() 25 | .logout() 26 | .permitAll(); 27 | } 28 | 29 | @Autowired 30 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 31 | auth 32 | .inMemoryAuthentication() 33 | .withUser("user").password("password").roles("USER"); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Chapter4-4-2/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.domain.User; 4 | import com.didispace.domain.UserRepository; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.cache.CacheManager; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | /** 14 | * @author 程序猿DD 15 | * @version 1.0.0 16 | * @date 16/3/23 下午2:34. 17 | * @blog http://blog.didispace.com 18 | */ 19 | @RunWith(SpringJUnit4ClassRunner.class) 20 | @SpringApplicationConfiguration(Application.class) 21 | public class ApplicationTests { 22 | 23 | @Autowired 24 | private UserRepository userRepository; 25 | 26 | @Autowired 27 | private CacheManager cacheManager; 28 | 29 | @Before 30 | public void before() { 31 | userRepository.save(new User("AAA", 10)); 32 | } 33 | 34 | @Test 35 | public void test() throws Exception { 36 | 37 | User u1 = userRepository.findByName("AAA"); 38 | System.out.println("第一次查询:" + u1.getAge()); 39 | 40 | User u2 = userRepository.findByName("AAA"); 41 | System.out.println("第二次查询:" + u2.getAge()); 42 | 43 | u1.setAge(20); 44 | userRepository.save(u1); 45 | User u3 = userRepository.findByName("AAA"); 46 | System.out.println("第三次查询:" + u3.getAge()); 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Chapter3-2-6/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.domain.User; 4 | import com.didispace.domain.UserRepository; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @SpringApplicationConfiguration(Application.class) 16 | public class ApplicationTests { 17 | 18 | @Autowired 19 | private UserRepository userRepository; 20 | 21 | @Before 22 | public void setUp() { 23 | userRepository.deleteAll(); 24 | } 25 | 26 | @Test 27 | public void test() throws Exception { 28 | 29 | // 创建三个User,并验证User总数 30 | userRepository.save(new User(1L, "didi", 30)); 31 | userRepository.save(new User(2L, "mama", 40)); 32 | userRepository.save(new User(3L, "kaka", 50)); 33 | Assert.assertEquals(3, userRepository.findAll().size()); 34 | 35 | // 删除一个User,再验证User总数 36 | User u = userRepository.findOne(1L); 37 | userRepository.delete(u); 38 | Assert.assertEquals(2, userRepository.findAll().size()); 39 | 40 | // 删除一个User,再验证User总数 41 | u = userRepository.findByUsername("mama"); 42 | userRepository.delete(u); 43 | Assert.assertEquals(1, userRepository.findAll().size()); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Chapter4-1-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter4-1-1 8 | 1.0.0 9 | jar 10 | 11 | Chapter4-1-1 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Chapter4-1-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter4-1-2 8 | 1.0.0 9 | jar 10 | 11 | Chapter4-1-2 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Chapter4-4-1/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.domain.User; 4 | import com.didispace.domain.UserRepository; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.cache.CacheManager; 11 | import org.springframework.cache.ehcache.EhCacheCacheManager; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | /** 15 | * @author 程序猿DD 16 | * @version 1.0.0 17 | * @date 16/3/23 下午2:34. 18 | * @blog http://blog.didispace.com 19 | */ 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | @SpringApplicationConfiguration(Application.class) 22 | public class ApplicationTests { 23 | 24 | @Autowired 25 | private UserRepository userRepository; 26 | 27 | @Autowired 28 | private CacheManager cacheManager; 29 | 30 | @Before 31 | public void before() { 32 | userRepository.save(new User("AAA", 10)); 33 | } 34 | 35 | @Test 36 | public void test() throws Exception { 37 | 38 | User u1 = userRepository.findByName("AAA"); 39 | System.out.println("第一次查询:" + u1.getAge()); 40 | 41 | User u2 = userRepository.findByName("AAA"); 42 | System.out.println("第二次查询:" + u2.getAge()); 43 | 44 | u1.setAge(20); 45 | userRepository.save(u1); 46 | User u3 = userRepository.findByName("AAA"); 47 | System.out.println("第三次查询:" + u3.getAge()); 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Chapter4-2-2/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # LOG4J配置 2 | log4j.rootCategory=INFO, stdout, file, errorfile 3 | log4j.category.com.didispace=DEBUG, didifile 4 | log4j.logger.error=errorfile 5 | 6 | # 控制台输出 7 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 10 | 11 | # root日志输出 12 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 13 | log4j.appender.file.file=logs/all.log 14 | log4j.appender.file.DatePattern='.'yyyy-MM-dd 15 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 17 | 18 | # error日志输出 19 | log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender 20 | log4j.appender.errorfile.file=logs/error.log 21 | log4j.appender.errorfile.DatePattern='.'yyyy-MM-dd 22 | log4j.appender.errorfile.Threshold = ERROR 23 | log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.errorfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 25 | 26 | # com.didispace下的日志输出 27 | log4j.appender.didifile=org.apache.log4j.DailyRollingFileAppender 28 | log4j.appender.didifile.file=logs/my.log 29 | log4j.appender.didifile.DatePattern='.'yyyy-MM-dd 30 | log4j.appender.didifile.layout=org.apache.log4j.PatternLayout 31 | log4j.appender.didifile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L ---- %m%n 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter4-2-4/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # LOG4J配置 2 | log4j.rootCategory=INFO, stdout, file, errorfile 3 | log4j.category.com.didispace=DEBUG, didifile 4 | log4j.logger.error=errorfile 5 | 6 | # 控制台输出 7 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 10 | 11 | # root日志输出 12 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 13 | log4j.appender.file.file=logs/all.log 14 | log4j.appender.file.DatePattern='.'yyyy-MM-dd 15 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 17 | 18 | # error日志输出 19 | log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender 20 | log4j.appender.errorfile.file=logs/error.log 21 | log4j.appender.errorfile.DatePattern='.'yyyy-MM-dd 22 | log4j.appender.errorfile.Threshold = ERROR 23 | log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.errorfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 25 | 26 | # com.didispace下的日志输出 27 | log4j.appender.didifile=org.apache.log4j.DailyRollingFileAppender 28 | log4j.appender.didifile.file=logs/my.log 29 | log4j.appender.didifile.DatePattern='.'yyyy-MM-dd 30 | log4j.appender.didifile.layout=org.apache.log4j.PatternLayout 31 | log4j.appender.didifile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L ---- %m%n 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter4-2-3/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # LOG4J配置 2 | log4j.rootCategory=INFO, stdout, file, errorfile 3 | log4j.category.com.didispace=${logging.level.com.didispace}, didifile 4 | log4j.logger.error=errorfile 5 | 6 | # 控制台输出 7 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 8 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 10 | 11 | # root日志输出 12 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 13 | log4j.appender.file.file=logs/all.log 14 | log4j.appender.file.DatePattern='.'yyyy-MM-dd 15 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 17 | 18 | # error日志输出 19 | log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender 20 | log4j.appender.errorfile.file=logs/error.log 21 | log4j.appender.errorfile.DatePattern='.'yyyy-MM-dd 22 | log4j.appender.errorfile.Threshold = ERROR 23 | log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout 24 | log4j.appender.errorfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n 25 | 26 | # com.didispace下的日志输出 27 | log4j.appender.didifile=org.apache.log4j.DailyRollingFileAppender 28 | log4j.appender.didifile.file=logs/my.log 29 | log4j.appender.didifile.DatePattern='.'yyyy-MM-dd 30 | log4j.appender.didifile.layout=org.apache.log4j.PatternLayout 31 | log4j.appender.didifile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L ---- %m%n 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Chapter3-2-4/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.domain.p.User; 4 | import com.didispace.domain.p.UserRepository; 5 | import com.didispace.domain.s.Message; 6 | import com.didispace.domain.s.MessageRepository; 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.boot.test.SpringApplicationConfiguration; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | 15 | 16 | @RunWith(SpringJUnit4ClassRunner.class) 17 | @SpringApplicationConfiguration(Application.class) 18 | public class ApplicationTests { 19 | 20 | @Autowired 21 | private UserRepository userRepository; 22 | @Autowired 23 | private MessageRepository messageRepository; 24 | 25 | @Before 26 | public void setUp() { 27 | } 28 | 29 | @Test 30 | public void test() throws Exception { 31 | 32 | userRepository.save(new User("aaa", 10)); 33 | userRepository.save(new User("bbb", 20)); 34 | userRepository.save(new User("ccc", 30)); 35 | userRepository.save(new User("ddd", 40)); 36 | userRepository.save(new User("eee", 50)); 37 | 38 | Assert.assertEquals(5, userRepository.findAll().size()); 39 | 40 | messageRepository.save(new Message("o1", "aaaaaaaaaa")); 41 | messageRepository.save(new Message("o2", "bbbbbbbbbb")); 42 | messageRepository.save(new Message("o3", "cccccccccc")); 43 | 44 | Assert.assertEquals(3, messageRepository.findAll().size()); 45 | 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Chapter3-1-5/src/main/java/com/didispace/Swagger2.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | /** 14 | * @author 程序猿DD 15 | * @version 1.0.0 16 | * @date 16/4/18 下午12:02. 17 | * @blog http://blog.didispace.com 18 | */ 19 | @Configuration 20 | @EnableSwagger2 21 | public class Swagger2 { 22 | 23 | @Bean 24 | public Docket createRestApi() { 25 | return new Docket(DocumentationType.SWAGGER_2) 26 | .apiInfo(apiInfo()) 27 | .select() 28 | .apis(RequestHandlerSelectors.basePackage("com.didispace.web")) 29 | .paths(PathSelectors.any()) 30 | .build(); 31 | } 32 | 33 | private ApiInfo apiInfo() { 34 | return new ApiInfoBuilder() 35 | .title("Spring Boot中使用Swagger2构建RESTful APIs") 36 | .description("更多Spring Boot相关文章请关注:http://blog.didispace.com/") 37 | .termsOfServiceUrl("http://blog.didispace.com/") 38 | .contact("程序猿DD") 39 | .version("1.0") 40 | .build(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Chapter5-2-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | rabbitmq-hello 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | rabbitmq-hello 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-amqp 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Chapter1/src/test/java/com/didispace/Chapter1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.HelloController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | @RunWith(SpringJUnit4ClassRunner.class) 22 | @SpringApplicationConfiguration(classes = MockServletContext.class) 23 | @WebAppConfiguration 24 | public class Chapter1ApplicationTests { 25 | 26 | private MockMvc mvc; 27 | 28 | @Before 29 | public void setUp() throws Exception { 30 | mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build(); 31 | } 32 | 33 | @Test 34 | public void getHello() throws Exception { 35 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 36 | .andExpect(status().isOk()) 37 | .andExpect(content().string(equalTo("Hello World"))); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Chapter6-1-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | statemachine 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | statemachine 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | org.springframework.statemachine 34 | spring-statemachine-core 35 | 1.2.0.RELEASE 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Chapter9-1-1/compute-service/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.ComputeController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | @RunWith(SpringJUnit4ClassRunner.class) 22 | @SpringApplicationConfiguration(classes = MockServletContext.class) 23 | @WebAppConfiguration 24 | public class ApplicationTests { 25 | 26 | private MockMvc mvc; 27 | 28 | @Before 29 | public void setUp() throws Exception { 30 | mvc = MockMvcBuilders.standaloneSetup(new ComputeController()).build(); 31 | } 32 | 33 | @Test 34 | public void getHello() throws Exception { 35 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 36 | .andExpect(status().isOk()) 37 | .andExpect(content().string(equalTo("Hello World"))); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Chapter9-1-3/compute-service/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.ComputeController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | @RunWith(SpringJUnit4ClassRunner.class) 22 | @SpringApplicationConfiguration(classes = MockServletContext.class) 23 | @WebAppConfiguration 24 | public class ApplicationTests { 25 | 26 | private MockMvc mvc; 27 | 28 | @Before 29 | public void setUp() throws Exception { 30 | mvc = MockMvcBuilders.standaloneSetup(new ComputeController()).build(); 31 | } 32 | 33 | @Test 34 | public void getHello() throws Exception { 35 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 36 | .andExpect(status().isOk()) 37 | .andExpect(content().string(equalTo("Hello World"))); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Chapter2-1-1/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.service.BlogProperties; 4 | import org.apache.commons.logging.Log; 5 | import org.apache.commons.logging.LogFactory; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.SpringApplicationConfiguration; 12 | import org.springframework.mock.web.MockServletContext; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | 15 | 16 | /** 17 | * 18 | * @author 程序猿DD 19 | * @version 1.0.0 20 | * @blog http://blog.didispace.com 21 | * 22 | */ 23 | @RunWith(SpringJUnit4ClassRunner.class) 24 | @SpringApplicationConfiguration(Application.class) 25 | public class ApplicationTests { 26 | 27 | private static final Log log = LogFactory.getLog(ApplicationTests.class); 28 | 29 | @Autowired 30 | private BlogProperties blogProperties; 31 | 32 | 33 | @Test 34 | public void test1() throws Exception { 35 | Assert.assertEquals("程序猿DD", blogProperties.getName()); 36 | Assert.assertEquals("Spring Boot教程", blogProperties.getTitle()); 37 | Assert.assertEquals("程序猿DD正在努力写《Spring Boot教程》", blogProperties.getDesc()); 38 | 39 | log.info("随机数测试输出:"); 40 | log.info("随机字符串 : " + blogProperties.getValue()); 41 | log.info("随机int : " + blogProperties.getNumber()); 42 | log.info("随机long : " + blogProperties.getBignumber()); 43 | log.info("随机10以下 : " + blogProperties.getTest1()); 44 | log.info("随机10-20 : " + blogProperties.getTest2()); 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Chapter2-1-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter2-1-1 8 | 1.0.0 9 | jar 10 | 11 | Chapter2-1-1 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-maven-plugin 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Chapter3-2-6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | demo 8 | 1.0.0 9 | jar 10 | 11 | demo 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-data-mongodb 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Chapter1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter1 8 | 1.0.0 9 | jar 10 | 11 | Chapter1 12 | The first Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Chapter3-1-2/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.HelloController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | /** 22 | * 23 | * @author 程序猿DD 24 | * @version 1.0.0 25 | * @blog http://blog.didispace.com 26 | * 27 | */ 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @SpringApplicationConfiguration(classes = MockServletContext.class) 30 | @WebAppConfiguration 31 | public class ApplicationTests { 32 | 33 | private MockMvc mvc; 34 | 35 | @Before 36 | public void setUp() throws Exception { 37 | mvc = MockMvcBuilders.standaloneSetup( 38 | new HelloController()).build(); 39 | } 40 | 41 | @Test 42 | public void getHello() throws Exception { 43 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 44 | .andExpect(status().isOk()) 45 | .andExpect(content().string(equalTo("Hello World"))); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Chapter3-1-3/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.HelloController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | /** 22 | * 23 | * @author 程序猿DD 24 | * @version 1.0.0 25 | * @blog http://blog.didispace.com 26 | * 27 | */ 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @SpringApplicationConfiguration(classes = MockServletContext.class) 30 | @WebAppConfiguration 31 | public class ApplicationTests { 32 | 33 | private MockMvc mvc; 34 | 35 | @Before 36 | public void setUp() throws Exception { 37 | mvc = MockMvcBuilders.standaloneSetup( 38 | new HelloController()).build(); 39 | } 40 | 41 | @Test 42 | public void getHello() throws Exception { 43 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 44 | .andExpect(status().isOk()) 45 | .andExpect(content().string(equalTo("Hello World"))); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Chapter3-1-4/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.HelloController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | /** 22 | * 23 | * @author 程序猿DD 24 | * @version 1.0.0 25 | * @blog http://blog.didispace.com 26 | * 27 | */ 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @SpringApplicationConfiguration(classes = MockServletContext.class) 30 | @WebAppConfiguration 31 | public class ApplicationTests { 32 | 33 | private MockMvc mvc; 34 | 35 | @Before 36 | public void setUp() throws Exception { 37 | mvc = MockMvcBuilders.standaloneSetup( 38 | new HelloController()).build(); 39 | } 40 | 41 | @Test 42 | public void getHello() throws Exception { 43 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 44 | .andExpect(status().isOk()) 45 | .andExpect(content().string(equalTo("Hello World"))); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Chapter3-2-5/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-2-5 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-2-5 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-redis 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /Chapter4-3-1/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.web.HelloController; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockServletContext; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 14 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 15 | 16 | import static org.hamcrest.Matchers.equalTo; 17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 19 | 20 | 21 | /** 22 | * 23 | * @author 程序猿DD 24 | * @version 1.0.0 25 | * @blog http://blog.didispace.com 26 | * 27 | */ 28 | @RunWith(SpringJUnit4ClassRunner.class) 29 | @SpringApplicationConfiguration(classes = MockServletContext.class) 30 | @WebAppConfiguration 31 | public class ApplicationTests { 32 | 33 | private MockMvc mvc; 34 | 35 | @Before 36 | public void setUp() throws Exception { 37 | mvc = MockMvcBuilders.standaloneSetup( 38 | new HelloController()).build(); 39 | } 40 | 41 | @Test 42 | public void getHello() throws Exception { 43 | mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) 44 | .andExpect(status().isOk()) 45 | .andExpect(content().string(equalTo("Hello World"))); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Chapter3-1-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-1-1 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-1-1 12 | RESTful API Project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-maven-plugin 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Chapter3-2-5/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.domain.User; 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.beans.factory.annotation.Qualifier; 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.data.redis.core.StringRedisTemplate; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @SpringApplicationConfiguration(Application.class) 17 | public class ApplicationTests { 18 | 19 | @Autowired 20 | private StringRedisTemplate stringRedisTemplate; 21 | 22 | @Autowired 23 | private RedisTemplate redisTemplate; 24 | 25 | @Test 26 | public void test() throws Exception { 27 | 28 | // 保存字符串 29 | stringRedisTemplate.opsForValue().set("aaa", "111"); 30 | Assert.assertEquals("111", stringRedisTemplate.opsForValue().get("aaa")); 31 | 32 | // 保存对象 33 | User user = new User("超人", 20); 34 | redisTemplate.opsForValue().set(user.getUsername(), user); 35 | 36 | user = new User("蝙蝠侠", 30); 37 | redisTemplate.opsForValue().set(user.getUsername(), user); 38 | 39 | user = new User("蜘蛛侠", 40); 40 | redisTemplate.opsForValue().set(user.getUsername(), user); 41 | 42 | Assert.assertEquals(20, redisTemplate.opsForValue().get("超人").getAge().longValue()); 43 | Assert.assertEquals(30, redisTemplate.opsForValue().get("蝙蝠侠").getAge().longValue()); 44 | Assert.assertEquals(40, redisTemplate.opsForValue().get("蜘蛛侠").getAge().longValue()); 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Chapter4-1-2/src/main/java/com/didispace/async/Task.java: -------------------------------------------------------------------------------- 1 | package com.didispace.async; 2 | 3 | import org.springframework.scheduling.annotation.Async; 4 | import org.springframework.scheduling.annotation.AsyncResult; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.Random; 8 | import java.util.concurrent.Future; 9 | 10 | /** 11 | * @author 程序猿DD 12 | * @version 1.0.0 13 | * @date 16/5/16 下午12:58. 14 | * @blog http://blog.didispace.com 15 | */ 16 | @Component 17 | public class Task { 18 | 19 | public static Random random =new Random(); 20 | 21 | @Async 22 | public Future doTaskOne() throws Exception { 23 | System.out.println("开始做任务一"); 24 | long start = System.currentTimeMillis(); 25 | Thread.sleep(random.nextInt(10000)); 26 | long end = System.currentTimeMillis(); 27 | System.out.println("完成任务一,耗时:" + (end - start) + "毫秒"); 28 | return new AsyncResult<>("任务一完成"); 29 | } 30 | 31 | @Async 32 | public Future doTaskTwo() throws Exception { 33 | System.out.println("开始做任务二"); 34 | long start = System.currentTimeMillis(); 35 | Thread.sleep(random.nextInt(10000)); 36 | long end = System.currentTimeMillis(); 37 | System.out.println("完成任务二,耗时:" + (end - start) + "毫秒"); 38 | return new AsyncResult<>("任务二完成"); 39 | } 40 | 41 | @Async 42 | public Future doTaskThree() throws Exception { 43 | System.out.println("开始做任务三"); 44 | long start = System.currentTimeMillis(); 45 | Thread.sleep(random.nextInt(10000)); 46 | long end = System.currentTimeMillis(); 47 | System.out.println("完成任务三,耗时:" + (end - start) + "毫秒"); 48 | return new AsyncResult<>("任务三完成"); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Chapter4-2-6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.1.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-actuator 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Chapter3-2-3/src/test/java/com/didispace/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import org.springframework.boot.test.SpringApplicationConfiguration; 10 | import org.springframework.jdbc.core.JdbcTemplate; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | 14 | @RunWith(SpringJUnit4ClassRunner.class) 15 | @SpringApplicationConfiguration(Application.class) 16 | public class ApplicationTests { 17 | 18 | @Autowired 19 | @Qualifier("primaryJdbcTemplate") 20 | protected JdbcTemplate jdbcTemplate1; 21 | 22 | @Autowired 23 | @Qualifier("secondaryJdbcTemplate") 24 | protected JdbcTemplate jdbcTemplate2; 25 | 26 | @Before 27 | public void setUp() { 28 | jdbcTemplate1.update("DELETE FROM USER "); 29 | jdbcTemplate2.update("DELETE FROM USER "); 30 | } 31 | 32 | @Test 33 | public void test() throws Exception { 34 | 35 | // 往第一个数据源中插入两条数据 36 | jdbcTemplate1.update("insert into user(id,name,age) values(?, ?, ?)", 1, "aaa", 20); 37 | jdbcTemplate1.update("insert into user(id,name,age) values(?, ?, ?)", 2, "bbb", 30); 38 | 39 | // 往第二个数据源中插入一条数据,若插入的是第一个数据源,则会主键冲突报错 40 | jdbcTemplate2.update("insert into user(id,name,age) values(?, ?, ?)", 1, "aaa", 20); 41 | 42 | // 查一下第一个数据源中是否有两条数据,验证插入是否成功 43 | Assert.assertEquals("2", jdbcTemplate1.queryForObject("select count(1) from user", String.class)); 44 | 45 | // 查一下第一个数据源中是否有两条数据,验证插入是否成功 46 | Assert.assertEquals("1", jdbcTemplate2.queryForObject("select count(1) from user", String.class)); 47 | 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Chapter3-2-3/src/main/java/com/didispace/DataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import org.springframework.beans.factory.annotation.Qualifier; 4 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.Primary; 9 | import org.springframework.jdbc.core.JdbcTemplate; 10 | 11 | import javax.sql.DataSource; 12 | 13 | /** 14 | * @author 程序猿DD 15 | * @version 1.0.0 16 | * @date 16/3/26 下午9:11. 17 | * @blog http://blog.didispace.com 18 | */ 19 | @Configuration 20 | public class DataSourceConfig { 21 | 22 | @Bean(name = "primaryDataSource") 23 | @Qualifier("primaryDataSource") 24 | @ConfigurationProperties(prefix="spring.datasource.primary") 25 | public DataSource primaryDataSource() { 26 | return DataSourceBuilder.create().build(); 27 | } 28 | 29 | @Bean(name = "secondaryDataSource") 30 | @Qualifier("secondaryDataSource") 31 | @Primary 32 | @ConfigurationProperties(prefix="spring.datasource.secondary") 33 | public DataSource secondaryDataSource() { 34 | return DataSourceBuilder.create().build(); 35 | } 36 | 37 | @Bean(name = "primaryJdbcTemplate") 38 | public JdbcTemplate primaryJdbcTemplate( 39 | @Qualifier("primaryDataSource") DataSource dataSource) { 40 | return new JdbcTemplate(dataSource); 41 | } 42 | 43 | @Bean(name = "secondaryJdbcTemplate") 44 | public JdbcTemplate secondaryJdbcTemplate( 45 | @Qualifier("secondaryDataSource") DataSource dataSource) { 46 | return new JdbcTemplate(dataSource); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Chapter4-5-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter4-5-1 8 | 1.0.0 9 | jar 10 | 11 | Chapter4-5-1 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-mail 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-velocity 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Chapter3-3-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-3-1 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-3-1 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | 5.1.21 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-data-jpa 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Chapter3-2-7/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-2-7 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-2-7 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | org.mybatis.spring.boot 41 | mybatis-spring-boot-starter 42 | 1.1.1 43 | 44 | 45 | 46 | mysql 47 | mysql-connector-java 48 | 5.1.21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Chapter3-2-8/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-2-8 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-2-8 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | org.mybatis.spring.boot 41 | mybatis-spring-boot-starter 42 | 1.1.1 43 | 44 | 45 | 46 | mysql 47 | mysql-connector-java 48 | 5.1.21 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Chapter9-1-5/api-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | api-gateway 8 | 1.0.0 9 | jar 10 | 11 | api-gateway 12 | Spring Cloud project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-starter-zuul 31 | 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-eureka 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-dependencies 45 | Brixton.RELEASE 46 | pom 47 | import 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-maven-plugin 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Chapter4-2-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter4-2-2 8 | 1.0.0 9 | jar 10 | 11 | Chapter4-2-2 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-logging 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-log4j 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Chapter4-2-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter4-2-3 8 | 1.0.0 9 | jar 10 | 11 | Chapter4-2-3 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-logging 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-log4j 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Chapter3-2-3/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-2-3 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-2-3 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | 5.1.21 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-jdbc 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Chapter9-1-5/service-A/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | service-A 8 | 1.0.0 9 | jar 10 | 11 | service-A 12 | Spring Cloud project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-eureka 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-dependencies 45 | Brixton.RELEASE 46 | pom 47 | import 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-maven-plugin 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Chapter9-1-5/service-B/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | service-B 8 | 1.0.0 9 | jar 10 | 11 | service-B 12 | Spring Cloud project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-eureka 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-dependencies 45 | Brixton.RELEASE 46 | pom 47 | import 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-maven-plugin 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Chapter3-1-6/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-1-6 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-1-6 12 | Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-web 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-thymeleaf 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | true 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Chapter3-2-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-2-2 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-2-2 12 | Spring Boot project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | 5.1.21 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-data-jpa 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Chapter3-2-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-2-1 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-2-1 12 | Spring Boot with JDBCTemplate 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.3.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | 5.1.21 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-jdbc 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | --------------------------------------------------------------------------------