├── 03-velocity ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── index.vm │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── web │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 13-async ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── async │ │ │ └── Task.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 14-log4j ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── log4j.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ └── Application.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 17-web-aop └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── log4j.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── 05-exception ├── 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 ├── 12-scheduled ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── task │ │ │ └── ScheduledTasks.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 16-log4j-mongodb └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── log4j.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── web │ │ └── HelloController.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── README.md ├── 03-freemarker ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── index.ftl │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── web │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 18-spring-security └── 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 ├── 29-SpringbootKafka ├── .gitignore ├── src │ └── main │ │ ├── resources │ │ └── config │ │ │ ├── application-prod.yml │ │ │ ├── application.yml │ │ │ └── application-dev.yml │ │ └── java │ │ └── com │ │ └── penck │ │ └── kafka │ │ ├── KafkaApplication.java │ │ ├── web │ │ └── TestController.java │ │ ├── consumer │ │ └── Consumer.java │ │ ├── domain │ │ └── Message.java │ │ └── producer │ │ └── Producer.java ├── README.md └── pom.xml ├── 04-SpringBootWithSwagger ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ ├── web │ │ └── HelloController.java │ │ ├── domain │ │ └── User.java │ │ └── Swagger2.java └── pom.xml ├── 25-distribute-config ├── 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 │ └── pom.xml └── config-client │ └── src │ └── main │ ├── resources │ └── bootstrap.properties │ └── java │ └── com │ └── didispace │ ├── Application.java │ └── web │ └── TestController.java ├── 15-log4j-env-level ├── 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 ├── 28-springboot-kafka ├── kafka-consumer │ ├── .gitignore │ └── src │ │ └── main │ │ ├── resources │ │ ├── config │ │ │ ├── application.yml │ │ │ ├── application-prod.yml │ │ │ └── application-dev.yml │ │ └── static │ │ │ ├── images │ │ │ └── development_ribbon.png │ │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ ├── glyphicons-halflings-regular.woff │ │ │ └── glyphicons-halflings-regular.woff2 │ │ │ └── styles │ │ │ └── consumer-app.css │ │ └── java │ │ └── com │ │ └── penck │ │ └── consumer │ │ ├── ConsumerApplication.java │ │ ├── domain │ │ ├── DownlinkMessage.java │ │ └── UplinkMessage.java │ │ └── config │ │ ├── WebSocketStompConfig.java │ │ └── ZookeeperProperties.java └── kafka-producer │ ├── .gitignore │ └── src │ └── main │ ├── resources │ ├── config │ │ ├── application.yml │ │ ├── application-prod.yml │ │ └── application-dev.yml │ └── static │ │ ├── images │ │ └── development_ribbon.png │ │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ │ └── styles │ │ └── producer-app.css │ └── java │ └── com │ └── penck │ └── producer │ ├── domain │ ├── TopicPayload.java │ └── MessagePayload.java │ ├── ProducerApplication.java │ ├── service │ └── SimplePartitioner.java │ ├── web │ └── ProducerController.java │ └── config │ └── ZookeeperProperties.java ├── 01-custom-properties ├── 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 ├── 21-email ├── weixin.jpg ├── src │ └── main │ │ ├── resources │ │ ├── templates │ │ │ └── template.vm │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ └── Application.java └── pom.xml ├── 23-state-machine ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Events.java │ │ ├── States.java │ │ ├── Application.java │ │ └── EventConfig.java └── pom.xml ├── 10-mongoDB ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── domain │ │ │ ├── UserRepository.java │ │ │ └── User.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 27-spring-bubbo ├── 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 │ └── compute-api.iml │ ├── compute-service.iml │ └── pom.xml ├── 26-api-gateway ├── 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 │ └── pom.xml └── api-gateway │ ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── filter │ │ └── AccessFilter.java │ └── pom.xml ├── 24-spring-eureka ├── compute-service │ ├── 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 │ └── pom.xml ├── 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 ├── 11-mybatis ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── domain │ │ ├── User.java │ │ └── UserMapper.java └── pom.xml ├── 06-JdbcTemplate └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ ├── controller │ │ └── HelloController.java │ │ └── service │ │ ├── UserService.java │ │ └── UserServiceImpl.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── 22-rabbit-mq ├── 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 ├── 02-thymeleaf ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── index.html │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── web │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 07-spring-jpa ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── didispace │ │ │ ├── Application.java │ │ │ └── domain │ │ │ ├── UserRepository.java │ │ │ └── User.java │ └── test │ │ └── java │ │ └── com │ │ └── didispace │ │ └── ApplicationTests.java └── pom.xml ├── 19-cache-ehcache └── src │ ├── main │ ├── resources │ │ ├── ehcache.xml │ │ └── application.properties │ └── java │ │ └── com │ │ └── didispace │ │ ├── Application.java │ │ └── domain │ │ ├── UserRepository.java │ │ └── User.java │ └── test │ └── java │ └── com │ └── didispace │ └── ApplicationTests.java ├── 09-redis ├── 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 ├── 08-muti-data-source ├── 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 └── pom.xml └── 20-cache-redis └── src ├── main ├── resources │ └── application.properties └── java │ └── com │ └── didispace │ ├── Application.java │ └── domain │ ├── UserRepository.java │ └── User.java └── test └── java └── com └── didispace └── ApplicationTests.java /03-velocity/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /13-async/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /14-log4j/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /17-web-aop/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /05-exception/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /12-scheduled/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /16-log4j-mongodb/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringBootSamples 2 | SpringBootSamples 3 | -------------------------------------------------------------------------------- /03-freemarker/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /18-spring-security/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /29-SpringbootKafka/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | *.iml 4 | -------------------------------------------------------------------------------- /04-SpringBootWithSwagger/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /25-distribute-config/config-repo/didispace-dev.properties: -------------------------------------------------------------------------------- 1 | from=git-dev-1.0 -------------------------------------------------------------------------------- /25-distribute-config/config-repo/didispace-prod.properties: -------------------------------------------------------------------------------- 1 | from=git-prod-1.0 -------------------------------------------------------------------------------- /25-distribute-config/config-repo/didispace-test.properties: -------------------------------------------------------------------------------- 1 | from=git-test-1.0 -------------------------------------------------------------------------------- /25-distribute-config/config-repo/didispace.properties: -------------------------------------------------------------------------------- 1 | from=git-default-1.0 2 | -------------------------------------------------------------------------------- /15-log4j-env-level/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=dev -------------------------------------------------------------------------------- /25-distribute-config/config-server/src/main/resources/didispace.properties: -------------------------------------------------------------------------------- 1 | from=local -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | target/ 3 | .idea 4 | *.iml 5 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | target/ 3 | .idea 4 | *.iml 5 | -------------------------------------------------------------------------------- /01-custom-properties/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | # 服务端口 2 | server.port=1111 -------------------------------------------------------------------------------- /25-distribute-config/config-server/src/main/resources/didispace-dev.properties: -------------------------------------------------------------------------------- 1 | from=local-dev -------------------------------------------------------------------------------- /01-custom-properties/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | # 服务端口 2 | server.port=3333 -------------------------------------------------------------------------------- /01-custom-properties/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | # 服务端口 2 | server.port=2222 -------------------------------------------------------------------------------- /15-log4j-env-level/src/main/resources/application-dev.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.didispace=INFO -------------------------------------------------------------------------------- /15-log4j-env-level/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.didispace=INFO -------------------------------------------------------------------------------- /15-log4j-env-level/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.didispace=DEBUG -------------------------------------------------------------------------------- /21-email/weixin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/21-email/weixin.jpg -------------------------------------------------------------------------------- /25-distribute-config/config-server/src/main/resources/didispace-prod.properties: -------------------------------------------------------------------------------- 1 | from=local-prod -------------------------------------------------------------------------------- /25-distribute-config/config-server/src/main/resources/didispace-test.properties: -------------------------------------------------------------------------------- 1 | from=local-test -------------------------------------------------------------------------------- /23-state-machine/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=statemachine 2 | 3 | -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/resources/config/application-prod.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: true 4 | 5 | 6 | -------------------------------------------------------------------------------- /10-mongoDB/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.mongodb.uri=mongodb://name:pass@localhost:27017/test 2 | 3 | 4 | -------------------------------------------------------------------------------- /21-email/src/main/resources/templates/template.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 |

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

4 | 5 | -------------------------------------------------------------------------------- /27-spring-bubbo/consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=localhost:2181 3 | 4 | 5 | logging.level.root=INFO -------------------------------------------------------------------------------- /23-state-machine/src/main/java/com/didispace/Events.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | public enum Events { 4 | PAY, // 支付 5 | RECEIVE // 收货 6 | } -------------------------------------------------------------------------------- /27-spring-bubbo/compute-service/compute-api-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #ZooKeeper 2 | dubbo.registry.address=localhost:2181 3 | 4 | logging.level.root=DEBUG -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: kafka 4 | profiles: 5 | active: dev 6 | 7 | server: 8 | port: 8200 9 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: consumer 4 | profiles: 5 | active: dev 6 | 7 | server: 8 | port: 8200 9 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/config/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: producer 4 | profiles: 5 | active: dev 6 | 7 | server: 8 | port: 8100 9 | -------------------------------------------------------------------------------- /25-distribute-config/config-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/25-distribute-config/config-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | -------------------------------------------------------------------------------- /23-state-machine/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 | -------------------------------------------------------------------------------- /11-mybatis/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 -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/static/images/development_ribbon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-consumer/src/main/resources/static/images/development_ribbon.png -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/static/images/development_ribbon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-producer/src/main/resources/static/images/development_ribbon.png -------------------------------------------------------------------------------- /06-JdbcTemplate/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 -------------------------------------------------------------------------------- /22-rabbit-mq/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 | -------------------------------------------------------------------------------- /02-thymeleaf/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #thymeleaf start 2 | spring.thymeleaf.mode=HTML5 3 | spring.thymeleaf.encoding=UTF-8 4 | spring.thymeleaf.content-type=text/html 5 | #开发时关闭缓存,不然没法看到实时页面 6 | spring.thymeleaf.cache=false 7 | #thymeleaf end -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /25-distribute-config/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-consumer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QDPeng/SpringBootSamples/HEAD/28-springboot-kafka/kafka-producer/src/main/resources/static/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /24-spring-eureka/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/ -------------------------------------------------------------------------------- /26-api-gateway/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/ -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /05-exception/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Hello World

9 | 10 | 11 | -------------------------------------------------------------------------------- /07-spring-jpa/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 -------------------------------------------------------------------------------- /19-cache-ehcache/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /21-email/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.mail.host=smtp.163.com 2 | spring.mail.username=username@163.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 -------------------------------------------------------------------------------- /05-exception/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 统一异常处理 6 | 7 | 8 |

Error Handler

9 |
10 |
11 | 12 | -------------------------------------------------------------------------------- /19-cache-ehcache/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 -------------------------------------------------------------------------------- /05-exception/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 | -------------------------------------------------------------------------------- /03-velocity/src/main/resources/templates/index.vm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 14 | Velocity模板 15 | ${host} 16 | 17 | -------------------------------------------------------------------------------- /09-redis/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 | -------------------------------------------------------------------------------- /21-email/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 | -------------------------------------------------------------------------------- /03-freemarker/src/main/resources/templates/index.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 14 | FreeMarker模板引擎 15 | ${host} 16 | 17 | -------------------------------------------------------------------------------- /07-spring-jpa/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 | -------------------------------------------------------------------------------- /10-mongoDB/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 | -------------------------------------------------------------------------------- /11-mybatis/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 | -------------------------------------------------------------------------------- /17-web-aop/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 | -------------------------------------------------------------------------------- /06-JdbcTemplate/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 | -------------------------------------------------------------------------------- /16-log4j-mongodb/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 | -------------------------------------------------------------------------------- /08-muti-data-source/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 | -------------------------------------------------------------------------------- /22-rabbit-mq/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 | -------------------------------------------------------------------------------- /18-spring-security/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | Spring Security入门 6 | 7 | 8 |

欢迎使用Spring Security!

9 | 10 |

点击 这里 打个招呼吧

11 | 12 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/java/com/penck/producer/domain/TopicPayload.java: -------------------------------------------------------------------------------- 1 | package com.penck.producer.domain; 2 | 3 | /** 4 | * Created by peng on 2017/4/19. 5 | */ 6 | public class TopicPayload { 7 | private String topic; 8 | 9 | public String getTopic() { 10 | return topic; 11 | } 12 | 13 | public void setTopic(String topic) { 14 | this.topic = topic; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /10-mongoDB/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 | -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /25-distribute-config/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 | -------------------------------------------------------------------------------- /29-SpringbootKafka/README.md: -------------------------------------------------------------------------------- 1 | #SpringBoot1.5.1版本集成spring-kafka自动配置 2 | 3 | ## 1、在官网下载安装 kafka_2.11-0.10.2.0 4 | 5 | ## 2、进入conf/server.properties 开启监听:listeners=PLAINTEXT://localhost:9092 6 | 7 | ## 3、通过cmd进入bin/windows目录,开启zookeeper server: 8 | 9 | ### zookeeper-server-start.bat D:\kafka_2.11-0.10.2.0\config\zookeeper.properties 10 | 11 | ## 3、通过cmd进入bin/windows目录,开启kafka server: 12 | 13 | ### kafka-server-start.bat D:\kafka_2.11-0.10.2.0\config\server.properties 14 | -------------------------------------------------------------------------------- /02-thymeleaf/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 14 |
15 | Hello World 16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/java/com/penck/kafka/KafkaApplication.java: -------------------------------------------------------------------------------- 1 | package com.penck.kafka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by peng on 2017/4/20. 8 | */ 9 | @SpringBootApplication 10 | public class KafkaApplication { 11 | public static void main(String[] args) { 12 | SpringApplication.run(KafkaApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /12-scheduled/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | } -------------------------------------------------------------------------------- /18-spring-security/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | Hello World! 6 | 7 | 8 |

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

9 |
10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /26-api-gateway/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/ -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/java/com/penck/consumer/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.penck.consumer; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * Created by peng on 2017/4/19. 9 | */ 10 | @SpringBootApplication 11 | public class ConsumerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/java/com/penck/producer/ProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.penck.producer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by peng on 2017/4/19. 8 | */ 9 | 10 | @SpringBootApplication 11 | public class ProducerApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ProducerApplication.class, args); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /02-thymeleaf/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 | -------------------------------------------------------------------------------- /03-velocity/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 | -------------------------------------------------------------------------------- /05-exception/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 | -------------------------------------------------------------------------------- /08-muti-data-source/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 | -------------------------------------------------------------------------------- /03-freemarker/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 | -------------------------------------------------------------------------------- /01-custom-properties/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 | -------------------------------------------------------------------------------- /18-spring-security/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 | -------------------------------------------------------------------------------- /04-SpringBootWithSwagger/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 | -------------------------------------------------------------------------------- /12-scheduled/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 | -------------------------------------------------------------------------------- /22-rabbit-mq/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 | -------------------------------------------------------------------------------- /17-web-aop/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 | -------------------------------------------------------------------------------- /25-distribute-config/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 | -------------------------------------------------------------------------------- /16-log4j-mongodb/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /09-redis/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 | -------------------------------------------------------------------------------- /20-cache-redis/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 | -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/resources/config/application-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: false 4 | 5 | 6 | kafka: 7 | bootstrap-servers: localhost:9092 8 | consumer: 9 | group-id: "penck" 10 | key-deserializer: org.apache.kafka.common.serialization.StringDeserializer 11 | value-deserializer: org.apache.kafka.common.serialization.StringDeserializer 12 | producer: 13 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 14 | value-serializer: org.apache.kafka.common.serialization.StringSerializer -------------------------------------------------------------------------------- /14-log4j/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 | -------------------------------------------------------------------------------- /01-custom-properties/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 -------------------------------------------------------------------------------- /15-log4j-env-level/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/config/application-prod.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: true 4 | 5 | zookeeper: 6 | host: zookeeper 7 | port: 2181 8 | sessionTimeoutMs: 10000 9 | connectionTimeoutMs: 10000 10 | 11 | kafka: 12 | host: kafka 13 | port: 9092 14 | soTimeout: 100000 15 | bufferSize: 65536 16 | clientId: producer 17 | serializerClass: kafka.serializer.StringEncoder 18 | partitionerClass: com.penck.producer.service.SimplePartitioner 19 | requestRequiredAcks: 1 20 | numPartitions: 1 21 | replicationFactor: 1 22 | -------------------------------------------------------------------------------- /08-muti-data-source/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 -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/config/application-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: false 4 | 5 | zookeeper: 6 | host: localhost 7 | port: 2181 8 | sessionTimeoutMs: 10000 9 | connectionTimeoutMs: 10000 10 | 11 | kafka: 12 | host: localhost 13 | port: 9092 14 | soTimeout: 100000 15 | bufferSize: 65536 16 | clientId: producer 17 | serializerClass: kafka.serializer.StringEncoder 18 | partitionerClass: com.penck.producer.service.SimplePartitioner 19 | requestRequiredAcks: 1 20 | numPartitions: 1 21 | replicationFactor: 1 22 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | -------------------------------------------------------------------------------- /19-cache-ehcache/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 | -------------------------------------------------------------------------------- /20-cache-redis/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 | -------------------------------------------------------------------------------- /12-scheduled/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 | -------------------------------------------------------------------------------- /16-log4j-mongodb/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/static/styles/consumer-app.css: -------------------------------------------------------------------------------- 1 | .nav, .pagination, .carousel, .panel-title a { cursor: pointer; } 2 | 3 | body { 4 | background-color: #cccccc; 5 | font-family: Arial,Helvetica,sans-serif; 6 | } 7 | 8 | .app-title { 9 | float: right; 10 | margin: 0 0 30px 10px; 11 | } 12 | 13 | .downlink-input { 14 | padding: 10px 10px 30px 10px; 15 | margin: 10px; 16 | } 17 | 18 | .message-output { 19 | padding: 10px; 20 | margin: 10px; 21 | } 22 | 23 | .panel-body { 24 | height: 300px; 25 | overflow-y: scroll; 26 | width: 100%; 27 | } 28 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/java/com/penck/producer/domain/MessagePayload.java: -------------------------------------------------------------------------------- 1 | package com.penck.producer.domain; 2 | 3 | /** 4 | * Created by peng on 2017/4/19. 5 | */ 6 | public class MessagePayload { 7 | String topic; 8 | String message; 9 | 10 | public String getTopic() { 11 | return topic; 12 | } 13 | 14 | public void setTopic(String topic) { 15 | this.topic = topic; 16 | } 17 | 18 | public String getMessage() { 19 | return message; 20 | } 21 | 22 | public void setMessage(String message) { 23 | this.message = message; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/config/application-prod.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: true 4 | 5 | zookeeper: 6 | host: zookeeper 7 | port: 2181 8 | sessionTimeoutMs: 10000 9 | connectionTimeoutMs: 10000 10 | 11 | kafka: 12 | host: kafka 13 | port: 9092 14 | soTimeout: 100000 15 | bufferSize: 65536 16 | clientId: producer 17 | serializerClass: kafka.serializer.StringEncoder 18 | partitionerClass: com.penck.producer.service.SimplePartitioner 19 | requestRequiredAcks: 1 20 | numPartitions: 1 21 | replicationFactor: 1 22 | 23 | consumer: 24 | topic: topic-01 25 | messageKey: key-01 26 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/resources/config/application-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: false 4 | 5 | zookeeper: 6 | host: localhost 7 | port: 2181 8 | sessionTimeoutMs: 10000 9 | connectionTimeoutMs: 10000 10 | 11 | kafka: 12 | host: localhost 13 | port: 9092 14 | soTimeout: 100000 15 | bufferSize: 65536 16 | clientId: producer 17 | serializerClass: kafka.serializer.StringEncoder 18 | partitionerClass: com.penck.producer.service.SimplePartitioner 19 | requestRequiredAcks: 1 20 | numPartitions: 1 21 | replicationFactor: 1 22 | 23 | consumer: 24 | topic: topic-01 25 | messageKey: key-01 26 | -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/java/com/penck/kafka/web/TestController.java: -------------------------------------------------------------------------------- 1 | package com.penck.kafka.web; 2 | 3 | import com.penck.kafka.producer.Producer; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * Created by peng on 2017/4/20. 10 | */ 11 | @RestController 12 | public class TestController { 13 | 14 | @Autowired 15 | private Producer producer; 16 | 17 | @RequestMapping("/produce") 18 | public void produce() { 19 | producer.sendMessage(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /16-log4j-mongodb/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 | -------------------------------------------------------------------------------- /22-rabbit-mq/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 | } -------------------------------------------------------------------------------- /24-spring-eureka/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 | } -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/resources/static/styles/producer-app.css: -------------------------------------------------------------------------------- 1 | .nav, .pagination, .carousel, .panel-title a { cursor: pointer; } 2 | 3 | body { 4 | background-color: #cccccc; 5 | font-family: Arial,Helvetica,sans-serif; 6 | } 7 | 8 | .app-title { 9 | float: right; 10 | margin: 0 0 30px 10px; 11 | } 12 | 13 | .message-input { 14 | padding: 10px 10px 10px 10px; 15 | } 16 | 17 | .message-input .form-group { 18 | padding-bottom: 5px; 19 | } 20 | 21 | .message-output { 22 | /*padding: 10px;*/ 23 | /*margin: 10px;*/ 24 | } 25 | 26 | .panel-body { 27 | height: 300px; 28 | overflow-y: scroll; 29 | width: 100%; 30 | } 31 | -------------------------------------------------------------------------------- /27-spring-bubbo/compute-service/compute-service.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /06-JdbcTemplate/src/main/java/com/didispace/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.controller; 2 | 3 | 4 | import com.didispace.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | /** 10 | * @author 程序猿DD 11 | * @version 1.0.0 12 | * @blog http://blog.didispace.com 13 | */ 14 | @Controller 15 | public class HelloController { 16 | @Autowired 17 | UserService userService; 18 | 19 | @RequestMapping("/hello") 20 | public String hello() throws Exception { 21 | return null; 22 | } 23 | 24 | 25 | } -------------------------------------------------------------------------------- /06-JdbcTemplate/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 | -------------------------------------------------------------------------------- /04-SpringBootWithSwagger/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 | } -------------------------------------------------------------------------------- /22-rabbit-mq/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | } -------------------------------------------------------------------------------- /07-spring-jpa/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 | -------------------------------------------------------------------------------- /14-log4j/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 | -------------------------------------------------------------------------------- /17-web-aop/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 | -------------------------------------------------------------------------------- /22-rabbit-mq/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 | -------------------------------------------------------------------------------- /01-custom-properties/src/main/java/com/didispace/web/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.didispace.web; 2 | 3 | import com.didispace.service.BlogProperties; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author 程序猿DD 10 | * @version 1.0.0 11 | * @blog http://blog.didispace.com 12 | */ 13 | @RestController 14 | public class HelloController { 15 | 16 | @Autowired 17 | BlogProperties blogProperties; 18 | 19 | @RequestMapping("/hello") 20 | public String index() { 21 | 22 | return "Hello World" + blogProperties.toString(); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /15-log4j-env-level/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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /18-spring-security/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 | -------------------------------------------------------------------------------- /20-cache-redis/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 | -------------------------------------------------------------------------------- /08-muti-data-source/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 | -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/java/com/penck/kafka/consumer/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.penck.kafka.consumer; 2 | 3 | import com.penck.kafka.domain.Message; 4 | import com.penck.kafka.util.JSONUtils; 5 | import org.springframework.kafka.annotation.KafkaListener; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Created by peng on 2017/4/20. 10 | */ 11 | @Component 12 | public class Consumer { 13 | @KafkaListener(topics = "test1") 14 | public void processMessage(String content) { 15 | try { 16 | Message m = JSONUtils.json2pojo(content, Message.class); 17 | System.out.println(m.getId() + ",msg=" + m.getMsg()); 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /19-cache-ehcache/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 | -------------------------------------------------------------------------------- /27-spring-bubbo/compute-service/compute-api/compute-api.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/java/com/penck/consumer/domain/DownlinkMessage.java: -------------------------------------------------------------------------------- 1 | package com.penck.consumer.domain; 2 | 3 | /** 4 | * Created by peng on 2017/4/19. 5 | */ 6 | public class DownlinkMessage { 7 | private String topic; 8 | private String message; 9 | 10 | public String getTopic() { 11 | return topic; 12 | } 13 | 14 | public void setTopic(String topic) { 15 | this.topic = topic; 16 | } 17 | 18 | public String getMessage() { 19 | return message; 20 | } 21 | 22 | public void setMessage(String message) { 23 | this.message = message; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "DownlinkMessage [topic=" + topic + ", message=" + message + "]"; 29 | } 30 | } -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/java/com/penck/consumer/domain/UplinkMessage.java: -------------------------------------------------------------------------------- 1 | package com.penck.consumer.domain; 2 | 3 | /** 4 | * Created by peng on 2017/4/19. 5 | */ 6 | public class UplinkMessage { 7 | private String topic; 8 | private String message; 9 | 10 | public String getTopic() { 11 | return topic; 12 | } 13 | 14 | public void setTopic(String topic) { 15 | this.topic = topic; 16 | } 17 | 18 | public String getMessage() { 19 | return message; 20 | } 21 | 22 | public void setMessage(String message) { 23 | this.message = message; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "UplinkMessage [topic=" + topic + ", message=" + message + "]"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/java/com/penck/kafka/domain/Message.java: -------------------------------------------------------------------------------- 1 | package com.penck.kafka.domain; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Created by peng on 2017/4/20. 7 | */ 8 | public class Message { 9 | private Long id; 10 | private String msg; 11 | private Date sendTime; 12 | 13 | public Long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(Long id) { 18 | this.id = id; 19 | } 20 | 21 | public String getMsg() { 22 | return msg; 23 | } 24 | 25 | public void setMsg(String msg) { 26 | this.msg = msg; 27 | } 28 | 29 | public Date getSendTime() { 30 | return sendTime; 31 | } 32 | 33 | public void setSendTime(Date sendTime) { 34 | this.sendTime = sendTime; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | -------------------------------------------------------------------------------- /25-distribute-config/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 | } -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/java/com/penck/producer/service/SimplePartitioner.java: -------------------------------------------------------------------------------- 1 | package com.penck.producer.service; 2 | 3 | import kafka.producer.Partitioner; 4 | import kafka.utils.VerifiableProperties; 5 | 6 | /** 7 | * Created by peng on 2017/4/19. 8 | */ 9 | public class SimplePartitioner implements Partitioner { 10 | public SimplePartitioner(VerifiableProperties properties) { 11 | } 12 | 13 | @Override 14 | public int partition(Object key, int numPartitions) { 15 | int partition = 0; 16 | String stringKey = (String)key; 17 | int offset = stringKey.lastIndexOf('.'); 18 | if (offset > 0) { 19 | partition = Integer.parseInt(stringKey.substring(offset+1)) % numPartitions; 20 | } 21 | return partition; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /04-SpringBootWithSwagger/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 | -------------------------------------------------------------------------------- /13-async/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.async.Task; 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 | import java.util.concurrent.Future; 10 | 11 | @SpringBootApplication 12 | @EnableAsync 13 | public class Application { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(Application.class, args); 17 | Task task=new Task(); 18 | try { 19 | Future future =task.doTaskOne(); 20 | future.cancel(true); 21 | task.doTaskTwo(); 22 | 23 | } catch (Exception e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /18-spring-security/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 | } -------------------------------------------------------------------------------- /23-state-machine/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | } -------------------------------------------------------------------------------- /27-spring-bubbo/consumer/src/main/java/com/didispace/Application.java: -------------------------------------------------------------------------------- 1 | package com.didispace; 2 | 3 | import com.didispace.service.ComputeService; 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.ImportResource; 8 | 9 | @SpringBootApplication 10 | @ImportResource({"classpath:dubbo.xml"}) 11 | public class Application { 12 | 13 | public static void main(String[] args) throws InterruptedException { 14 | ApplicationContext context = SpringApplication.run(Application.class, args); 15 | //获取暴露的接口 16 | ComputeService computeService = (ComputeService) context.getBean("computeService"); 17 | System.out.println("computeService:" + computeService.add(111, 3333)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /09-redis/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /27-spring-bubbo/consumer/src/main/resources/dubbo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | -------------------------------------------------------------------------------- /29-SpringbootKafka/src/main/java/com/penck/kafka/producer/Producer.java: -------------------------------------------------------------------------------- 1 | package com.penck.kafka.producer; 2 | 3 | import com.penck.kafka.domain.Message; 4 | import com.penck.kafka.util.JSONUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.kafka.core.KafkaTemplate; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.Date; 10 | import java.util.UUID; 11 | 12 | /** 13 | * Created by peng on 2017/4/20. 14 | */ 15 | @Component 16 | public class Producer { 17 | @Autowired 18 | private KafkaTemplate kafkaTemplate; 19 | 20 | public void sendMessage() { 21 | Message m = new Message(); 22 | m.setId(System.currentTimeMillis()); 23 | m.setMsg(UUID.randomUUID().toString()); 24 | m.setSendTime(new Date()); 25 | try { 26 | kafkaTemplate.send("test1", JSONUtils.obj2json(m)); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /11-mybatis/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 | -------------------------------------------------------------------------------- /05-exception/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 | } -------------------------------------------------------------------------------- /10-mongoDB/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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /03-velocity/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.ResponseBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | /** 11 | * @author 程序猿DD 12 | * @version 1.0.0 13 | * @blog http://blog.didispace.com 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 ModelAndView index(ModelMap map) { 26 | // map.addAttribute("host", "http://blog.didispace.com"); 27 | // return "index"; 28 | ModelAndView mv = new ModelAndView("index"); 29 | mv.addObject("host", "http://blog.didispace.com"); 30 | mv.addObject("clz", "red"); 31 | 32 | return mv; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /03-freemarker/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.ResponseBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | /** 11 | * @author 程序猿DD 12 | * @version 1.0.0 13 | * @blog http://blog.didispace.com 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 ModelAndView index(ModelMap map) { 26 | // map.addAttribute("host", "http://blog.didispace.com"); 27 | // return "index"; 28 | ModelAndView mv = new ModelAndView("index"); 29 | mv.addObject("host", "http://blog.didispace.com"); 30 | mv.addObject("clz", "red"); 31 | 32 | return mv; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /02-thymeleaf/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.ResponseBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | /** 11 | * @author 程序猿DD 12 | * @version 1.0.0 13 | * @blog http://blog.didispace.com 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 ModelAndView index(ModelMap map) { 26 | ModelAndView mv = new ModelAndView("index"); 27 | mv.addObject("host", "http://blog.didispace.com"); 28 | mv.addObject("clz", "red"); 29 | // map.addAttribute("host", "http://blog.didispace.com"); 30 | // map.addAttribute("clz", "red"); 31 | return mv; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /05-exception/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 | } -------------------------------------------------------------------------------- /06-JdbcTemplate/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 | -------------------------------------------------------------------------------- /23-state-machine/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 | } -------------------------------------------------------------------------------- /11-mybatis/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 | } -------------------------------------------------------------------------------- /24-spring-eureka/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 | } -------------------------------------------------------------------------------- /13-async/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 | -------------------------------------------------------------------------------- /27-spring-bubbo/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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | } -------------------------------------------------------------------------------- /26-api-gateway/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 | } -------------------------------------------------------------------------------- /07-spring-jpa/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 | -------------------------------------------------------------------------------- /19-cache-ehcache/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 | -------------------------------------------------------------------------------- /08-muti-data-source/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 | -------------------------------------------------------------------------------- /08-muti-data-source/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 | -------------------------------------------------------------------------------- /09-redis/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/java/com/penck/consumer/config/WebSocketStompConfig.java: -------------------------------------------------------------------------------- 1 | package com.penck.consumer.config; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 7 | import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer; 8 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 9 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 10 | 11 | /** 12 | * Created by peng on 2017/4/19. 13 | */ 14 | @Configuration 15 | @EnableWebSocketMessageBroker 16 | public class WebSocketStompConfig extends AbstractWebSocketMessageBrokerConfigurer { 17 | private final Logger logger = LoggerFactory.getLogger(WebSocketStompConfig.class); 18 | 19 | @Override 20 | public void registerStompEndpoints(StompEndpointRegistry registry) { 21 | registry.addEndpoint("/kafka").withSockJS(); 22 | } 23 | 24 | @Override 25 | public void configureMessageBroker(MessageBrokerRegistry registry) { 26 | registry.enableSimpleBroker("/topic"); 27 | registry.setApplicationDestinationPrefixes("/app"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /05-exception/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 | -------------------------------------------------------------------------------- /08-muti-data-source/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 | -------------------------------------------------------------------------------- /20-cache-redis/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 | -------------------------------------------------------------------------------- /06-JdbcTemplate/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 | -------------------------------------------------------------------------------- /05-exception/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 | -------------------------------------------------------------------------------- /29-SpringbootKafka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.penck 8 | kafka 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.springframework.boot 14 | 15 | spring-boot-starter-parent 16 | 1.5.1.RELEASE 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | org.springframework.kafka 25 | spring-kafka 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-maven-plugin 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /09-redis/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 | } -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/java/com/penck/producer/web/ProducerController.java: -------------------------------------------------------------------------------- 1 | package com.penck.producer.web; 2 | 3 | 4 | import com.penck.producer.service.KafkaService; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.context.ConfigurableApplicationContext; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | 12 | import javax.inject.Inject; 13 | 14 | /** 15 | * Created by peng on 2017/4/19. 16 | */ 17 | @Controller 18 | @RequestMapping("/") 19 | public class ProducerController { 20 | private final Logger logger = LoggerFactory.getLogger(ProducerController.class); 21 | 22 | @Inject 23 | ConfigurableApplicationContext context; 24 | 25 | @Inject 26 | KafkaService kafkaService; 27 | 28 | @RequestMapping(value = "/", method = RequestMethod.GET) 29 | public String home() { 30 | logger.info("Home Controller"); 31 | // kafkaService.sendMessage("test", "test message"); 32 | // kafkaService.sendMessage("topic-01", "topic-01 message"); 33 | // kafkaService.sendMessage("topic-02", "topic-02 message"); 34 | // kafkaService.sendMessage("topic-03", "topic-03 message"); 35 | // kafkaService.sendMessage("topic-04", "topic-04 message"); 36 | 37 | return "index"; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-consumer/src/main/java/com/penck/consumer/config/ZookeeperProperties.java: -------------------------------------------------------------------------------- 1 | package com.penck.consumer.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by peng on 2017/4/19. 8 | */ 9 | @Component 10 | @ConfigurationProperties("zookeeper") 11 | public class ZookeeperProperties { 12 | private String host; 13 | private int port; 14 | private int sessionTimeoutMs; 15 | private int connectionTimeoutMs; 16 | 17 | public String getHost() { 18 | return host; 19 | } 20 | 21 | public void setHost(String host) { 22 | this.host = host; 23 | } 24 | 25 | public int getPort() { 26 | return port; 27 | } 28 | 29 | public void setPort(int port) { 30 | this.port = port; 31 | } 32 | 33 | public int getSessionTimeoutMs() { 34 | return sessionTimeoutMs; 35 | } 36 | 37 | public void setSessionTimeoutMs(int sessionTimeoutMs) { 38 | this.sessionTimeoutMs = sessionTimeoutMs; 39 | } 40 | 41 | public int getConnectionTimeoutMs() { 42 | return connectionTimeoutMs; 43 | } 44 | 45 | public void setConnectionTimeoutMs(int connectionTimeoutMs) { 46 | this.connectionTimeoutMs = connectionTimeoutMs; 47 | } 48 | 49 | public String getZookeeperAddress() { 50 | return host + ":" + port; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /28-springboot-kafka/kafka-producer/src/main/java/com/penck/producer/config/ZookeeperProperties.java: -------------------------------------------------------------------------------- 1 | package com.penck.producer.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by peng on 2017/4/19. 8 | */ 9 | @Component 10 | @ConfigurationProperties("zookeeper") 11 | public class ZookeeperProperties { 12 | private String host; 13 | private int port; 14 | private int sessionTimeoutMs; 15 | private int connectionTimeoutMs; 16 | 17 | public String getHost() { 18 | return host; 19 | } 20 | 21 | public void setHost(String host) { 22 | this.host = host; 23 | } 24 | 25 | public int getPort() { 26 | return port; 27 | } 28 | 29 | public void setPort(int port) { 30 | this.port = port; 31 | } 32 | 33 | public int getSessionTimeoutMs() { 34 | return sessionTimeoutMs; 35 | } 36 | 37 | public void setSessionTimeoutMs(int sessionTimeoutMs) { 38 | this.sessionTimeoutMs = sessionTimeoutMs; 39 | } 40 | 41 | public int getConnectionTimeoutMs() { 42 | return connectionTimeoutMs; 43 | } 44 | 45 | public void setConnectionTimeoutMs(int connectionTimeoutMs) { 46 | this.connectionTimeoutMs = connectionTimeoutMs; 47 | } 48 | 49 | public String getZookeeperAddress() { 50 | return host + ":" + port; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /18-spring-security/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 | } -------------------------------------------------------------------------------- /20-cache-redis/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 | -------------------------------------------------------------------------------- /10-mongoDB/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 | -------------------------------------------------------------------------------- /13-async/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | async 8 | 1.0.0 9 | jar 10 | 11 | async 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 | -------------------------------------------------------------------------------- /12-scheduled/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | scheduled 8 | 1.0.0 9 | jar 10 | 11 | scheduled 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 | -------------------------------------------------------------------------------- /19-cache-ehcache/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 | -------------------------------------------------------------------------------- /14-log4j/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 | -------------------------------------------------------------------------------- /17-web-aop/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 | -------------------------------------------------------------------------------- /15-log4j-env-level/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 | -------------------------------------------------------------------------------- /08-muti-data-source/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 | -------------------------------------------------------------------------------- /22-rabbit-mq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | rabbit-mq 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | rabbit-mq 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 | -------------------------------------------------------------------------------- /04-SpringBootWithSwagger/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 | -------------------------------------------------------------------------------- /24-spring-eureka/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 | -------------------------------------------------------------------------------- /23-state-machine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | state-machine 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | state-machine 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 | -------------------------------------------------------------------------------- /01-custom-properties/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 | -------------------------------------------------------------------------------- /09-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | redis 8 | 1.0.0 9 | jar 10 | 11 | redis 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 | -------------------------------------------------------------------------------- /01-custom-properties/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | custom-properties 8 | 1.0.0 9 | jar 10 | 11 | custom-properties 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 | -------------------------------------------------------------------------------- /10-mongoDB/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | mongoDB 8 | 1.0.0 9 | jar 10 | 11 | mongoDB 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 | -------------------------------------------------------------------------------- /02-thymeleaf/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 | -------------------------------------------------------------------------------- /03-velocity/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 | -------------------------------------------------------------------------------- /03-freemarker/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 | -------------------------------------------------------------------------------- /18-spring-security/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 | -------------------------------------------------------------------------------- /09-redis/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 | -------------------------------------------------------------------------------- /13-async/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 | -------------------------------------------------------------------------------- /21-email/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | email 8 | 1.0.0 9 | jar 10 | 11 | email 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 | -------------------------------------------------------------------------------- /07-spring-jpa/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | spring-jpa 8 | 1.0.0 9 | jar 10 | 11 | spring-jpa 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 | -------------------------------------------------------------------------------- /08-muti-data-source/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | muti-data-source 8 | 1.0.0 9 | jar 10 | 11 | muti-data-source 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 | 61 | -------------------------------------------------------------------------------- /11-mybatis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | mybatis 8 | 1.0.0 9 | jar 10 | 11 | mybatis 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 | -------------------------------------------------------------------------------- /14-log4j/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | log4j 8 | 1.0.0 9 | jar 10 | 11 | log4j 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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /05-exception/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | exception 8 | 1.0.0 9 | jar 10 | 11 | exception 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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /26-api-gateway/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 | -------------------------------------------------------------------------------- /15-log4j-env-level/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | log4j-env-level 8 | 1.0.0 9 | jar 10 | 11 | log4j-env-level 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 | -------------------------------------------------------------------------------- /03-velocity/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 Web 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 | org.springframework.boot 45 | spring-boot-starter-velocity 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 | 63 | 64 | -------------------------------------------------------------------------------- /03-freemarker/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 Web 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 | org.springframework.boot 45 | spring-boot-starter-freemarker 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 | 63 | 64 | -------------------------------------------------------------------------------- /24-spring-eureka/compute-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | compute-service 8 | 1.0.0 9 | jar 10 | 11 | compute-service 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 | -------------------------------------------------------------------------------- /02-thymeleaf/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | Chapter3-1-2 8 | 1.0.0 9 | jar 10 | 11 | Chapter3-1-2 12 | Spring Boot with Thymeleaf 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 | -------------------------------------------------------------------------------- /25-distribute-config/config-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | config-server 8 | 1.0.0 9 | jar 10 | 11 | config-server 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.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-config-server 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | Brixton.RELEASE 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /26-api-gateway/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | eureka-server 8 | 1.0.0 9 | jar 10 | 11 | eureka-server 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.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-eureka-server 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | Brixton.RELEASE 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /24-spring-eureka/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | eureka-server 8 | 1.0.0 9 | jar 10 | 11 | eureka-server 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.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-eureka-server 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | Brixton.RELEASE 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /07-spring-jpa/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.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 UserRepository userRepository; 19 | 20 | @Test 21 | public void test() throws Exception { 22 | 23 | // 创建10条记录 24 | userRepository.save(new User("AAA", 10)); 25 | userRepository.save(new User("BBB", 20)); 26 | userRepository.save(new User("CCC", 30)); 27 | userRepository.save(new User("DDD", 40)); 28 | userRepository.save(new User("EEE", 50)); 29 | userRepository.save(new User("FFF", 60)); 30 | userRepository.save(new User("GGG", 70)); 31 | userRepository.save(new User("HHH", 80)); 32 | userRepository.save(new User("III", 90)); 33 | userRepository.save(new User("JJJ", 100)); 34 | 35 | // 测试findAll, 查询所有记录 36 | Assert.assertEquals(10, userRepository.findAll().size()); 37 | 38 | // 测试findByName, 查询姓名为FFF的User 39 | Assert.assertEquals(60, userRepository.findByName("FFF").getAge().longValue()); 40 | 41 | // 测试findUser, 查询姓名为FFF的User 42 | Assert.assertEquals(60, userRepository.findUser("FFF").getAge().longValue()); 43 | 44 | // 测试findByNameAndAge, 查询姓名为FFF并且年龄为60的User 45 | Assert.assertEquals("FFF", userRepository.findByNameAndAge("FFF", 60).getName()); 46 | 47 | // 测试删除姓名为AAA的User 48 | userRepository.delete(userRepository.findByName("AAA")); 49 | 50 | // 测试findAll, 查询所有记录, 验证上面的删除是否成功 51 | Assert.assertEquals(9, userRepository.findAll().size()); 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /04-SpringBootWithSwagger/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.didispace 7 | SpringBootWithSwagger 8 | 1.0.0 9 | jar 10 | 11 | SpringBootWithSwagger 12 | SpringBootWithSwagger 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 | io.springfox 45 | springfox-swagger2 46 | 2.2.2 47 | 48 | 49 | io.springfox 50 | springfox-swagger-ui 51 | 2.2.2 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | --------------------------------------------------------------------------------