├── spring-boot-logging-log4j2-config
└── src
│ └── main
│ ├── resources
│ └── specific.properties
│ └── java
│ └── com
│ └── rhwayfun
│ └── springboot
│ └── logging
│ └── log4j2
│ └── config
│ ├── BigdataUtilImpl.java
│ ├── Log4j2Plugin.java
│ ├── Application.java
│ ├── Log4j2Controller.java
│ └── SpecificLog4j2Configuration.java
├── spring-boot-custom-schema
├── src
│ ├── main
│ │ ├── resources
│ │ │ ├── META-INF
│ │ │ │ ├── spring.schemas
│ │ │ │ ├── spring.handlers
│ │ │ │ └── people.xsd
│ │ │ └── spring
│ │ │ │ └── custom-spring-schema.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── spring
│ │ │ └── boot
│ │ │ └── custom
│ │ │ └── schema
│ │ │ ├── spring
│ │ │ ├── PeopleNamespaceHandler.java
│ │ │ ├── PeopleBean.java
│ │ │ └── PeopleBeanDefinitionParser.java
│ │ │ └── Application.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── spring
│ │ └── boot
│ │ └── custom
│ │ └── schema
│ │ └── ApplicationTest.java
└── pom.xml
├── spring-boot-starter
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── spring.factories
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── starter
│ │ ├── DemoService.java
│ │ ├── DemoProperties.java
│ │ └── DemoServiceAutoConfiguration.java
└── pom.xml
├── spring-boot-dubbo
├── consumer
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ ├── application.properties
│ │ │ │ └── dubbo-consumer.xml
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── rhwayfun
│ │ │ │ └── springboot
│ │ │ │ └── dubbo
│ │ │ │ └── consumer
│ │ │ │ ├── config
│ │ │ │ └── AppConfig.java
│ │ │ │ └── Application.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── springboot
│ │ │ └── dubbo
│ │ │ └── consumer
│ │ │ └── DubboTest.java
│ └── pom.xml
├── provider
│ ├── src
│ │ └── main
│ │ │ ├── resources
│ │ │ ├── application.properties
│ │ │ └── dubbo-provider.xml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── springboot
│ │ │ └── dubbo
│ │ │ ├── config
│ │ │ └── AppConfig.java
│ │ │ ├── Application.java
│ │ │ └── provider
│ │ │ └── DemoProviderImpl.java
│ └── pom.xml
├── api
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── springboot
│ │ │ └── dubbo
│ │ │ └── api
│ │ │ ├── DemoProvider.java
│ │ │ └── DemoProviderMock.java
│ └── pom.xml
└── pom.xml
├── spring-boot-rocketmq-starter
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── spring.factories
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── rocketmq
│ │ └── starter
│ │ └── constants
│ │ ├── RocketMqTopic.java
│ │ ├── RocketMqTag.java
│ │ └── RocketMqContent.java
└── pom.xml
├── spring-boot-rocketmq
├── src
│ └── main
│ │ ├── resources
│ │ └── application.properties
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── rocketmq
│ │ ├── mq
│ │ ├── DemoRocketMqTag.java
│ │ ├── DemoRocketMqTopic.java
│ │ ├── DemoRocketMqContent.java
│ │ ├── DemoRocketMqProducerExample.java
│ │ └── DemoRocketMqConsumerExample.java
│ │ └── Application.java
└── pom.xml
├── .travis.yml.bak
├── .gitignore
├── source
└── src
│ ├── main
│ ├── resources
│ │ ├── banners.txt
│ │ ├── spring
│ │ │ ├── app-context-db.xml
│ │ │ ├── app-context-common.xml
│ │ │ └── disconf.xml
│ │ ├── webapp
│ │ │ └── WEB-INF
│ │ │ │ └── jsp
│ │ │ │ ├── home.jsp
│ │ │ │ └── login.jsp
│ │ ├── disconf.properties
│ │ ├── config
│ │ │ └── application.properties
│ │ └── static
│ │ │ └── js
│ │ │ └── index.js
│ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── quickstart
│ │ ├── mockito
│ │ ├── EmailVerification.java
│ │ ├── UserDAO.java
│ │ ├── UserDAOImpl.java
│ │ ├── UserService.java
│ │ ├── MainService.java
│ │ ├── Mockito.java
│ │ └── Invocation.java
│ │ ├── aspect
│ │ ├── StatsService.java
│ │ └── StatsServiceInterceptor.java
│ │ ├── controller
│ │ └── rest
│ │ │ ├── MyException.java
│ │ │ └── MyRestResponse.java
│ │ ├── cas
│ │ └── CasProperties.java
│ │ ├── disconf
│ │ ├── DisconfConfig.java
│ │ ├── ConfigTask.java
│ │ └── JedisConfig.java
│ │ ├── security
│ │ ├── dao
│ │ │ ├── UserRepository.java
│ │ │ └── impl
│ │ │ │ └── UserRepositoryImpl.java
│ │ ├── config
│ │ │ └── WebMvcConfig.java
│ │ └── domain
│ │ │ └── UserRole.java
│ │ ├── datasource
│ │ └── constants
│ │ │ └── DataSourceConstants.java
│ │ ├── retry
│ │ ├── web
│ │ │ ├── RetryController.java
│ │ │ └── RetryService.java
│ │ └── RetryTestService.java
│ │ ├── doamin
│ │ ├── User.java
│ │ └── CarBO.java
│ │ ├── memory
│ │ ├── MemorySizes.java
│ │ └── MemoryCounterTest.java
│ │ └── kafka
│ │ ├── config
│ │ └── KafkaConfig.java
│ │ └── simple
│ │ ├── SimpleKafkaProducer.java
│ │ ├── SimpleKafkaConsumerGroup.java
│ │ └── SimpleKafkaConsumer.java
│ └── test
│ └── java
│ └── com
│ └── rhwayfun
│ ├── BootDemoApplicationTests.java
│ ├── testng
│ ├── TestngDemo2.java
│ └── TestngDemo1.java
│ ├── MyMockitoTest.java
│ ├── AspectTest.java
│ ├── springboot
│ └── quickstart
│ │ └── mockito
│ │ ├── BaseMockitoTest.java
│ │ ├── invocation
│ │ └── InvocationTimesTest.java
│ │ ├── UserServiceTest.java
│ │ └── UserServiceSpyTest.java
│ ├── UserServiceTest.java
│ ├── CarDAOTest.java
│ └── UserServiceSpyTest.java
├── spring-boot-logging-log4j2
└── src
│ ├── main
│ ├── resources
│ │ └── log4j2.xml
│ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── logging
│ │ └── log4j2
│ │ └── Application.java
│ └── test
│ └── java
│ └── com
│ └── rhwayfun
│ └── springboot
│ └── logging
│ └── log4j2
│ └── web
│ └── LogControllerTest.java
├── spring-boot-mybatis
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.properties
│ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── springboot
│ │ │ └── mybatis
│ │ │ ├── constants
│ │ │ └── DataSourceConstants.java
│ │ │ └── Application.java
│ └── test
│ │ └── resources
│ │ └── mybatis-generator.xml
└── pom.xml
├── spring-boot-dubbo-annotation
├── dubbo-api
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── springboot
│ │ │ └── dubbo
│ │ │ └── annotation
│ │ │ └── api
│ │ │ ├── DemoProvider.java
│ │ │ └── DemoProviderMock.java
│ └── pom.xml
├── dubbo-provider
│ ├── src
│ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── rhwayfun
│ │ │ │ └── springboot
│ │ │ │ └── dubbo
│ │ │ │ └── annotation
│ │ │ │ ├── config
│ │ │ │ └── AppConfig.java
│ │ │ │ ├── Application.java
│ │ │ │ └── provider
│ │ │ │ └── DemoProviderImpl.java
│ │ │ └── resources
│ │ │ └── application.properties
│ └── pom.xml
├── dubbo-consumer
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rhwayfun
│ │ │ │ └── springboot
│ │ │ │ └── dubbo
│ │ │ │ └── annotation
│ │ │ │ └── consumer
│ │ │ │ ├── config
│ │ │ │ └── AppConfig.java
│ │ │ │ ├── Application.java
│ │ │ │ └── service
│ │ │ │ └── DemoConsumer.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── dubbo
│ │ └── annotation
│ │ └── consumer
│ │ └── DubboTest.java
└── pom.xml
├── spring-boot-mybatis-annotation
└── src
│ └── main
│ ├── resources
│ └── application.properties
│ └── java
│ └── com
│ └── rhwayfun
│ └── springboot
│ └── mybatis
│ └── annotation
│ ├── Application.java
│ ├── constants
│ ├── DataSourceConstants.java
│ ├── SqlConstants.java
│ └── UserSqlProvider.java
│ ├── mapper
│ ├── UserMapperExt.java
│ └── UserMapper.java
│ └── entity
│ └── UserEntity.java
├── spring-boot-starter-rest
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.properties
│ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── springboot
│ │ │ └── starter
│ │ │ └── rest
│ │ │ ├── Application.java
│ │ │ └── web
│ │ │ └── controller
│ │ │ └── DemoController.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── starter
│ │ └── rest
│ │ └── DemoControllerTest.java
└── pom.xml
├── spring-boot-mybatis-sharding-jdbc
└── src
│ └── main
│ ├── resources
│ └── application.properties
│ └── java
│ └── com
│ └── rhwayfun
│ └── springboot
│ └── mybatis
│ └── shardingjdbc
│ ├── druid
│ ├── DruidStatsFilter.java
│ ├── DruidStatsServlet.java
│ └── DruidStatsConfig.java
│ ├── costants
│ ├── DataSourceConstants.java
│ └── SqlConstants.java
│ ├── Application.java
│ ├── mapper
│ └── UserMapper.java
│ ├── service
│ └── UserService.java
│ └── entity
│ └── UserEntity.java
├── spring-boot-quickstart
├── src
│ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── rhwayfun
│ │ │ └── springboot
│ │ │ └── quickstart
│ │ │ ├── Application.java
│ │ │ └── web
│ │ │ └── DemoController.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── quickstart
│ │ └── web
│ │ └── DemoControllerTest.java
└── pom.xml
├── spring-boot-log4j2-integration
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── services
│ │ │ └── io.github.rhwayfun.springboot.log4j2.integration.appender.AppenderFactory
│ │ └── java
│ │ └── io
│ │ └── github
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── log4j2
│ │ └── integration
│ │ ├── appender
│ │ ├── AppenderFactory.java
│ │ └── impl
│ │ │ ├── WarnAppenderFactory.java
│ │ │ ├── ErrorAppenderFactory.java
│ │ │ ├── InfoAppenderFactory.java
│ │ │ └── ConsoleAppenderFactory.java
│ │ ├── en
│ │ ├── PatternLayoutEn.java
│ │ ├── LoggerTypeEn.java
│ │ └── AppenderTypeEn.java
│ │ └── util
│ │ └── AppenderUtil.java
└── pom.xml
├── spring-boot-configuration
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── rhwayfun
│ │ │ │ └── springboot
│ │ │ │ └── configuration
│ │ │ │ ├── Application.java
│ │ │ │ └── random
│ │ │ │ └── RandomProperty.java
│ │ └── resources
│ │ │ ├── application-dev.properties
│ │ │ └── application.properties
│ └── test
│ │ └── java
│ │ └── com
│ │ └── rhwayfun
│ │ └── springboot
│ │ └── configuration
│ │ ├── SimplePropertyTest.java
│ │ ├── RandomPropertyTest.java
│ │ └── ProfilePropertyTest.java
└── pom.xml
├── spring-boot-mybatis-sharding-jdbc-masterslave
└── src
│ └── main
│ ├── resources
│ ├── mybatis-config.xml
│ └── mapper
│ │ └── UserMapper.xml
│ └── java
│ └── com
│ └── rhwayfun
│ └── springboot
│ └── mybatis
│ └── shardingjdbc
│ └── masterslave
│ ├── Application.java
│ ├── mapper
│ ├── UserMapper.java
│ └── UserRepository.java
│ ├── constants
│ ├── DataSourceConstants.java
│ └── SqlConstants.java
│ └── entity
│ └── UserEntity.java
├── spring-boot-mybatis-multidatasource
└── src
│ └── main
│ ├── resources
│ └── application.properties
│ └── java
│ └── com
│ └── rhwayfun
│ └── springboot
│ └── mybatis
│ └── multidatasource
│ ├── Application.java
│ ├── constants
│ └── DataSourceConstants.java
│ ├── mapper
│ ├── user
│ │ └── UserMapper.java
│ └── city
│ │ └── CityMapper.java
│ └── entity
│ ├── UserEntity.java
│ └── CityEntity.java
├── spring-boot-task
└── pom.xml
├── spring-boot-aspect
└── pom.xml
├── spring-boot-disconf
└── pom.xml
├── spring-boot-geode
└── pom.xml
├── spring-boot-ignite
└── pom.xml
├── spring-boot-kafka
└── pom.xml
├── spring-boot-mockito
└── pom.xml
├── spring-boot-mongodb
└── pom.xml
├── spring-boot-redis
└── pom.xml
├── spring-boot-retry
└── pom.xml
├── spring-boot-web-jsp
└── pom.xml
├── spring-boot-influxdb
└── pom.xml
├── spring-boot-security
└── pom.xml
├── spring-boot-elastic-job
└── pom.xml
├── spring-boot-security-cas
└── pom.xml
├── spring-boot-cache-caffeine
└── pom.xml
├── spring-boot-cache-ehcache
└── pom.xml
├── spring-boot-elasticsearch
└── pom.xml
├── spring-boot-web-bootstrap
└── pom.xml
├── spring-boot-web-thymeleaf
└── pom.xml
├── spring-boot-dubbo-extension
└── pom.xml
├── spring-boot-hibernate-validation
└── pom.xml
├── docs
└── sql
│ └── security
│ └── init.sql
├── .travis.yml
└── apache-rocketmq-starter-guide.md
/spring-boot-logging-log4j2-config/src/main/resources/specific.properties:
--------------------------------------------------------------------------------
1 | app.code=spring-boot-logging-log4j2-config
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/resources/META-INF/spring.schemas:
--------------------------------------------------------------------------------
1 | http\://blog.csdn.net/cutesource/schema/people.xsd=META-INF/people.xsd
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/resources/META-INF/spring.handlers:
--------------------------------------------------------------------------------
1 | http\://blog.csdn.net/cutesource/schema/people=com.rhwayfun.spring.boot.custom.schema.spring.PeopleNamespaceHandler
--------------------------------------------------------------------------------
/spring-boot-starter/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.rhwayfun.springboot.starter.DemoServiceAutoConfiguration
--------------------------------------------------------------------------------
/spring-boot-dubbo/consumer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-dubbo-consumer
2 |
3 | dubbo.registry.zk=multicast://224.5.6.7:1234
4 | dubbo.protocol.port=20880
--------------------------------------------------------------------------------
/spring-boot-dubbo/provider/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-dubbo-provider
2 |
3 | dubbo.registry.zk=multicast://224.5.6.7:1234
4 | dubbo.protocol.port=20880
--------------------------------------------------------------------------------
/spring-boot-rocketmq-starter/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | com.rhwayfun.springboot.rocketmq.starter.config.RocketMqAutoConfiguration
--------------------------------------------------------------------------------
/spring-boot-rocketmq/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-rocketmq
2 |
3 | # Apache RocketMQ
4 | spring.rocketmq.nameServer=localhost:9876
5 | spring.rocketmq.producer-group-name=spring-boot-test-producer-group
--------------------------------------------------------------------------------
/.travis.yml.bak:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | sudo: false # faster builds
7 |
8 | script: "mvn cobertura:cobertura"
9 |
10 | after_success:
11 | - bash <(curl -s https://codecov.io/bash) -t e973842b-bf4c-4c04-b87d-5150d41e52bd
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Maven
2 | target/
3 | *.ser
4 | *.ec
5 |
6 | # IntelliJ Idea
7 | .idea/
8 | out/
9 | *.ipr
10 | *.iws
11 | *.iml
12 |
13 | # Eclipse
14 | .classpath
15 | .project
16 | .settings/
17 | .metadata/
18 |
19 | # OS X
20 | .DS_Store
21 |
22 | # Disconf
23 | /disconf/
--------------------------------------------------------------------------------
/source/src/main/resources/banners.txt:
--------------------------------------------------------------------------------
1 |
2 | _________ .__
3 | / _____/____________|__| ____ ____
4 | \_____ \\____ \_ __ \ |/ \ / ___\
5 | / \ |_> > | \/ | | \/ /_/ >
6 | /_______ / __/|__| |__|___| /\___ /
7 | \/|__| \//_____/
8 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/api/src/main/java/com/rhwayfun/springboot/dubbo/api/DemoProvider.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.api;
2 |
3 | /**
4 | * @author rhwayfun
5 | * @since 0.0.1
6 | */
7 | public interface DemoProvider {
8 |
9 | String sayHello(String name);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | %d %p [%t] %c{10}:%M:%L %X{traceId,0} %m%n
6 |
7 |
8 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq-starter/src/main/java/com/rhwayfun/springboot/rocketmq/starter/constants/RocketMqTopic.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.starter.constants;
2 |
3 | /**
4 | * @author rhwayfun
5 | * @since 0.0.1
6 | */
7 | public interface RocketMqTopic {
8 |
9 | String getTopic();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-mybatis/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-mybatis
2 |
3 | mybatis.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
4 | mybatis.datasource.username=travis
5 | mybatis.datasource.password=
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-api/src/main/java/com/rhwayfun/springboot/dubbo/annotation/api/DemoProvider.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.api;
2 |
3 | /**
4 | * @author rhwayfun
5 | * @since 0.0.1
6 | */
7 | public interface DemoProvider {
8 |
9 | String sayHello(String name);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-mybatis
2 |
3 | mybatis.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
4 | mybatis.datasource.username=travis
5 | mybatis.datasource.password=
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/mockito/EmailVerification.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | /**
4 | * Created by chubin on 2017/4/16.
5 | */
6 | public class EmailVerification{
7 | public boolean verifyEmail(String email){
8 | return "zhongchubin@dianwoba.com".equals(email);
9 | }
10 | }
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/aspect/StatsService.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.aspect;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * Created by chubin on 2017/3/19.
7 | */
8 | @Target({ElementType.METHOD})
9 | @Retention(RetentionPolicy.CLASS)
10 | @Documented
11 | public @interface StatsService {
12 | }
13 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/controller/rest/MyException.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.controller.rest;
2 |
3 | /**
4 | * Created by chubin on 2017/2/12.
5 | */
6 | public class MyException extends RuntimeException {
7 |
8 | public MyException(String message) {
9 | super(message);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-provider/src/main/java/com/rhwayfun/springboot/dubbo/annotation/config/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 |
5 | /**
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | @Configuration
10 | public class AppConfig {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-starter-rest/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-starter-rest
2 |
3 | demo.user.id=1
4 | demo.user.name=happyxiaofan
5 | demo.user.age=12
6 | demo.user.email=rhwayfun@gmail.com
7 |
8 | user1.id=1
9 | user1.name=bean1
10 | user1.city=Hangzhou
11 |
12 | user2.id=2
13 | user2.name=bean2
14 | user2.city=Shanghai
15 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-consumer/src/main/java/com/rhwayfun/springboot/dubbo/annotation/consumer/config/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.consumer.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 |
5 | /**
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | @Configuration
10 | public class AppConfig {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-mybatis/src/main/java/com/rhwayfun/springboot/mybatis/constants/DataSourceConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.constants;
2 |
3 | public abstract class DataSourceConstants {
4 |
5 | public static final String MAPPER_PACKAGE = "com.rhwayfun.springboot.mybatis.mapper";
6 | public static final String MAPPER_LOCATION = "classpath:mybatis/*Mapper*.xml";
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/api/src/main/java/com/rhwayfun/springboot/dubbo/api/DemoProviderMock.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.api;
2 |
3 | /**
4 | * @author rhwayfun
5 | * @since 0.0.1
6 | */
7 | public class DemoProviderMock implements DemoProvider {
8 |
9 | @Override
10 | public String sayHello(String name) {
11 | // 容错数据,此方法只在出现RpcException时被执行
12 | return null;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-mybatis-sharding-jdbc
2 | server.context-path=/springboot
3 |
4 | mybatis.datasource.url=jdbc:mysql://127.0.0.1:3306/%s?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
5 | mybatis.datasource.username=travis
6 | mybatis.datasource.password=
7 |
8 | logging.level.com.alibaba.druid=debug
--------------------------------------------------------------------------------
/spring-boot-dubbo/provider/src/main/java/com/rhwayfun/springboot/dubbo/config/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.context.annotation.ImportResource;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @Configuration
11 | @ImportResource("dubbo-provider.xml")
12 | public class AppConfig {
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq-starter/src/main/java/com/rhwayfun/springboot/rocketmq/starter/constants/RocketMqTag.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.starter.constants;
2 |
3 | /**
4 | * The interface RocketMqTag.
5 | *
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | public interface RocketMqTag {
10 |
11 | /**
12 | * Gets tag.
13 | *
14 | * @return the tag
15 | */
16 | String getTag();
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq/src/main/java/com/rhwayfun/springboot/rocketmq/mq/DemoRocketMqTag.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.mq;
2 |
3 | import io.github.rhwayfun.springboot.rocketmq.starter.constants.RocketMqTag;
4 |
5 | /**
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | public class DemoRocketMqTag implements RocketMqTag {
10 | @Override
11 | public String getTag() {
12 | return "TagA";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/spring-boot-quickstart/src/main/java/com/rhwayfun/springboot/quickstart/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart;
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 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/cas/CasProperties.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.cas;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 |
5 | /**
6 | * Created by chubin on 2017/8/13.
7 | */
8 |
9 | @ConfigurationProperties(prefix = CasProperties.CAS_PREFIX)
10 | public class CasProperties {
11 |
12 | public static final String CAS_PREFIX = "cas";
13 |
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/consumer/src/main/java/com/rhwayfun/springboot/dubbo/consumer/config/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.consumer.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.context.annotation.ImportResource;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @Configuration
11 | @ImportResource("dubbo-consumer.xml")
12 | public class AppConfig {
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq/src/main/java/com/rhwayfun/springboot/rocketmq/mq/DemoRocketMqTopic.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.mq;
2 |
3 | import io.github.rhwayfun.springboot.rocketmq.starter.constants.RocketMqTopic;
4 |
5 | /**
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | public class DemoRocketMqTopic implements RocketMqTopic {
10 | @Override
11 | public String getTopic() {
12 | return "TopicA";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/BootDemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class BootDemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/testng/TestngDemo2.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.testng;
2 |
3 | import org.junit.AfterClass;
4 | import org.junit.BeforeClass;
5 | import org.testng.annotations.Test;
6 |
7 | import java.time.LocalDateTime;
8 |
9 | /**
10 | * Created by chubin on 2017/3/28.
11 | */
12 | public class TestngDemo2 {
13 |
14 | @Test
15 | public void testParameter(String test1){
16 | System.out.println(test1);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-api/src/main/java/com/rhwayfun/springboot/dubbo/annotation/api/DemoProviderMock.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.api;
2 |
3 | /**
4 | * @author rhwayfun
5 | * @since 0.0.1
6 | */
7 | public class DemoProviderMock implements DemoProvider {
8 |
9 | @Override
10 | public String sayHello(String name) {
11 | // 容错数据,此方法只在出现RpcException时被执行
12 | return null;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/controller/rest/MyRestResponse.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.controller.rest;
2 |
3 | /**
4 | * Created by chubin on 2017/2/12.
5 | */
6 | public class MyRestResponse {
7 | private String message;
8 |
9 | public MyRestResponse(String message) {
10 | this.message = message;
11 | }
12 |
13 | public String getMessage() {
14 | return this.message;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/resources/META-INF/services/io.github.rhwayfun.springboot.log4j2.integration.appender.AppenderFactory:
--------------------------------------------------------------------------------
1 | io.github.rhwayfun.springboot.log4j2.integration.appender.impl.ConsoleAppenderFactory
2 | io.github.rhwayfun.springboot.log4j2.integration.appender.impl.InfoAppenderFactory
3 | io.github.rhwayfun.springboot.log4j2.integration.appender.impl.WarnAppenderFactory
4 | io.github.rhwayfun.springboot.log4j2.integration.appender.impl.ErrorAppenderFactory
5 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/disconf/DisconfConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.disconf;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.context.annotation.ImportResource;
5 |
6 | /**
7 | * Created by chubin on 2017/6/11.
8 | */
9 | @Configuration
10 | @ImportResource(locations = {"classpath:spring/app-context-common.xml", "classpath:spring/disconf.xml"})
11 | public class DisconfConfig {
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/provider/src/main/java/com/rhwayfun/springboot/dubbo/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo;
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) throws InterruptedException {
10 | SpringApplication.run(Application.class, args);
11 | Thread.sleep(Long.MAX_VALUE);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-mybatis/src/main/java/com/rhwayfun/springboot/mybatis/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis;
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) throws InterruptedException {
10 | SpringApplication.run(Application.class, args);
11 | Thread.sleep(Long.MAX_VALUE);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-quickstart/src/main/java/com/rhwayfun/springboot/quickstart/web/DemoController.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.web;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | /**
7 | * Created by chubin on 2017/9/10.
8 | */
9 | @RestController
10 | public class DemoController {
11 |
12 | @RequestMapping("/now")
13 | public String now(){
14 | return "hello";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-configuration/src/main/java/com/rhwayfun/springboot/configuration/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.configuration;
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) throws InterruptedException {
10 | SpringApplication.run(Application.class, args);
11 | Thread.sleep(Long.MAX_VALUE);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/resources/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/java/com/rhwayfun/spring/boot/custom/schema/spring/PeopleNamespaceHandler.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.spring.boot.custom.schema.spring;
2 |
3 | import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
4 |
5 | /**
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | public class PeopleNamespaceHandler extends NamespaceHandlerSupport {
10 | @Override
11 | public void init() {
12 | registerBeanDefinitionParser("people", new PeopleBeanDefinitionParser());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/provider/src/main/java/com/rhwayfun/springboot/dubbo/provider/DemoProviderImpl.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.provider;
2 |
3 | import com.rhwayfun.springboot.dubbo.api.DemoProvider;
4 | import org.springframework.stereotype.Component;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @Component
11 | public class DemoProviderImpl implements DemoProvider {
12 |
13 | @Override
14 | public String sayHello(String name) {
15 | return "Hello " + name;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/source/src/main/resources/spring/app-context-db.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2/src/main/java/com/rhwayfun/springboot/logging/log4j2/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.logging.log4j2;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 程序入口
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(Application.class, args);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/source/src/main/resources/webapp/WEB-INF/jsp/home.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
5 |
6 |
7 |
8 |
9 | Welcome SpringBoot
10 | <%--
11 | --%>
12 |
13 |
14 | ${time}
15 | logout
16 |
17 |
--------------------------------------------------------------------------------
/source/src/main/resources/spring/app-context-common.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/security/dao/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.security.dao;
2 |
3 | import com.rhwayfun.springboot.quickstart.security.datasource.model.User;
4 | import com.rhwayfun.springboot.quickstart.security.datasource.model.UserAuthority;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by chubin on 2017/8/13.
10 | */
11 | public interface UserRepository{
12 |
13 | User findByUserName(String username);
14 |
15 | List findRoles(int userId);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/appender/AppenderFactory.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.appender;
2 |
3 | import io.github.rhwayfun.springboot.log4j2.integration.en.AppenderTypeEn;
4 | import org.apache.logging.log4j.core.Appender;
5 | import org.apache.logging.log4j.core.LoggerContext;
6 |
7 | /**
8 | * @author rhwayfun
9 | * @since 0.0.1
10 | */
11 | public interface AppenderFactory {
12 |
13 | Appender createAppender(LoggerContext ctx, AppenderTypeEn type);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-multidatasource/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-mybatis-multidatasource
2 |
3 | mybatis.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
4 | mybatis.datasource.username=travis
5 | mybatis.datasource.password=
6 |
7 | mybatis.datasource2.url=jdbc:mysql://127.0.0.1:3306/springboot2?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false
8 | mybatis.datasource2.username=travis
9 | mybatis.datasource2.password=
--------------------------------------------------------------------------------
/spring-boot-dubbo/api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-dubbo
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | api
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/consumer/src/main/java/com/rhwayfun/springboot/dubbo/consumer/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.consumer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @SpringBootApplication
11 | public class Application {
12 |
13 | public static void main(String[] args) throws InterruptedException {
14 | SpringApplication.run(Application.class, args);
15 | Thread.sleep(Long.MAX_VALUE);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq/src/main/java/com/rhwayfun/springboot/rocketmq/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 程序入口
8 | *
9 | * @author rhwayfun
10 | * @since 0.0.1
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) throws InterruptedException {
16 | SpringApplication.run(Application.class, args);
17 | Thread.sleep(Long.MAX_VALUE);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/resources/spring/custom-spring-schema.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-provider/src/main/java/com/rhwayfun/springboot/dubbo/annotation/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @SpringBootApplication
11 | public class Application {
12 |
13 | public static void main(String[] args) throws InterruptedException {
14 | SpringApplication.run(Application.class, args);
15 | Thread.sleep(Long.MAX_VALUE);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-task/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-task
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-aspect/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-aspect
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-disconf/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-disconf
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-geode/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-geode
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-ignite/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-ignite
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-kafka/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-kafka
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-mockito/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-mockito
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-mongodb/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-mongodb
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-redis/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-redis
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-retry/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-retry
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-starter-rest/src/main/java/com/rhwayfun/springboot/starter/rest/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.starter.rest;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 程序入口
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) throws InterruptedException {
16 | SpringApplication.run(Application.class, args);
17 | Thread.sleep(Long.MAX_VALUE);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-boot-web-jsp/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-web-jsp
13 |
14 |
15 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/MyMockitoTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun;
2 |
3 | import org.junit.Test;
4 |
5 | import java.util.List;
6 |
7 | import static com.rhwayfun.springboot.quickstart.mockito.Mockito.mock;
8 | import static com.rhwayfun.springboot.quickstart.mockito.Mockito.when;
9 |
10 | /**
11 | * Created by chubin on 2017/4/16.
12 | */
13 | public class MyMockitoTest {
14 |
15 | @Test
16 | public void test() throws Exception{
17 | List mock = mock(List.class);
18 | when(mock.get(0)).thenReturn("hello");
19 | System.out.println(mock.get(0));
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-boot-influxdb/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-influxdb
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-security/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-security
13 |
14 |
15 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/mockito/UserDAO.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by chubin on 2017/3/26.
9 | */
10 | public interface UserDAO {
11 |
12 | User findById(int id);
13 |
14 | void deleteById(int id);
15 |
16 | List findLists(int... ids);
17 |
18 | boolean modifyUser(User user);
19 |
20 | boolean modifyUser(Integer id, String name, List hobbies);
21 |
22 | User findByName(String name);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-consumer/src/main/java/com/rhwayfun/springboot/dubbo/annotation/consumer/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.consumer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @SpringBootApplication
11 | public class Application {
12 |
13 | public static void main(String[] args) throws InterruptedException {
14 | SpringApplication.run(Application.class, args);
15 | Thread.sleep(Long.MAX_VALUE);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-elastic-job/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-elastic-job
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/java/com/rhwayfun/springboot/mybatis/annotation/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.annotation;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 程序入口
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) throws InterruptedException {
16 | SpringApplication.run(Application.class, args);
17 | Thread.sleep(Long.MAX_VALUE);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-boot-security-cas/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-security-cas
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-cache-caffeine/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-cache-caffeine
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-cache-ehcache/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-cache-ehcache
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-elasticsearch/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-elasticsearch
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-web-bootstrap/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-web-bootstrap
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-web-thymeleaf/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-web-thymeleaf
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-extension/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-dubbo-extension
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-configuration/src/main/resources/application-dev.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-configuration
2 |
3 | # random value
4 | my.secret=${random.value}
5 | my.number=${random.int}
6 | my.bignumber=${random.long}
7 | my.uuid=${random.uuid}
8 | my.number.less.than.ten=${random.int(10)}
9 | my.number.in.range=${random.int[100,200]}
10 |
11 | # property value
12 | my.config.app=${spring.application.name}
13 | my.config.user=springboot
14 | my.config.age=1
15 | my.config.email=springboot@gmail.com
16 | my.config.blog=http://blog.csdn.net/springboot
17 | my.config.github=https://github.com/springboot/spring-boot-samples
18 |
--------------------------------------------------------------------------------
/spring-boot-hibernate-validation/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-hibernate-validation
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-multidatasource/src/main/java/com/rhwayfun/springboot/mybatis/multidatasource/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.multidatasource;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 程序入口
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) throws InterruptedException {
16 | SpringApplication.run(Application.class, args);
17 | Thread.sleep(Long.MAX_VALUE);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-boot-configuration/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=spring-boot-configuration
2 |
3 | # random value
4 | my.secret=${random.value}
5 | my.number=${random.int}
6 | my.bignumber=${random.long}
7 | my.uuid=${random.uuid}
8 | my.number.less.than.ten=${random.int(10)}
9 | my.number.in.range=${random.int[10,100]}
10 |
11 | # property value
12 | my.config.app=${spring.application.name}
13 | my.config.user=happyxiaofan
14 | my.config.age=24
15 | my.config.email=rhwayfun@gmail.com
16 | my.config.blog=http://blog.csdn.net/u011116672
17 | my.config.github=https://github.com/happyxiaofan/spring-boot-learning-examples
18 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-dubbo-annotation
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | dubbo-api
13 | 0.0.1-SNAPSHOT
14 |
15 |
--------------------------------------------------------------------------------
/spring-boot-starter/src/main/java/com/rhwayfun/springboot/starter/DemoService.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.starter;
2 |
3 | /**
4 | * @author happyxiaofan
5 | * @since 0.0.1
6 | */
7 | public class DemoService {
8 |
9 | private DemoProperties demoProperties;
10 |
11 | public DemoService(DemoProperties demoProperties) {
12 | this.demoProperties = demoProperties;
13 | }
14 |
15 | public String userInfo() {
16 | return String.format("User[id=%s, name=%s, age=%s, email=%s]",
17 | demoProperties.getId(), demoProperties.getName(), demoProperties.getAge(), demoProperties.getEmail());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/AspectTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun;
2 |
3 | import com.rhwayfun.springboot.quickstart.aspect.StatsService;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 | import java.time.LocalDateTime;
8 |
9 | /**
10 | * Created by chubin on 2017/3/19.
11 | */
12 | public class AspectTest {
13 |
14 | private static Logger log = LoggerFactory.getLogger(AspectTest.class);
15 |
16 | public static void main(String[] args) {
17 | AspectTest.print();
18 | }
19 |
20 | @StatsService
21 | public static void print(){
22 | log.info("Now: {}", LocalDateTime.now());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/masterslave/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * 程序入口
8 | *
9 | * @author rhwayfun
10 | * @since 0.0.1
11 | */
12 | @SpringBootApplication
13 | public class Application {
14 |
15 | public static void main(String[] args) throws InterruptedException {
16 | SpringApplication.run(Application.class, args);
17 | Thread.sleep(Long.MAX_VALUE);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/java/com/rhwayfun/spring/boot/custom/schema/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.spring.boot.custom.schema;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.ImportResource;
6 |
7 | @SpringBootApplication
8 | @ImportResource(locations = {"classpath:spring/custom-spring-schema.xml"})
9 | public class Application {
10 |
11 | public static void main(String[] args) throws InterruptedException {
12 | SpringApplication.run(Application.class, args);
13 | Thread.sleep(Long.MAX_VALUE);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq-starter/src/main/java/com/rhwayfun/springboot/rocketmq/starter/constants/RocketMqContent.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.starter.constants;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.serializer.SerializerFeature;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * @author rhwayfun
10 | * @since 0.0.1
11 | */
12 | public class RocketMqContent implements Serializable {
13 |
14 | private static final long serialVersionUID = 1L;
15 |
16 | @Override
17 | public String toString() {
18 | return JSON.toJSONString(this, SerializerFeature.NotWriteDefaultValue);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/datasource/constants/DataSourceConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.datasource.constants;
2 |
3 | /**
4 | * Created by chubin on 2017/7/29.
5 | */
6 | public abstract class DataSourceConstants {
7 |
8 | public static final String MAPPER_PACKAGE = "com.rhwayfun.springboot.datasource";
9 | public static final String MAPPER_SECURITY_PACKAGE = "com.rhwayfun.springboot.security.datasource.mapper";
10 | public static final String MAPPER_LOCATION = "classpath:mapper/mybatis/*.xml";
11 | public static final String MAPPER_SECURITY_LOCATION = "classpath:mapper/security/*.xml";
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/en/PatternLayoutEn.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.en;
2 |
3 | /**
4 | * @author rhwayfun
5 | * @since 0.0.1
6 | */
7 | public enum PatternLayoutEn {
8 | /**
9 | * default
10 | */
11 | COMMON("%d %p [%t] %c{10}:%M:%L %m%n");
12 |
13 | private String layout;
14 |
15 | public String getLayout() {
16 | return layout;
17 | }
18 |
19 | public void setLayout(String layout) {
20 | this.layout = layout;
21 | }
22 |
23 | PatternLayoutEn(String layout) {
24 | this.layout = layout;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2-config/src/main/java/com/rhwayfun/springboot/logging/log4j2/config/BigdataUtilImpl.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.logging.log4j2.config;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 |
7 | /**
8 | * @author rhwayfun
9 | * @since 0.0.1
10 | */
11 | public class BigdataUtilImpl {
12 |
13 | /** Logger */
14 | private static Logger logger = LoggerFactory.getLogger(BigdataUtilImpl.class);
15 |
16 | public static void logAction(Object o) {
17 | for (int i = 0; i < 100; i++) {
18 | logger.info(logger.getName() + JSON.toJSONString(o));
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2-config/src/main/java/com/rhwayfun/springboot/logging/log4j2/config/Log4j2Plugin.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.logging.log4j2.config;
2 |
3 | import org.apache.logging.log4j.core.config.ConfigurationFactory;
4 | import org.apache.logging.log4j.core.config.Order;
5 | import org.apache.logging.log4j.core.config.plugins.Plugin;
6 |
7 | import java.lang.annotation.*;
8 |
9 | /**
10 | * @author rhwayfun
11 | * @since 0.0.1
12 | */
13 | @Documented
14 | @Retention(RetentionPolicy.RUNTIME)
15 | @Target(ElementType.TYPE)
16 | @Plugin(name = "CustomConfigurationFactory", category = ConfigurationFactory.CATEGORY)
17 | @Order(50)
18 | public @interface Log4j2Plugin {
19 | }
20 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-consumer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # Spring boot application
2 | spring.application.name=spring-boot-dubbo-annotation-consumer
3 |
4 | # Dubbo Config properties
5 | ## ApplicationConfig Bean
6 | dubbo.application.id=spring-boot-dubbo-annotation-consumer
7 | dubbo.application.name=spring-boot-dubbo-annotation-consumer
8 |
9 | ## ProtocolConfig Bean
10 | dubbo.protocol.id=dubbo
11 | dubbo.protocol.name=dubbo
12 | dubbo.protocol.port=20880
13 |
14 | # Dubbo Endpoint (default status is disable)
15 | endpoints.dubbo.enabled=true
16 |
17 | # Dubbo Health
18 | ## StatusChecker Name defaults (default : "memory", "load" )
19 | management.health.dubbo.status.defaults=memory
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/masterslave/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.mapper;
2 |
3 | import com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.entity.UserEntity;
4 | import org.apache.ibatis.annotations.Mapper;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @Mapper
11 | public interface UserMapper {
12 |
13 | void createIfNotExistsTable();
14 |
15 | void truncateTable();
16 |
17 | Long insert(UserEntity model);
18 |
19 | UserEntity find(Long userId);
20 |
21 | void delete(Long userId);
22 |
23 | void dropTable();
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/testng/TestngDemo1.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.testng;
2 |
3 | import org.junit.AfterClass;
4 | import org.junit.BeforeClass;
5 | import org.testng.annotations.Test;
6 |
7 | import java.time.LocalDateTime;
8 |
9 | /**
10 | * Created by chubin on 2017/3/28.
11 | */
12 | public class TestngDemo1 {
13 |
14 | @BeforeClass
15 | public void before(){
16 | System.out.println("before:" + LocalDateTime.now());
17 | }
18 |
19 | @Test
20 | public void test(){
21 | System.out.println("test:" + LocalDateTime.now());
22 | }
23 |
24 | @AfterClass
25 | public void after(){
26 | System.out.println("after:" + LocalDateTime.now());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/druid/DruidStatsFilter.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.druid;
2 |
3 | import com.alibaba.druid.support.http.WebStatFilter;
4 |
5 | import javax.servlet.annotation.WebFilter;
6 | import javax.servlet.annotation.WebInitParam;
7 |
8 | /**
9 | * druid监控Filter
10 | *
11 | * @author happyxiaofan
12 | * @since 0.0.1
13 | */
14 | @WebFilter(filterName="druidWebStatFilter",urlPatterns="/*",
15 | initParams={
16 | @WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略资源
17 | })
18 | public class DruidStatsFilter extends WebStatFilter {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-provider/src/main/java/com/rhwayfun/springboot/dubbo/annotation/provider/DemoProviderImpl.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.provider;
2 |
3 | import com.alibaba.dubbo.config.annotation.Service;
4 | import com.rhwayfun.springboot.dubbo.annotation.api.DemoProvider;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | @Service(
11 | version = "1.0.0",
12 | application = "${dubbo.application.id}",
13 | protocol = "${dubbo.protocol.id}",
14 | registry = "${dubbo.registry.id}"
15 | )
16 | public class DemoProviderImpl implements DemoProvider {
17 |
18 | @Override
19 | public String sayHello(String name) {
20 | return "Hello " + name;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-provider/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # Spring boot application
2 | spring.application.name=spring-boot-dubbo-annotation-provider
3 |
4 | # Base packages to scan Dubbo Components (e.g., @Service, @Reference)
5 | dubbo.scan.basePackages=com.rhwayfun.springboot.dubbo.annotation.provider
6 |
7 | # Dubbo Config properties
8 | ## ApplicationConfig Bean
9 | dubbo.application.id=spring-boot-dubbo-annotation-provider
10 | dubbo.application.name=spring-boot-dubbo-annotation-provider
11 |
12 | ## ProtocolConfig Bean
13 | dubbo.protocol.id=dubbo
14 | dubbo.protocol.name=dubbo
15 | dubbo.protocol.port=20880
16 | dubbo.protocol.status=server
17 |
18 | ## RegistryConfig Bean
19 | dubbo.registry.id=my-registry
20 | dubbo.registry.address=N/A
--------------------------------------------------------------------------------
/spring-boot-rocketmq/src/main/java/com/rhwayfun/springboot/rocketmq/mq/DemoRocketMqContent.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.mq;
2 |
3 |
4 | import io.github.rhwayfun.springboot.rocketmq.starter.constants.RocketMqContent;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | public class DemoRocketMqContent extends RocketMqContent {
11 |
12 | private int cityId;
13 | private String desc;
14 |
15 | public int getCityId() {
16 | return cityId;
17 | }
18 |
19 | public void setCityId(int cityId) {
20 | this.cityId = cityId;
21 | }
22 |
23 | public String getDesc() {
24 | return desc;
25 | }
26 |
27 | public void setDesc(String desc) {
28 | this.desc = desc;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/source/src/main/resources/disconf.properties:
--------------------------------------------------------------------------------
1 | # 是否使用远程配置文件
2 | # true(默认)会从远程获取配置 false则直接获取本地配置
3 | disconf.enable.remote.conf=true
4 |
5 | # 配置服务器的 HOST,用逗号分隔 127.0.0.1:8000,127.0.0.1:8000
6 | disconf.conf_server_host=127.0.0.1:8091
7 |
8 | # 版本, 请采用 X_X_X_X 格式
9 | disconf.version=1_0_0_0
10 |
11 | # APP 请采用 产品线_服务名 格式
12 | disconf.app=springboot-learning-example
13 |
14 | # 环境
15 | disconf.env=rd
16 |
17 | # debug
18 | disconf.debug=true
19 |
20 | # 忽略哪些分布式配置,用逗号分隔
21 | disconf.ignore=
22 |
23 | # 获取远程配置 重试次数,默认是3次
24 | disconf.conf_server_url_retry_times=1
25 |
26 | # 获取远程配置 重试时休眠时间,默认是5秒
27 | disconf.conf_server_url_retry_sleep_seconds=1
28 |
29 | # 应用本身的配置文件
30 | disconf.app_conf_files_name=app.properties
31 |
32 | # 开关配置
33 | disconf.app_commom_files_name=common.properties
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/security/config/WebMvcConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.security.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
6 |
7 | /**
8 | * Created by chubin on 2017/8/19.
9 | */
10 | @Configuration
11 | public class WebMvcConfig extends WebMvcConfigurerAdapter {
12 | /**
13 | * 统一注册纯RequestMapping跳转View的Controller
14 | */
15 | @Override
16 | public void addViewControllers(ViewControllerRegistry registry) {
17 | registry.addViewController("/login").setViewName("/login");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/java/com/rhwayfun/springboot/mybatis/annotation/constants/DataSourceConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.annotation.constants;
2 |
3 | /**
4 | * 数据源相关常量
5 | *
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | public abstract class DataSourceConstants {
10 |
11 | /**
12 | * 数据源配置前缀
13 | *
14 | */
15 | public static final String DATASOURCE_PREFIX = "mybatis.datasource";
16 |
17 | /**
18 | * MySQL驱动
19 | *
20 | */
21 | public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
22 |
23 | /**
24 | * Mybatis Mapper接口路径
25 | *
26 | */
27 | public static final String MAPPER_PACKAGE = "com.rhwayfun.springboot.mybatis.annotation.mapper";
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/consumer/src/main/resources/dubbo-consumer.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/costants/DataSourceConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.costants;
2 |
3 | /**
4 | * 数据源相关常量
5 | *
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | public abstract class DataSourceConstants {
10 |
11 | /**
12 | * 数据源配置前缀
13 | *
14 | */
15 | public static final String DATASOURCE_PREFIX = "mybatis.datasource";
16 |
17 | /**
18 | * MySQL驱动
19 | *
20 | */
21 | public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
22 |
23 | /**
24 | * Mybatis Mapper接口路径
25 | *
26 | */
27 | public static final String MAPPER_PACKAGE = "com.rhwayfun.springboot.mybatis.shardingjdbc.mapper";
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/source/src/main/resources/config/application.properties:
--------------------------------------------------------------------------------
1 | env=dev
2 | spring.application.name=springboot-learning-example
3 |
4 | spring.mvc.view.prefix=/WEB-INF/jsp/
5 | spring.mvc.view.suffix=.jsp
6 | server.port=9999
7 |
8 | logging.path=C:/logs
9 |
10 | mybatis.datasource.url=jdbc:mysql://127.0.0.1:3306/mybatis?useUnicode=true&characterEncoding=utf8
11 | mybatis.datasource.username=root
12 | mybatis.datasource.password=1209
13 | mybatis.datasource.driverClassName=com.mysql.jdbc.Driver
14 |
15 | security.datasource.url=jdbc:mysql://127.0.0.1:3306/security?useUnicode=true&characterEncoding=utf8
16 | security.datasource.username=root
17 | security.datasource.password=1209
18 | security.datasource.driverClassName=com.mysql.jdbc.Driver
19 |
20 | security.user.name=admin
21 | security.user.password=123456
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/retry/web/RetryController.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.retry.web;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * Created by ZhongCB on 2017/9/7.
9 | */
10 | @RestController
11 | public class RetryController {
12 |
13 | private final RetryService retryService;
14 |
15 | @Autowired
16 | public RetryController(RetryService retryService) {
17 | this.retryService = retryService;
18 | }
19 |
20 | @GetMapping("/randomNum")
21 | public int randomNum() throws Exception {
22 | return retryService.randomNum();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/springboot/quickstart/mockito/BaseMockitoTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import org.junit.Before;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.InjectMocks;
6 | import org.mockito.Mock;
7 | import org.mockito.junit.MockitoJUnitRunner;
8 |
9 | /**
10 | * Created by chubin on 2017/4/9.
11 | */
12 | @RunWith(MockitoJUnitRunner.class) // 使用这个注解在使用@Mock注解创建的对象时不会NPE
13 | public abstract class BaseMockitoTest {
14 |
15 | @InjectMocks
16 | protected UserService userService;
17 |
18 | @Mock
19 | protected UserDAO userDAO;
20 |
21 | @InjectMocks
22 | protected MainService mainService;
23 |
24 | @Before
25 | public void setUp(){
26 | mainService.setUserService(userService);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-consumer/src/main/java/com/rhwayfun/springboot/dubbo/annotation/consumer/service/DemoConsumer.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.consumer.service;
2 |
3 | import com.alibaba.dubbo.config.annotation.Reference;
4 | import com.rhwayfun.springboot.dubbo.annotation.api.DemoProvider;
5 | import org.springframework.stereotype.Component;
6 |
7 | /**
8 | * @author rhwayfun
9 | * @since 0.0.1
10 | */
11 | @Component
12 | public class DemoConsumer {
13 |
14 | @Reference(version = "1.0.0",
15 | application = "${dubbo.application.id}",
16 | url = "dubbo://localhost:20880")
17 | private DemoProvider demoProvider;
18 |
19 | public String sayHi(String name) {
20 | return demoProvider.sayHello(name);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/java/com/rhwayfun/spring/boot/custom/schema/spring/PeopleBean.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.spring.boot.custom.schema.spring;
2 |
3 | /**
4 | * @author rhwayfun
5 | * @since 0.0.1
6 | */
7 | public class PeopleBean {
8 | private String id;
9 | private String name;
10 | private Integer age;
11 |
12 | public String getId() {
13 | return id;
14 | }
15 |
16 | public void setId(String id) {
17 | this.id = id;
18 | }
19 |
20 | public String getName() {
21 | return name;
22 | }
23 |
24 | public void setName(String name) {
25 | this.name = name;
26 | }
27 |
28 | public Integer getAge() {
29 | return age;
30 | }
31 |
32 | public void setAge(Integer age) {
33 | this.age = age;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/retry/RetryTestService.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.retry;
2 |
3 | import org.springframework.retry.annotation.Recover;
4 | import org.springframework.retry.annotation.Retryable;
5 |
6 | /**
7 | * Created by chubin on 2017/8/27.
8 | */
9 | public class RetryTestService {
10 |
11 | @Retryable(IllegalArgumentException.class)
12 | public int calc(int len) throws Exception {
13 | System.out.println("retry success!");
14 | if (len > 2) throw new IllegalArgumentException(len + " is " + len + "!");
15 | return len;
16 | }
17 |
18 | @Recover
19 | public int recover(IllegalArgumentException e, int len){
20 | System.out.println("recover method call success!");
21 | return len;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/appender/impl/WarnAppenderFactory.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.appender.impl;
2 |
3 | import io.github.rhwayfun.springboot.log4j2.integration.appender.AbstractAppenderFactory;
4 | import io.github.rhwayfun.springboot.log4j2.integration.en.AppenderTypeEn;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | public class WarnAppenderFactory extends AbstractAppenderFactory {
11 |
12 | @Override
13 | protected boolean isAppropriate(AppenderTypeEn type) {
14 | return type == AppenderTypeEn.WARN_APPENDER;
15 | }
16 |
17 | @Override
18 | protected String getCurrentLogFileName() {
19 | return getLogFilePath() + getProjectName() + "-warn.log";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/appender/impl/ErrorAppenderFactory.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.appender.impl;
2 |
3 | import io.github.rhwayfun.springboot.log4j2.integration.appender.AbstractAppenderFactory;
4 | import io.github.rhwayfun.springboot.log4j2.integration.en.AppenderTypeEn;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | public class ErrorAppenderFactory extends AbstractAppenderFactory {
11 |
12 | @Override
13 | protected boolean isAppropriate(AppenderTypeEn type) {
14 | return type == AppenderTypeEn.ERROR_APPENDER;
15 | }
16 |
17 | @Override
18 | protected String getCurrentLogFileName() {
19 | return getLogFilePath() + getProjectName() + "-error.log";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/appender/impl/InfoAppenderFactory.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.appender.impl;
2 |
3 | import io.github.rhwayfun.springboot.log4j2.integration.appender.AbstractAppenderFactory;
4 | import io.github.rhwayfun.springboot.log4j2.integration.en.AppenderTypeEn;
5 |
6 | /**
7 | * @author rhwayfun
8 | * @since 0.0.1
9 | */
10 | public class InfoAppenderFactory extends AbstractAppenderFactory {
11 |
12 | @Override
13 | protected boolean isAppropriate(AppenderTypeEn type) {
14 | return type == AppenderTypeEn.INFO_APPENDER;
15 | }
16 |
17 | @Override
18 | protected String getFilePattern(String currentLogFileName) {
19 | return currentLogFileName + "-%d{yyyy-MM-dd-HH}";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/masterslave/constants/DataSourceConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.constants;
2 |
3 | /**
4 | * 数据源相关常量
5 | *
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | public abstract class DataSourceConstants {
10 |
11 | /**
12 | * 数据源配置前缀
13 | *
14 | */
15 | public static final String DATASOURCE_PREFIX = "mybatis.datasource";
16 |
17 | /**
18 | * MySQL驱动
19 | *
20 | */
21 | public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
22 |
23 | /**
24 | * Mybatis Mapper接口路径
25 | *
26 | */
27 | public static final String MAPPER_PACKAGE = "com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.mapper";
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/docs/sql/security/init.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE `g_authority` (
2 | `id` int(11) NOT NULL,
3 | `auth_id` int(11) DEFAULT NULL,
4 | `auth_name` varchar(45) DEFAULT NULL,
5 | PRIMARY KEY (`id`),
6 | KEY `IDX_AUTHORITY` (`auth_id`,`auth_name`)
7 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
8 |
9 | CREATE TABLE `g_users` (
10 | `id` int(11) NOT NULL COMMENT 'Id,自增主键',
11 | `user_id` int(11) DEFAULT NULL COMMENT '用户id',
12 | `user_name` varchar(45) DEFAULT NULL COMMENT '用户名称',
13 | PRIMARY KEY (`id`),
14 | KEY `IDX_USER_ID` (`user_id`,`user_name`)
15 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
16 |
17 | CREATE TABLE `r_auth_user` (
18 | `id` int(11) NOT NULL,
19 | `user_id` int(11) DEFAULT NULL,
20 | `auth_id` int(11) DEFAULT NULL,
21 | PRIMARY KEY (`id`),
22 | KEY `IDX_USER_AUTH` (`user_id`,`auth_id`)
23 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-log4j2-integration
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-log4j2
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/provider/src/main/resources/dubbo-provider.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/source/src/main/resources/static/js/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by chubin on 2017/2/12.
3 | */
4 |
5 | $(document).ready(function(){
6 | window.location.href("home.jsp")
7 | });
8 |
9 | /*
10 | function yes() {
11 | var body = "";
12 | var users = $('#users');
13 | var name = $('#name').val();
14 | var age = $('#age').val();
15 | $.ajax({
16 | type: 'post',
17 | url: 'users',
18 | dataType: 'json',
19 | data:{
20 | name: name,
21 | age: age
22 | },
23 | success: function(data){
24 | $.each(data, function(i, user){
25 | var oldStr = "" + user.id + ", " + user.name + ", " + user.age + "
";
26 | body += oldStr;
27 | });
28 | //alert(body);
29 | users.html(body);
30 | }
31 | });
32 | }*/
33 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/security/domain/UserRole.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.security.domain;
2 |
3 | import com.rhwayfun.springboot.quickstart.security.datasource.model.User;
4 | import com.rhwayfun.springboot.quickstart.security.datasource.model.UserAuthority;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by chubin on 2017/8/13.
10 | */
11 | public class UserRole {
12 |
13 | private User user;
14 | private List roles;
15 |
16 | public User getUser() {
17 | return user;
18 | }
19 |
20 | public void setUser(User user) {
21 | this.user = user;
22 | }
23 |
24 | public List getRoles() {
25 | return roles;
26 | }
27 |
28 | public void setRoles(List roles) {
29 | this.roles = roles;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | sudo: false # faster builds
4 |
5 | services:
6 | - mysql # start mysql service
7 |
8 | before_install:
9 | - pip install --user codecov
10 | - mysql -e 'CREATE DATABASE springboot;' # create database springboot
11 | - mysql -e 'CREATE DATABASE springboot2;' # create database springboot2
12 | - mysql -e 'CREATE DATABASE ds_master_0;' # create database ds_master_0
13 | - mysql -e 'CREATE DATABASE ds_master_0_slave_0;' # create database ds_master_0_slave_0
14 | - mysql -e 'CREATE DATABASE ds_master_0_slave_1;' # create database ds_master_0_slave_1
15 | - mysql -e 'CREATE DATABASE ds_master_1;' # create database ds_master_1
16 | - mysql -e 'CREATE DATABASE ds_master_1_slave_0;' # create database ds_master_1_slave_0
17 | - mysql -e 'CREATE DATABASE ds_master_1_slave_1;' # create database ds_master_1_slave_1
18 |
19 |
20 | after_success:
21 | - codecov
--------------------------------------------------------------------------------
/source/src/main/resources/webapp/WEB-INF/jsp/login.jsp:
--------------------------------------------------------------------------------
1 |
2 |
3 | <%--<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
4 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>--%>
5 |
6 |
7 |
8 |
9 | Welcome SpringBoot
10 |
11 |
12 |
13 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/spring-boot-starter-rest/src/main/java/com/rhwayfun/springboot/starter/rest/web/controller/DemoController.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.starter.rest.web.controller;
2 |
3 | import com.rhwayfun.springboot.starter.DemoService;
4 | import org.springframework.web.bind.annotation.PathVariable;
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 |
9 | import javax.annotation.Resource;
10 |
11 | /**
12 | * @author happyxiaofan
13 | * @since 0.0.1
14 | */
15 | @RestController
16 | public class DemoController {
17 |
18 | @Resource
19 | private DemoService demoService;
20 |
21 | @RequestMapping("user-info/{id}")
22 | @ResponseBody
23 | public String userInfo(@PathVariable String id) {
24 | return demoService.userInfo();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-dubbo
13 | 0.0.1-SNAPSHOT
14 | pom
15 |
16 |
17 | api
18 | provider
19 | consumer
20 |
21 |
22 |
23 | 0.0.1-SNAPSHOT
24 |
25 |
26 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/retry/web/RetryService.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.retry.web;
2 |
3 | import org.springframework.retry.annotation.CircuitBreaker;
4 | import org.springframework.retry.annotation.Recover;
5 | import org.springframework.stereotype.Service;
6 |
7 | import java.time.LocalDateTime;
8 |
9 | /**
10 | * Created by ZhongCB on 2017/9/7.
11 | */
12 | @Service
13 | public class RetryService {
14 |
15 | @Recover
16 | public int fallBack() {
17 | return 2;
18 | }
19 |
20 | @CircuitBreaker(include = IllegalArgumentException.class, maxAttempts = 1, openTimeout = 10000L, resetTimeout = 5000L)
21 | public int randomNum() throws Exception {
22 | System.out.println("call randomNum..." + LocalDateTime.now());
23 | if (Math.random() > .5) {
24 | throw new IllegalArgumentException("Exception");
25 | }
26 | return 1;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/java/com/rhwayfun/springboot/mybatis/annotation/constants/SqlConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.annotation.constants;
2 |
3 | /**
4 | * Sql语句
5 | *
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | public abstract class SqlConstants {
10 |
11 | public static final String GET_ALL_SQL = "SELECT * FROM user";
12 |
13 | public static final String GET_ONE_SQL = "SELECT * FROM user WHERE user_id = #{userId}";
14 |
15 | public static final String INSERT_SQL = "INSERT INTO user(user_id,user_name,age,birth) VALUES(#{userId}, #{userName}, #{age}, #{birth})";
16 |
17 | public static final String UPDATE_SQL = "UPDATE user SET user_name=#{userName},age=#{age},birth=#{birth} WHERE user_id =#{userId}";
18 |
19 | public static final String DELETE_SQL = "DELETE FROM user WHERE user_id =#{userId}";
20 |
21 | public static final String DELETE_ALL_SQL = "DELETE FROM user";
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2-config/src/main/java/com/rhwayfun/springboot/logging/log4j2/config/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.logging.log4j2.config;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
6 |
7 | /**
8 | * 程序入口
9 | *
10 | * @author happyxiaofan
11 | * @since 0.0.1
12 | */
13 | @SpringBootApplication
14 | //@ConditionalOnClass(SpecificLog4j2Configuration.class)
15 | public class Application {
16 |
17 | static {
18 | //System.setProperty("log4j2.configurationFactory", "com.rhwayfun.springboot.logging.log4j2.config.SpecificLog4j2Configuration");
19 | System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
20 | }
21 |
22 | public static void main(String[] args) {
23 | SpringApplication.run(Application.class, args);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/resources/META-INF/people.xsd:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/disconf/ConfigTask.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.disconf;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | import javax.annotation.PostConstruct;
6 | import javax.annotation.Resource;
7 |
8 | /**
9 | * Created by chubin on 2017/6/11.
10 | */
11 | @Service
12 | public class ConfigTask {
13 |
14 | @Resource
15 | private PropertyUpdateCallBackV3 propertyUpdateCallBackV3;
16 |
17 | @Resource
18 | private JedisConfig jedisConfig;
19 |
20 | @PostConstruct
21 | public void execute() throws Exception{
22 | new Thread(new Runnable() {
23 | @Override
24 | public void run() {
25 | while (true) {
26 | //System.out.println("factor:" + propertyUpdateCallBackV3.getCalcFactorV2());
27 | //System.out.println("port:" + jedisConfig.getPort());
28 | }
29 | }
30 | }).start();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/en/LoggerTypeEn.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.en;
2 |
3 | import org.apache.logging.log4j.Level;
4 |
5 | /**
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | public enum LoggerTypeEn {
10 | /**
11 | * Spring
12 | */
13 | SPRING_LOGGER("org.springframework", Level.INFO);
14 |
15 | private String loggerName;
16 | private Level level;
17 |
18 | public String getLoggerName() {
19 | return loggerName;
20 | }
21 |
22 | public void setLoggerName(String loggerName) {
23 | this.loggerName = loggerName;
24 | }
25 |
26 | public Level getLevel() {
27 | return level;
28 | }
29 |
30 | public void setLevel(Level level) {
31 | this.level = level;
32 | }
33 |
34 | LoggerTypeEn(String loggerName, Level level) {
35 | this.loggerName = loggerName;
36 | this.level = level;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/aspect/StatsServiceInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.aspect;
2 |
3 | import org.aspectj.lang.ProceedingJoinPoint;
4 | import org.aspectj.lang.annotation.Around;
5 | import org.aspectj.lang.annotation.Aspect;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | /**
10 | * Created by chubin on 2017/3/19.
11 | */
12 | @Aspect
13 | public class StatsServiceInterceptor {
14 |
15 | /** Logger */
16 | private static Logger log = LoggerFactory.getLogger(StatsServiceInterceptor.class);
17 |
18 | @Around("execution(* *(..)) && @annotation(StatsService)")
19 | public Object invoke(ProceedingJoinPoint pjp) {
20 | try {
21 | log.info("before invoke target.");
22 | return pjp.proceed();
23 | } catch (Throwable e) {
24 | log.error("invoke occurs error:", e);
25 | return null;
26 | } finally {
27 | log.info("after invoke target.");
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/doamin/User.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.doamin;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Created by chubin on 2017/2/12.
9 | */
10 | @Data
11 | public class User {
12 | private String name;
13 | private int id;
14 | private int age;
15 | private List hobbies;
16 |
17 | public User() {
18 |
19 | }
20 |
21 | public User(Integer id, String name, List hobbies){
22 | this.id = id;
23 | this.name = name;
24 | this.hobbies= hobbies;
25 | }
26 |
27 | public User(String name, int id, int age, List hobbies) {
28 | this.name = name;
29 | this.id = id;
30 | this.age = age;
31 | this.hobbies = hobbies;
32 | }
33 |
34 | public User(int id) {
35 | this.id = id;
36 | }
37 |
38 | public User(String name, int id, int age) {
39 | this.name = name;
40 | this.id = id;
41 | this.age = age;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/Application.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.web.servlet.ServletComponentScan;
6 |
7 | /**
8 | * 程序入口
9 | *
10 | * @author happyxiaofan
11 | * @since 0.0.1
12 | */
13 | @SpringBootApplication
14 | /**
15 | * 使用注解@ServletComponentScan
16 | * 如果不是使用配置的方式,注解@WebServlet/@WebFilter添加Servlet或Filter,需要添加这个注解启用Servlet扫描
17 | * @see com.rhwayfun.springboot.mybatis.shardingjdbc.druid.DruidStatsConfig
18 | * @see com.rhwayfun.springboot.mybatis.shardingjdbc.druid.DruidStatsServlet
19 | * @see com.rhwayfun.springboot.mybatis.shardingjdbc.druid.DruidStatsFilter
20 | */
21 | public class Application {
22 |
23 | public static void main(String[] args) throws InterruptedException {
24 | SpringApplication.run(Application.class, args);
25 | Thread.sleep(Long.MAX_VALUE);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/druid/DruidStatsServlet.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.druid;
2 |
3 | import com.alibaba.druid.support.http.StatViewServlet;
4 |
5 | import javax.servlet.annotation.WebInitParam;
6 | import javax.servlet.annotation.WebServlet;
7 |
8 | /**
9 | * druid监控Servlet
10 | *
11 | * @author happyxiaofan
12 | * @since 0.0.1
13 | */
14 | @WebServlet(urlPatterns = "/druid/*",
15 | initParams={
16 | //@WebInitParam(name="allow",value="192.168.125.120,127.0.0.1"),// IP白名单 (没有配置或者为空,则允许所有访问)
17 | @WebInitParam(name="deny",value="192.168.16.111"),// IP黑名单 (存在共同时,deny优先于allow)
18 | @WebInitParam(name="loginUsername",value="happyxiaofan"),// 用户名
19 | @WebInitParam(name="loginPassword",value="springboot"),// 密码
20 | @WebInitParam(name="resetEnable",value="false")// 禁用HTML页面上的“Reset All”功能
21 | })
22 | public class DruidStatsServlet extends StatViewServlet {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-boot-starter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-starter
13 | jar
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-autoconfigure
19 |
20 |
21 |
22 |
23 |
24 |
25 | org.apache.maven.plugins
26 | maven-compiler-plugin
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-multidatasource/src/main/java/com/rhwayfun/springboot/mybatis/multidatasource/constants/DataSourceConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.multidatasource.constants;
2 |
3 | /**
4 | * 数据源相关常量
5 | *
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | public abstract class DataSourceConstants {
10 |
11 | /**
12 | * 数据源配置前缀
13 | *
14 | */
15 | public static final String DATASOURCE_PREFIX = "mybatis.datasource";
16 |
17 | /**
18 | * 另外一个数据源配置前缀
19 | *
20 | */
21 | public static final String DATASOURCE2_PREFIX = "mybatis.datasource2";
22 |
23 | /**
24 | * MySQL驱动
25 | *
26 | */
27 | public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
28 |
29 | /**
30 | * Mybatis Mapper接口路径
31 | *
32 | */
33 | public static final String MAPPER_PACKAGE = "com.rhwayfun.springboot.mybatis.multidatasource.mapper.user";
34 |
35 | /**
36 | * Mybatis Mapper接口路径
37 | *
38 | */
39 | public static final String MAPPER2_PACKAGE = "com.rhwayfun.springboot.mybatis.multidatasource.mapper.city";
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spring-boot-starter/src/main/java/com/rhwayfun/springboot/starter/DemoProperties.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.starter;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 |
5 | /**
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | @ConfigurationProperties(prefix = "demo.user")
10 | public class DemoProperties {
11 |
12 | private String id;
13 |
14 | private String name;
15 |
16 | private int age;
17 |
18 | private String email;
19 |
20 | public String getId() {
21 | return id;
22 | }
23 |
24 | public void setId(String id) {
25 | this.id = id;
26 | }
27 |
28 | public String getName() {
29 | return name;
30 | }
31 |
32 | public void setName(String name) {
33 | this.name = name;
34 | }
35 |
36 | public int getAge() {
37 | return age;
38 | }
39 |
40 | public void setAge(int age) {
41 | this.age = age;
42 | }
43 |
44 | public String getEmail() {
45 | return email;
46 | }
47 |
48 | public void setEmail(String email) {
49 | this.email = email;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/test/java/com/rhwayfun/spring/boot/custom/schema/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.spring.boot.custom.schema;
2 |
3 | import com.rhwayfun.spring.boot.custom.schema.spring.PeopleBean;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.context.ApplicationContext;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 |
11 | import javax.annotation.Resource;
12 |
13 | /**
14 | * @author rhwayfun
15 | * @since 0.0.1
16 | */
17 | @RunWith(SpringRunner.class)
18 | @SpringBootTest
19 | public class ApplicationTest {
20 |
21 | @Resource
22 | private ApplicationContext applicationContext;
23 |
24 | @Test
25 | public void testGetPeopleBean() throws Exception {
26 | PeopleBean peopleBean = (PeopleBean) applicationContext.getBean("peopleBean");
27 | Assert.assertEquals(peopleBean.getId(), "peopleBean");
28 | Assert.assertEquals(peopleBean.getName(), "rhwayfun");
29 | Assert.assertEquals(String.valueOf(peopleBean.getAge()), "25");
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | spring-boot-learning-examples
8 | com.rhwayfun
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | spring-boot-dubbo-annotation
13 | pom
14 |
15 |
16 | dubbo-api
17 | dubbo-consumer
18 | dubbo-provider
19 |
20 |
21 |
22 |
23 |
24 | com.alibaba.boot
25 | dubbo-spring-boot-starter
26 | 0.1.0
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/mockito/UserDAOImpl.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 | import org.springframework.stereotype.Repository;
5 |
6 | import java.util.Date;
7 | import java.util.List;
8 |
9 | /**
10 | * Created by chubin on 2017/4/16.
11 | */
12 | @Repository
13 | public class UserDAOImpl implements UserDAO{
14 |
15 | @Override
16 | public User findById(int id) {
17 | return new User("Tim", 2, 10);
18 | }
19 |
20 | @Override
21 | public void deleteById(int id) {
22 |
23 | }
24 |
25 | @Override
26 | public List findLists(int... ids) {
27 | return null;
28 | }
29 |
30 | @Override
31 | public boolean modifyUser(User user) {
32 | return false;
33 | }
34 |
35 | @Override
36 | public boolean modifyUser(Integer id, String name, List hobbies) {
37 | return false;
38 | }
39 |
40 | @Override
41 | public User findByName(String name) {
42 | return null;
43 | }
44 |
45 | public final Date getNow() {
46 | return new Date();
47 | }
48 | }
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/memory/MemorySizes.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.memory;
2 |
3 | import java.util.IdentityHashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Created by chubin on 2017/8/20.
8 | */
9 | public class MemorySizes {
10 | private final Map primitiveSizes = new IdentityHashMap() {
11 | {
12 | put(boolean.class, new Integer(1));
13 | put(byte.class, new Integer(1));
14 | put(char.class, new Integer(2));
15 | put(short.class, new Integer(2));
16 | put(int.class, new Integer(4));
17 | put(float.class, new Integer(4));
18 | put(double.class, new Integer(8));
19 | put(long.class, new Integer(8));
20 | }
21 | };
22 |
23 | public int getPrimitiveFieldSize(Class clazz) {
24 | return ((Integer) primitiveSizes.get(clazz)).intValue();
25 | }
26 |
27 | public int getPrimitiveArrayElementSize(Class clazz) {
28 | return getPrimitiveFieldSize(clazz);
29 | }
30 |
31 | public int getPointerSize() {
32 | return 4;
33 | }
34 |
35 | public int getClassSize() {
36 | return 8;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/consumer/src/test/java/com/rhwayfun/springboot/dubbo/consumer/DubboTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.consumer;
2 |
3 | import com.rhwayfun.springboot.dubbo.api.DemoProvider;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | import javax.annotation.Resource;
10 |
11 | import static org.junit.Assert.assertEquals;
12 | import static org.junit.Assert.assertNull;
13 |
14 | /**
15 | * @author rhwayfun
16 | * @since 0.0.1
17 | */
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest
20 | public class DubboTest {
21 |
22 | private static final String PARAM = "Dubbo";
23 |
24 | @Resource
25 | private DemoProvider demoProvider;
26 |
27 | @Test
28 | public void testDubbo() throws Exception {
29 | String result = null;
30 | try {
31 | result = demoProvider.sayHello(PARAM);
32 | if (result != null) {
33 | assertEquals("Hello " + PARAM, result);
34 | }
35 | } catch (Exception e) {
36 | assertNull(result);
37 | }
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/memory/MemoryCounterTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.memory;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * Created by chubin on 2017/8/20.
7 | */
8 | public class MemoryCounterTest {
9 |
10 | private static final MemoryCounter mc = new MemoryCounter();
11 |
12 | public static void main(String[] args) {
13 | RiderBasicInfoDTO obj = new RiderBasicInfoDTO();
14 | obj.setCityId(1);
15 | obj.setBlackList("1");
16 | obj.setClient("IOS");
17 | obj.setCode("test");
18 | obj.setFeature("test");
19 | obj.setId(1);
20 | obj.setImei("aaaaaaaaa");
21 | obj.setJobNumber("abc");
22 | obj.setLevel((byte) 5);
23 | obj.setMobile("18073152816");
24 | obj.setName("test");
25 | obj.setRegionId(1);
26 | obj.setOrderCelling(5);
27 | obj.setStatus((byte) 5);
28 | obj.setTakeMode((byte) 0);
29 | obj.setType((byte) 1);
30 | obj.setVerified((byte) 5);
31 | obj.setVerifiedTm(new Date());
32 | obj.setInviteId("test");
33 | long estimate = mc.estimate(obj);
34 | System.out.println(estimate);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/apache-rocketmq-starter-guide.md:
--------------------------------------------------------------------------------
1 | # Maven
2 |
3 | 引用RocketMQ Spring Boot Starter依赖:
4 |
5 | ```java
6 |
7 |
8 | com.rhwayfun
9 | spring-boot-rocketmq-starter
10 | 0.0.1-SNAPSHOT
11 |
12 |
13 | ```
14 |
15 | # Consumer
16 |
17 | 继承自`com.rhwayfun.springboot.rocketmq.starter.common.AbstractRocketMqConsumer`
18 |
19 | 使用示例:
20 |
21 | ```java
22 | @Component
23 | public class DemoRocketMqConsumerExample
24 | extends AbstractRocketMqConsumer {
25 |
26 | @Override
27 | public Map> subscribeTopicTags() {
28 | Map> topicSetMap = new HashMap<>();
29 | Set tagSet = new HashSet<>();
30 | tagSet.add("TagA");
31 | tagSet.add("TagB");
32 | topicSetMap.put("TopicA", tagSet);
33 | return topicSetMap;
34 | }
35 |
36 | @Override
37 | public boolean handle(String topic, String tag, DemoRocketMqContent content, MessageExt msg) {
38 | logger.info("receive msg[{}], topic:{}, tag:{}, content:{}", msg, topic, tag, content);
39 | return true;
40 | }
41 |
42 | }
43 | ```
44 |
45 | # Producer
46 | 待补充。。。
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-consumer/src/test/java/com/rhwayfun/springboot/dubbo/annotation/consumer/DubboTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.dubbo.annotation.consumer;
2 |
3 | import com.rhwayfun.springboot.dubbo.annotation.consumer.service.DemoConsumer;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | import javax.annotation.Resource;
10 |
11 | import static org.junit.Assert.assertEquals;
12 | import static org.junit.Assert.assertNull;
13 |
14 | /**
15 | * @author rhwayfun
16 | * @since 0.0.1
17 | */
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest
20 | public class DubboTest {
21 |
22 | private static final String PARAM = "Dubbo";
23 |
24 | @Resource
25 | private DemoConsumer demoConsumer;
26 |
27 | @Test
28 | public void testDubbo() throws Exception {
29 | String result = null;
30 | try {
31 | result = demoConsumer.sayHi(PARAM);
32 | if (result != null) {
33 | assertEquals("Hello " + PARAM, result);
34 | }
35 | } catch (Exception e) {
36 | assertNull(result);
37 | }
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/spring-boot-starter/src/main/java/com/rhwayfun/springboot/starter/DemoServiceAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.starter;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 |
11 | /**
12 | * @author happyxiaofan
13 | * @since 0.0.1
14 | */
15 | @Configuration
16 | @EnableConfigurationProperties(DemoProperties.class)
17 | @ConditionalOnClass(DemoProperties.class)
18 | @ConditionalOnProperty(prefix = "demo.user", value = "enabled", matchIfMissing = true)
19 | public class DemoServiceAutoConfiguration {
20 |
21 | @Autowired
22 | private DemoProperties demoProperties;
23 |
24 | @Bean
25 | @ConditionalOnMissingBean(DemoService.class)
26 | public DemoService demoService() {
27 | DemoService demoService = new DemoService(demoProperties);
28 | return demoService;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/src/main/java/com/rhwayfun/spring/boot/custom/schema/spring/PeopleBeanDefinitionParser.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.spring.boot.custom.schema.spring;
2 |
3 | import org.springframework.beans.factory.support.BeanDefinitionBuilder;
4 | import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
5 | import org.springframework.util.StringUtils;
6 | import org.w3c.dom.Element;
7 |
8 | /**
9 | * @author rhwayfun
10 | * @since 0.0.1
11 | */
12 | public class PeopleBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
13 |
14 | @Override
15 | protected Class> getBeanClass(Element element) {
16 | return PeopleBean.class;
17 | }
18 |
19 | @Override
20 | protected void doParse(Element element, BeanDefinitionBuilder builder) {
21 | String id = element.getAttribute("id");
22 | String name = element.getAttribute("name");
23 | String age = element.getAttribute("age");
24 | if (StringUtils.hasText(id)) {
25 | builder.addPropertyValue("id", id);
26 | }
27 | if (StringUtils.hasText(name)) {
28 | builder.addPropertyValue("name", name);
29 | }
30 | if (StringUtils.hasText(age)) {
31 | builder.addPropertyValue("age", age);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq/src/main/java/com/rhwayfun/springboot/rocketmq/mq/DemoRocketMqProducerExample.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.mq;
2 |
3 | import io.github.rhwayfun.springboot.rocketmq.starter.common.DefaultRocketMqProducer;
4 | import org.apache.rocketmq.common.message.Message;
5 | import org.springframework.stereotype.Component;
6 |
7 | import javax.annotation.PostConstruct;
8 | import javax.annotation.Resource;
9 | import java.util.Timer;
10 | import java.util.TimerTask;
11 |
12 | /**
13 | * @author rhwayfun
14 | * @since 0.0.1
15 | */
16 | @Component
17 | public class DemoRocketMqProducerExample {
18 |
19 | @Resource
20 | private DefaultRocketMqProducer producer;
21 |
22 | @PostConstruct
23 | public void execute() {
24 | new Timer().schedule(new TimerTask() {
25 | @Override
26 | public void run() {
27 | DemoRocketMqContent content = new DemoRocketMqContent();
28 | content.setCityId(1);
29 | content.setDesc("城市");
30 | Message msg = new Message("TopicA", "TagA", content.toString().getBytes());
31 | boolean sendResult = producer.sendMsg(msg);
32 | System.out.println("发送结果:" + sendResult);
33 | }
34 | }, 0, 10000);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/kafka/config/KafkaConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.kafka.config;
2 |
3 | import org.apache.kafka.clients.producer.KafkaProducer;
4 | import org.springframework.beans.factory.annotation.Configurable;
5 | import org.springframework.boot.context.properties.ConfigurationProperties;
6 | import org.springframework.context.annotation.Bean;
7 |
8 | import java.util.Properties;
9 |
10 | /**
11 | * Created by chubin on 2017/7/30.
12 | */
13 | @Configurable
14 | @ConfigurationProperties(prefix = "kafka")
15 | public class KafkaConfig {
16 |
17 | private String bootstrapServers;
18 |
19 | @Bean
20 | public KafkaProducer kafkaProducer() {
21 | Properties props = new Properties();
22 | props.put("bootstrap.servers", bootstrapServers);
23 |
24 | props.put("key.serializer",
25 | "org.apache.kafka.common.serializa-tion.StringSerializer");
26 |
27 | props.put("value.serializer",
28 | "org.apache.kafka.common.serializa-tion.StringSerializer");
29 |
30 | return new KafkaProducer<>(props);
31 | }
32 |
33 | public String getBootstrapServers() {
34 | return bootstrapServers;
35 | }
36 |
37 | public void setBootstrapServers(String bootstrapServers) {
38 | this.bootstrapServers = bootstrapServers;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/doamin/CarBO.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.doamin;
2 |
3 | import javax.validation.constraints.Min;
4 | import javax.validation.constraints.NotNull;
5 | import javax.validation.constraints.Size;
6 |
7 | /**
8 | * Created by chubin on 2017/7/29.
9 | */
10 | public class CarBO {
11 |
12 | @NotNull
13 | private String manufacturer;
14 |
15 | @NotNull
16 | @Size(min = 2, max = 5)
17 | private String licensePlate;
18 |
19 | @Min(5)
20 | private int seatCount;
21 |
22 | public CarBO(String manufacturer, String licencePlate, int seatCount) {
23 | this.manufacturer = manufacturer;
24 | this.licensePlate = licencePlate;
25 | this.seatCount = seatCount;
26 | }
27 |
28 | public String getManufacturer() {
29 | return manufacturer;
30 | }
31 |
32 | public void setManufacturer(String manufacturer) {
33 | this.manufacturer = manufacturer;
34 | }
35 |
36 | public String getLicensePlate() {
37 | return licensePlate;
38 | }
39 |
40 | public void setLicensePlate(String licensePlate) {
41 | this.licensePlate = licensePlate;
42 | }
43 |
44 | public int getSeatCount() {
45 | return seatCount;
46 | }
47 |
48 | public void setSeatCount(int seatCount) {
49 | this.seatCount = seatCount;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/mockito/UserService.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Service;
6 |
7 | import javax.annotation.Resource;
8 | import java.util.List;
9 |
10 | /**
11 | * Created by chubin on 2017/3/26.
12 | */
13 | @Service
14 | public class UserService {
15 |
16 | @Resource
17 | private UserDAO userDAO;
18 |
19 | public void setUserDAO(UserDAO userDAO) {
20 | this.userDAO = userDAO;
21 | }
22 |
23 | public UserDAO getUserDAO() {
24 | return userDAO;
25 | }
26 |
27 | public User findById(int id){
28 | return userDAO.findById(id);
29 | }
30 |
31 | public void deleteById(int id){
32 | userDAO.deleteById(id);
33 | }
34 |
35 | public List findLists(int ... ids){
36 | return userDAO.findLists(ids);
37 | }
38 |
39 | public boolean modifyUser(User user){
40 | return userDAO.modifyUser(user);
41 | }
42 |
43 | public boolean modifyUser(Integer id, String name, List hobbies){
44 | return userDAO.modifyUser(id, name, hobbies);
45 | }
46 |
47 | public User findByName(String name) {
48 | return userDAO.findByName(name);
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq/src/main/java/com/rhwayfun/springboot/rocketmq/mq/DemoRocketMqConsumerExample.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.rocketmq.mq;
2 |
3 | import io.github.rhwayfun.springboot.rocketmq.starter.common.AbstractRocketMqConsumer;
4 | import org.apache.rocketmq.common.message.MessageExt;
5 | import org.springframework.stereotype.Component;
6 |
7 | import java.util.HashMap;
8 | import java.util.HashSet;
9 | import java.util.Map;
10 | import java.util.Set;
11 |
12 | /**
13 | * @author rhwayfun
14 | * @since 0.0.1
15 | */
16 | @Component
17 | public class DemoRocketMqConsumerExample
18 | extends AbstractRocketMqConsumer {
19 |
20 | @Override
21 | public Map> subscribeTopicTags() {
22 | Map> topicSetMap = new HashMap<>();
23 | Set tagSet = new HashSet<>();
24 | tagSet.add("TagA");
25 | tagSet.add("TagB");
26 | topicSetMap.put("TopicA", tagSet);
27 | return topicSetMap;
28 | }
29 |
30 | @Override
31 | public String getConsumerGroup() {
32 | return "spring-boot-test-consumer-group";
33 | }
34 |
35 | @Override
36 | public boolean consumeMsg(DemoRocketMqContent content, MessageExt msg) {
37 | logger.info("receive msg[{}], topic:{}, tag:{}, content:{}", msg, content);
38 | return false;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-multidatasource/src/main/java/com/rhwayfun/springboot/mybatis/multidatasource/mapper/user/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.multidatasource.mapper.user;
2 |
3 | import com.rhwayfun.springboot.mybatis.multidatasource.constants.SqlConstants;
4 | import com.rhwayfun.springboot.mybatis.multidatasource.entity.UserEntity;
5 | import org.apache.ibatis.annotations.*;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 用户DAO
11 | *
12 | * @author happyxiaofan
13 | * @since 0.0.1
14 | */
15 | public interface UserMapper {
16 |
17 | @Select(SqlConstants.GET_ALL_SQL)
18 | @Results(id = "userResultMap", value = {
19 | @Result(property = "userId", column = "user_id"),
20 | @Result(property = "userName", column = "user_name"),
21 | @Result(property = "age", column = "age"),
22 | @Result(property = "birth", column = "birth")
23 | })
24 | List getAll();
25 |
26 | @Select(SqlConstants.GET_ONE_SQL)
27 | @ResultMap(value = "userResultMap")
28 | UserEntity getOne(Long userId);
29 |
30 | @Insert(SqlConstants.INSERT_SQL)
31 | int insert(UserEntity user);
32 |
33 | @Update(SqlConstants.UPDATE_SQL)
34 | int update(UserEntity user);
35 |
36 | @Delete(SqlConstants.DELETE_SQL)
37 | int delete(Long userId);
38 |
39 | @Delete(SqlConstants.DELETE_ALL_SQL)
40 | void deleteAll();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/en/AppenderTypeEn.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.en;
2 |
3 | import org.apache.logging.log4j.Level;
4 |
5 | /**
6 | * @author rhwayfun
7 | * @since 0.0.1
8 | */
9 | public enum AppenderTypeEn {
10 | /**
11 | * CONSOLE
12 | */
13 | CONSOLE_APPENDER("console", Level.ALL, true),
14 | INFO_APPENDER("info", Level.INFO, true),
15 | WARN_APPENDER("warn", Level.WARN, true),
16 | ERROR_APPENDER("error", Level.ERROR, true);
17 | private String name;
18 | private Level level;
19 | private boolean subRootAppender;
20 |
21 | public String getName() {
22 | return name;
23 | }
24 |
25 | public void setName(String name) {
26 | this.name = name;
27 | }
28 |
29 | public Level getLevel() {
30 | return level;
31 | }
32 |
33 | public void setLevel(Level level) {
34 | this.level = level;
35 | }
36 |
37 | public boolean isSubRootAppender() {
38 | return subRootAppender;
39 | }
40 |
41 | public void setSubRootAppender(boolean subRootAppender) {
42 | this.subRootAppender = subRootAppender;
43 | }
44 |
45 | AppenderTypeEn(String name, Level level, boolean subRootAppender) {
46 | this.name = name;
47 | this.level = level;
48 | this.subRootAppender = subRootAppender;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/appender/impl/ConsoleAppenderFactory.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.appender.impl;
2 |
3 | import io.github.rhwayfun.springboot.log4j2.integration.appender.AbstractAppenderFactory;
4 | import io.github.rhwayfun.springboot.log4j2.integration.en.AppenderTypeEn;
5 | import org.apache.logging.log4j.core.Appender;
6 | import org.apache.logging.log4j.core.appender.ConsoleAppender;
7 | import org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy;
8 | import org.apache.logging.log4j.core.config.Configuration;
9 | import org.apache.logging.log4j.core.filter.ThresholdFilter;
10 | import org.apache.logging.log4j.core.layout.PatternLayout;
11 |
12 | /**
13 | * @author rhwayfun
14 | * @since 0.0.1
15 | */
16 | public class ConsoleAppenderFactory extends AbstractAppenderFactory {
17 |
18 | @Override
19 | protected boolean isAppropriate(AppenderTypeEn type) {
20 | return type == AppenderTypeEn.CONSOLE_APPENDER;
21 | }
22 |
23 | @Override
24 | protected Appender newAppender(String currentLogFileName, String logFilePattern, PatternLayout layout,
25 | TriggeringPolicy tp, ThresholdFilter thresholdFilter, String appenderName,
26 | Configuration config) {
27 | return ConsoleAppender.createDefaultAppenderForLayout(layout);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-multidatasource/src/main/java/com/rhwayfun/springboot/mybatis/multidatasource/mapper/city/CityMapper.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.multidatasource.mapper.city;
2 |
3 | import com.rhwayfun.springboot.mybatis.multidatasource.constants.SqlConstants;
4 | import com.rhwayfun.springboot.mybatis.multidatasource.entity.CityEntity;
5 | import org.apache.ibatis.annotations.*;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 城市DAO
11 | *
12 | * @author happyxiaofan
13 | * @since 0.0.1
14 | */
15 | public interface CityMapper {
16 |
17 | @Select(SqlConstants.CITY_GET_ALL_SQL)
18 | @Results(id = "cityResultMap", value = {
19 | @Result(property = "id", column = "id"),
20 | @Result(property = "name", column = "name"),
21 | @Result(property = "createTime", column = "create_time"),
22 | @Result(property = "modifyTime", column = "modify_time")
23 | })
24 | List getAll();
25 |
26 | @Select(SqlConstants.CITY_GET_ONE_SQL)
27 | @ResultMap(value = "cityResultMap")
28 | CityEntity getOne(Long userId);
29 |
30 | @Insert(SqlConstants.CITY_INSERT_SQL)
31 | int insert(CityEntity user);
32 |
33 | @Update(SqlConstants.CITY_UPDATE_SQL)
34 | int update(CityEntity user);
35 |
36 | @Delete(SqlConstants.CITY_DELETE_SQL)
37 | int delete(Long userId);
38 |
39 | @Delete(SqlConstants.CITY_DELETE_ALL_SQL)
40 | void deleteAll();
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/spring-boot-configuration/src/main/java/com/rhwayfun/springboot/configuration/random/RandomProperty.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.configuration.random;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | /**
7 | * 随机值
8 | * 使用@Configuration注解声明这是一个配置文件
9 | *
10 | * @author happyxiaofan
11 | * @since 0.0.1
12 | */
13 | @Configuration
14 | public class RandomProperty {
15 |
16 | @Value("${my.secret}")
17 | private String randomValue;
18 |
19 | @Value("${my.number}")
20 | private int randomInt;
21 |
22 | @Value("${my.bignumber}")
23 | private long randomLong;
24 |
25 | @Value("${my.uuid}")
26 | private String randomUUID;
27 |
28 | @Value("${my.number.less.than.ten}")
29 | private int randomIntRange;
30 |
31 | @Value("${my.number.in.range}")
32 | private int randomIntMaxMinRange;
33 |
34 | public String getRandomValue() {
35 | return randomValue;
36 | }
37 |
38 | public int getRandomInt() {
39 | return randomInt;
40 | }
41 |
42 | public long getRandomLong() {
43 | return randomLong;
44 | }
45 |
46 | public String getRandomUUID() {
47 | return randomUUID;
48 | }
49 |
50 | public int getRandomIntRange() {
51 | return randomIntRange;
52 | }
53 |
54 | public int getRandomIntMaxMinRange() {
55 | return randomIntMaxMinRange;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/masterslave/constants/SqlConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.constants;
2 |
3 | /**
4 | * Sql语句
5 | *
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | public abstract class SqlConstants {
10 |
11 | /**
12 | * TABLE >>>>>>>>>> t_user
13 | */
14 |
15 | public static final String USER_CREATE_SQL = "CREATE TABLE IF NOT EXISTS `t_user` (`id` bigint(20) AUTO_INCREMENT, `user_id` bigint(20) NOT NULL COMMENT '用户id',`city_id` int(11) DEFAULT NULL COMMENT '城市id',`user_name` varchar(15) DEFAULT NULL,`age` int(11) DEFAULT NULL COMMENT '年龄',`birth` date DEFAULT NULL COMMENT '生日',PRIMARY KEY (`id`))";
16 |
17 | public static final String GET_ALL_SQL = "SELECT * FROM t_user";
18 |
19 | public static final String GET_ONE_SQL = "SELECT * FROM t_user WHERE user_id = #{userId}";
20 |
21 | public static final String GET_LIMIT_ONE_SQL = "SELECT * FROM t_user LIMIT 1";
22 |
23 | public static final String INSERT_SLAVE_SQL = "INSERT INTO t_user(city_id,user_name,age,birth) VALUES(#{cityId}, #{userName}, #{age}, #{birth})";
24 |
25 | public static final String UPDATE_SQL = "UPDATE t_user SET user_name=#{userName},age=#{age},birth=#{birth} WHERE user_id =#{userId}";
26 |
27 | public static final String DELETE_SQL = "DELETE FROM t_user WHERE user_id =#{userId}";
28 |
29 | public static final String DELETE_ALL_SQL = "DELETE FROM t_user";
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-quickstart/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | spring-boot-learning-examples
8 | com.rhwayfun
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | spring-boot-quickstart
13 | 0.0.1-SNAPSHOT
14 | jar
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter-web
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-test
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-devtools
30 | true
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-maven-plugin
39 |
40 |
41 | org.jacoco
42 | jacoco-maven-plugin
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/spring-boot-custom-schema/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-custom-schema
13 | 0.0.1-SNAPSHOT
14 | jar
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-starter-test
25 |
26 |
27 |
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-maven-plugin
33 |
34 |
35 | org.jacoco
36 | jacoco-maven-plugin
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/mockito/MainService.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.stereotype.Component;
7 |
8 | import javax.annotation.Resource;
9 | import java.util.List;
10 |
11 | /**
12 | * Created by ZhongCB on 2017/4/5.
13 | */
14 | @Component
15 | public class MainService {
16 |
17 | /** Logger */
18 | private static Logger log = LoggerFactory.getLogger(MainService.class);
19 |
20 | @Resource
21 | private UserService userService;
22 |
23 | public User getUser(Integer userId){
24 | try {
25 | return userService.findById(userId);
26 | } catch (Exception e){
27 | log.error("occurs error:{}", userId, e);
28 | return null;
29 | }
30 | }
31 |
32 | public User getUser(String name){
33 | try {
34 | return userService.findByName(name);
35 | } catch (Exception e){
36 | log.error("occurs error:{}", name, e);
37 | return null;
38 | }
39 | }
40 |
41 | public boolean modify(Integer id, String name, List hobbies){
42 | boolean modify = userService.modifyUser(id, name, hobbies);
43 | log.info("modify user--:{},name,hobbies:{}", id, name, hobbies);
44 | return modify;
45 | }
46 |
47 | public void setUserService(UserService userService) {
48 | this.userService = userService;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2-config/src/main/java/com/rhwayfun/springboot/logging/log4j2/config/Log4j2Controller.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.logging.log4j2.config;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.Getter;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.ResponseBody;
12 | import org.springframework.web.bind.annotation.RestController;
13 |
14 | import java.util.Date;
15 |
16 | /**
17 | * @author rhwayfun
18 | * @since 0.0.1
19 | */
20 | @RestController
21 | public class Log4j2Controller {
22 | /** Logger */
23 | private static Logger logger = LoggerFactory.getLogger(Log4j2Controller.class);
24 |
25 | @RequestMapping("/{id}")
26 | @ResponseBody
27 | public String id(@PathVariable String id) {
28 | logger.info("test id:{}", id);
29 | BigdataUtilImpl.logAction(new BigDateObject(1, new Date()));
30 | try {
31 | if (Integer.parseInt(id) % 2 == 0) {
32 | throw new RuntimeException("非法id:" + id);
33 | }
34 | } catch (Exception e) {
35 | logger.error("参数非法", e);
36 | }
37 | return System.currentTimeMillis() + "," + id;
38 | }
39 |
40 | @Data
41 | @AllArgsConstructor
42 | public static class BigDateObject {
43 | private int id;
44 | private Date date;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/masterslave/mapper/UserRepository.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.mapper;
2 |
3 | import com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.constants.SqlConstants;
4 | import com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.entity.UserEntity;
5 | import org.apache.ibatis.annotations.*;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 用户DAO
11 | *
12 | * @author rhwayfun
13 | * @since 0.0.1
14 | */
15 | public interface UserRepository {
16 |
17 | @Select(SqlConstants.GET_ALL_SQL)
18 | @Results(id = "userResultMap", value = {
19 | @Result(property = "userId", column = "user_id"),
20 | @Result(property = "cityId", column = "city_id"),
21 | @Result(property = "userName", column = "user_name"),
22 | @Result(property = "age", column = "age"),
23 | @Result(property = "birth", column = "birth")
24 | })
25 | List selectAll();
26 |
27 | @Select(SqlConstants.GET_ONE_SQL)
28 | @ResultMap(value = "userResultMap")
29 | UserEntity find(Long userId);
30 |
31 | @Insert(SqlConstants.INSERT_SLAVE_SQL)
32 | @Options(useGeneratedKeys = true, keyProperty = "userId")
33 | int insert(UserEntity user);
34 |
35 | @Update(SqlConstants.UPDATE_SQL)
36 | int update(UserEntity user);
37 |
38 | @Delete(SqlConstants.DELETE_SQL)
39 | int delete(Long userId);
40 |
41 | @Delete(SqlConstants.DELETE_ALL_SQL)
42 | void truncate();
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq-starter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-rocketmq-starter
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-configuration-processor
23 |
24 |
25 |
26 | org.apache.rocketmq
27 | rocketmq-client
28 |
29 |
30 |
31 | junit
32 | junit
33 |
34 |
35 |
36 |
37 |
38 |
39 | org.apache.maven.plugins
40 | maven-compiler-plugin
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/costants/SqlConstants.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.costants;
2 |
3 | /**
4 | * Sql语句
5 | *
6 | * @author happyxiaofan
7 | * @since 0.0.1
8 | */
9 | public abstract class SqlConstants {
10 |
11 | /**
12 | * TABLE >>>>>>>>>> user
13 | */
14 |
15 | public static final String USER_CREATE_SQL = "CREATE TABLE IF NOT EXISTS `user` (`id` bigint(20) AUTO_INCREMENT, `user_id` bigint(20) NOT NULL COMMENT '用户id',`city_id` int(11) DEFAULT NULL COMMENT '城市id',`user_name` varchar(15) DEFAULT NULL,`age` int(11) DEFAULT NULL COMMENT '年龄',`birth` date DEFAULT NULL COMMENT '生日',PRIMARY KEY (`id`))";
16 |
17 | public static final String GET_ALL_SQL = "SELECT * FROM user";
18 |
19 | public static final String GET_ONE_SQL = "SELECT * FROM user WHERE user_id = #{userId}";
20 |
21 | public static final String GET_LIMIT_ONE_SQL = "SELECT * FROM user LIMIT 1";
22 |
23 | public static final String INSERT_SQL = "INSERT INTO user(user_id,city_id,user_name,age,birth) VALUES(#{userId}, #{cityId}, #{userName}, #{age}, #{birth})";
24 |
25 | public static final String INSERT_SLAVE_SQL = "INSERT INTO user(city_id,user_name,age,birth) VALUES(#{cityId}, #{userName}, #{age}, #{birth})";
26 |
27 | public static final String UPDATE_SQL = "UPDATE user SET user_name=#{userName},age=#{age},birth=#{birth} WHERE user_id =#{userId}";
28 |
29 | public static final String DELETE_SQL = "DELETE FROM user WHERE user_id =#{userId}";
30 |
31 | public static final String DELETE_ALL_SQL = "DELETE FROM user";
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/spring-boot-rocketmq/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-rocketmq
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter
18 |
19 |
20 |
21 | io.github.rhwayfun
22 | spring-boot-rocketmq-starter
23 | 0.0.3.RELEASE
24 |
25 |
26 |
27 | junit
28 | junit
29 | 4.12
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-maven-plugin
38 |
39 |
40 | org.jacoco
41 | jacoco-maven-plugin
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/mockito/Mockito.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import net.sf.cglib.proxy.Enhancer;
4 | import net.sf.cglib.proxy.MethodInterceptor;
5 | import net.sf.cglib.proxy.MethodProxy;
6 |
7 | import java.lang.reflect.Method;
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * Created by chubin on 2017/4/16.
13 | */
14 | public class Mockito {
15 |
16 | private static Map MOCK_RESULTS = new HashMap<>();
17 |
18 | private static Invocation lastInvocation;
19 |
20 | public static T mock(Class t){
21 | Enhancer enhancer = new Enhancer();
22 | enhancer.setSuperclass(t);
23 | enhancer.setCallback(new MockMethodInterceptor());
24 | return (T) enhancer.create();
25 | }
26 |
27 | public static When when(T t){
28 | return new When();
29 | }
30 |
31 | public static class When{
32 | public void thenReturn(T obj){
33 | MOCK_RESULTS.put(lastInvocation, obj);
34 | }
35 | }
36 |
37 | private static class MockMethodInterceptor implements MethodInterceptor{
38 |
39 | @Override
40 | public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
41 | Invocation invocation = new Invocation(o, method, objects, methodProxy);
42 |
43 | lastInvocation = invocation;
44 |
45 | if (MOCK_RESULTS.containsKey(invocation)){
46 | return MOCK_RESULTS.get(invocation);
47 | }
48 |
49 | return null;
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/mockito/Invocation.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import net.sf.cglib.proxy.MethodProxy;
4 |
5 | import java.lang.reflect.Method;
6 | import java.util.Arrays;
7 |
8 | /**
9 | * Created by chubin on 2017/4/16.
10 | */
11 | public class Invocation {
12 |
13 | private final Object mock;
14 |
15 | private final Method method;
16 |
17 | private final Object[] agrs;
18 |
19 | private final MethodProxy proxy;
20 |
21 | public Invocation(Object mock, Method method, Object[] agrs, MethodProxy proxy) {
22 | this.mock = mock;
23 | this.method = method;
24 | this.agrs = copyArgs(agrs);
25 | this.proxy = proxy;
26 | }
27 |
28 | private Object[] copyArgs(Object[] args){
29 | Object[] newArgs = new Object[args.length];
30 | System.arraycopy(args, 0, newArgs, 0, args.length);
31 | return newArgs;
32 | }
33 |
34 | public Object callRealMethod() {
35 | try {
36 | return this.proxy.invokeSuper(mock, agrs);
37 | } catch (Throwable throwable) {
38 | throwable.printStackTrace();
39 | }
40 | return null;
41 | }
42 |
43 | @Override
44 | public boolean equals(Object o) {
45 | if (this == o) return true;
46 | if (o == null || getClass() != o.getClass()) return false;
47 |
48 | Invocation that = (Invocation) o;
49 |
50 | return this.method.equals(that.method) && this.proxy.equals(that.proxy) && Arrays.deepEquals(this.agrs, that.agrs);
51 | }
52 |
53 | @Override
54 | public int hashCode() {
55 | return 1;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/springboot/quickstart/mockito/invocation/InvocationTimesTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito.invocation;
2 |
3 | import com.rhwayfun.springboot.quickstart.mockito.BaseMockitoTest;
4 | import org.junit.Test;
5 |
6 | import java.util.List;
7 |
8 | import static org.mockito.Mockito.*;
9 |
10 | /**
11 | * Created by ZhongCB on 2017/4/11.
12 | */
13 | public class InvocationTimesTest extends BaseMockitoTest {
14 |
15 | @Test
16 | public void test1() throws Exception{
17 | List mockedList = mock(List.class);
18 |
19 | //using mock
20 | mockedList.add("once");
21 |
22 | mockedList.add("twice");
23 | mockedList.add("twice");
24 |
25 | mockedList.add("three times");
26 | mockedList.add("three times");
27 | mockedList.add("three times");
28 |
29 | mockedList.add("five times");
30 | mockedList.add("five times");
31 |
32 | //following two verifications work exactly the same - times(1) is used by default
33 | verify(mockedList).add("once");
34 | verify(mockedList, times(1)).add("once");
35 |
36 | //exact number of invocations verification
37 | verify(mockedList, times(2)).add("twice");
38 | verify(mockedList, times(3)).add("three times");
39 |
40 | //verification using never(). never() is an alias to times(0)
41 | verify(mockedList, never()).add("never happened");
42 |
43 | //verification using atLeast()/atMost()
44 | verify(mockedList, atLeastOnce()).add("three times");
45 | verify(mockedList, atLeast(2)).add("five times");
46 | verify(mockedList, atMost(5)).add("three times");
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/java/com/rhwayfun/springboot/mybatis/annotation/mapper/UserMapperExt.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.annotation.mapper;
2 |
3 | import com.rhwayfun.springboot.mybatis.annotation.constants.SqlConstants;
4 | import com.rhwayfun.springboot.mybatis.annotation.constants.UserSqlProvider;
5 | import com.rhwayfun.springboot.mybatis.annotation.entity.UserEntity;
6 | import org.apache.ibatis.annotations.*;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * 用户DAO扩展类,使用Sql生成器
12 | * @see UserSqlProvider
13 | *
14 | * @author happyxiaofan
15 | * @since 0.0.1
16 | */
17 | public interface UserMapperExt extends UserMapper {
18 |
19 | /**
20 | * 区别:findOneV2 VS findOne
21 | * 如果使用@SelectProvider创建SQL语句,且使用#{}获取参数,必须在参数加上@Param注解
22 | * 否则使用@Select定义Sql映射语句,则不需要添加@Param注解
23 | *
24 | * @param userId
25 | * @return
26 | */
27 | @SelectProvider(type = UserSqlProvider.class, method = "findOneSql")
28 | @ResultMap(value = "userResultMap")
29 | UserEntity findOne(@Param("userId") Long userId);
30 |
31 | @Select(SqlConstants.GET_ONE_SQL)
32 | @ResultMap(value = "userResultMap")
33 | UserEntity findOneV2(Long userId);
34 |
35 | @SelectProvider(type = UserSqlProvider.class, method = "findAllSql")
36 | @ResultMap(value = "userResultMap")
37 | List findAll();
38 |
39 | @InsertProvider(type = UserSqlProvider.class, method = "insertSql")
40 | int add(UserEntity user);
41 |
42 | @UpdateProvider(type = UserSqlProvider.class, method = "updateSql")
43 | int modify(UserEntity user);
44 |
45 | @DeleteProvider(type = UserSqlProvider.class, method = "deleteSql")
46 | int remove(Long userId);
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/springboot/quickstart/mockito/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.mockito.ArgumentCaptor;
7 | import org.mockito.InjectMocks;
8 | import org.mockito.Mock;
9 | import org.mockito.junit.MockitoJUnitRunner;
10 |
11 | import static org.junit.Assert.assertEquals;
12 | import static org.mockito.ArgumentMatchers.anyInt;
13 | import static org.mockito.Mockito.verify;
14 | import static org.mockito.Mockito.when;
15 |
16 | /**
17 | * Created by chubin on 2017/3/26.
18 | */
19 | @RunWith(MockitoJUnitRunner.class)
20 | public class UserServiceTest {
21 |
22 | @InjectMocks
23 | private UserService userService;
24 | @Mock
25 | private UserDAO userDAO;
26 |
27 | @Test
28 | public void testFindUserById() {
29 | ArgumentCaptor captor = ArgumentCaptor.forClass(User.class);
30 | User user = new User("Tom", 1, 13);
31 | userDAO.modifyUser(user);
32 | verify(userDAO).modifyUser(captor.capture());
33 |
34 | // 获取捕获的参数
35 | assertEquals(captor.getValue().getId(), 1);
36 | assertEquals(captor.getValue().getAge(), 13);
37 | assertEquals(captor.getValue().getName(), "Tom");
38 |
39 | // 添加条件返回值
40 | when(userDAO.findById(anyInt())).thenReturn(user);
41 | assertEquals(userDAO.findById(1).getId(), 1);
42 |
43 | // 测试是否相等
44 | assertEquals(userService.findById(1).getId(), 1);
45 | assertEquals(userService.findById(1).getAge(), 13);
46 | assertEquals(userService.findById(1).getName(), "Tom");
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/spring-boot-configuration/src/test/java/com/rhwayfun/springboot/configuration/SimplePropertyTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.configuration;
2 |
3 | import com.rhwayfun.springboot.configuration.property.SimpleProperty;
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.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * TEST
14 | *
15 | * @author happyxiaofan
16 | * @since 0.0.1
17 | */
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest
20 | public class SimplePropertyTest {
21 |
22 | @Autowired
23 | private SimpleProperty simpleProperty;
24 |
25 | @Test
26 | public void getApp() throws Exception {
27 | assertEquals("spring-boot-configuration", simpleProperty.getApp());
28 | }
29 |
30 | @Test
31 | public void getUser() throws Exception {
32 | assertEquals("happyxiaofan", simpleProperty.getUser());
33 | }
34 |
35 | @Test
36 | public void getAge() throws Exception {
37 | assertEquals(24, simpleProperty.getAge());
38 | }
39 |
40 | @Test
41 | public void getEmail() throws Exception {
42 | assertEquals("rhwayfun@gmail.com", simpleProperty.getEmail());
43 | }
44 |
45 | @Test
46 | public void getBlog() throws Exception {
47 | assertEquals("http://blog.csdn.net/u011116672", simpleProperty.getBlog());
48 | }
49 |
50 | @Test
51 | public void getGithub() throws Exception {
52 | assertEquals("https://github.com/happyxiaofan/spring-boot-learning-examples", simpleProperty.getGithub());
53 | }
54 |
55 | }
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2/src/test/java/com/rhwayfun/springboot/logging/log4j2/web/LogControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.logging.log4j2.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
7 | import org.springframework.mock.web.MockHttpServletRequest;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 | import org.springframework.test.web.servlet.MockMvc;
10 | import org.springframework.test.web.servlet.RequestBuilder;
11 | import org.springframework.test.web.servlet.ResultActions;
12 | import org.springframework.web.bind.annotation.RequestMethod;
13 |
14 | import javax.servlet.ServletContext;
15 |
16 | import static org.junit.Assert.assertNotNull;
17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
18 |
19 | /**
20 | *
21 | * @author happyxiaofan
22 | * @since 0.0.1
23 | */
24 | @RunWith(SpringRunner.class)
25 | @WebMvcTest(LogController.class)
26 | public class LogControllerTest {
27 |
28 | @Autowired
29 | private MockMvc mvc;
30 |
31 | @Test
32 | public void now() throws Exception {
33 | ResultActions resultActions = this.mvc.perform(new RequestBuilder() {
34 | @Override
35 | public MockHttpServletRequest buildRequest(ServletContext servletContext) {
36 | return new MockHttpServletRequest(RequestMethod.GET.name(), "/now/1");
37 | }
38 | }).andExpect(status().isOk());
39 | String contentAsString = resultActions.andReturn().getResponse().getContentAsString();
40 | assertNotNull(contentAsString);
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/spring-boot-configuration/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-configuration
13 | 0.0.1-SNAPSHOT
14 | jar
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter
20 |
21 |
22 |
23 | org.springframework.boot
24 | spring-boot-configuration-processor
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-test
30 | test
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.jacoco
38 | jacoco-maven-plugin
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-maven-plugin
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-dubbo
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | provider
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter
18 |
19 |
20 |
21 | com.rhwayfun
22 | api
23 | ${dubbo-api.version}
24 |
25 |
26 |
27 | com.alibaba
28 | dubbo
29 |
30 |
31 |
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-maven-plugin
42 |
43 |
44 | org.jacoco
45 | jacoco-maven-plugin
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.mapper;
2 |
3 | import com.rhwayfun.springboot.mybatis.shardingjdbc.costants.SqlConstants;
4 | import com.rhwayfun.springboot.mybatis.shardingjdbc.entity.UserEntity;
5 | import org.apache.ibatis.annotations.*;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 用户DAO
11 | *
12 | * @author happyxiaofan
13 | * @since 0.0.1
14 | */
15 | public interface UserMapper {
16 |
17 | @Select(SqlConstants.GET_ALL_SQL)
18 | @Results(id = "userResultMap", value = {
19 | @Result(property = "userId", column = "user_id"),
20 | @Result(property = "cityId", column = "city_id"),
21 | @Result(property = "userName", column = "user_name"),
22 | @Result(property = "age", column = "age"),
23 | @Result(property = "birth", column = "birth")
24 | })
25 | List getAll();
26 |
27 | @Select(SqlConstants.GET_ONE_SQL)
28 | @ResultMap(value = "userResultMap")
29 | UserEntity getOne(Long userId);
30 |
31 | @Select(SqlConstants.GET_LIMIT_ONE_SQL)
32 | @ResultMap(value = "userResultMap")
33 | UserEntity getLimitOne();
34 |
35 | @Insert(SqlConstants.INSERT_SQL)
36 | int insert(UserEntity user);
37 |
38 | @Insert(SqlConstants.INSERT_SLAVE_SQL)
39 | @Options(useGeneratedKeys = true, keyProperty = "userId")
40 | int insertSlave(UserEntity user);
41 |
42 | @Update(SqlConstants.UPDATE_SQL)
43 | int update(UserEntity user);
44 |
45 | @Delete(SqlConstants.DELETE_SQL)
46 | int delete(Long userId);
47 |
48 | @Delete(SqlConstants.DELETE_ALL_SQL)
49 | void deleteAll();
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/kafka/simple/SimpleKafkaProducer.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.kafka.simple;
2 |
3 | import org.apache.kafka.clients.producer.KafkaProducer;
4 | import org.apache.kafka.clients.producer.Producer;
5 | import org.apache.kafka.clients.producer.ProducerRecord;
6 |
7 | import java.util.Properties;
8 |
9 | /**
10 | * Created by chubin on 2017/7/30.
11 | */
12 | public class SimpleKafkaProducer {
13 |
14 | public static void main(String[] args) throws InterruptedException {
15 |
16 | Properties props = new Properties();
17 |
18 | //broker地址
19 | props.put("bootstrap.servers", "localhost:9092");
20 |
21 | //请求时候需要验证
22 | props.put("acks", "all");
23 |
24 | //请求失败时候需要重试
25 | props.put("retries", 0);
26 |
27 | //内存缓存区大小
28 | props.put("buffer.memory", 33554432);
29 |
30 | //指定消息key序列化方式
31 | props.put("key.serializer",
32 | "org.apache.kafka.common.serialization.StringSerializer");
33 |
34 | //指定消息本身的序列化方式
35 | props.put("value.serializer",
36 | "org.apache.kafka.common.serialization.StringSerializer");
37 |
38 | Producer producer = new KafkaProducer<>(props);
39 |
40 | /*for (int i = 0; i < 10; i++)
41 | producer.send(new ProducerRecord<>("test", Integer.toString(i), Integer.toString(i)));*/
42 | producer.send(new ProducerRecord<>("hello-kafka", "Test consumer group 01", "Test consumer group 01"));
43 | producer.send(new ProducerRecord<>("hello-kafka", "Test consumer group 02", "Test consumer group 02"));
44 | System.out.println("Message sent successfully");
45 | producer.close();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/spring-boot-configuration/src/test/java/com/rhwayfun/springboot/configuration/RandomPropertyTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.configuration;
2 |
3 | import com.rhwayfun.springboot.configuration.random.RandomProperty;
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.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * 随机值属性TEST
14 | *
15 | * @author happyxiaofan
16 | * @since 0.0.1
17 | */
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest
20 | public class RandomPropertyTest {
21 |
22 | @Autowired
23 | private RandomProperty randomProperty;
24 |
25 | @Test
26 | public void getRandomValue() throws Exception {
27 | assertNotNull(randomProperty.getRandomValue());
28 | }
29 |
30 | @Test
31 | public void getRandomInt() throws Exception {
32 | assertTrue(randomProperty.getRandomInt() > Integer.MIN_VALUE);
33 | }
34 |
35 | @Test
36 | public void getRandomLong() throws Exception {
37 | assertTrue(randomProperty.getRandomLong() > Long.MIN_VALUE);
38 | }
39 |
40 | @Test
41 | public void getRandomUUID() throws Exception {
42 | assertNotNull(randomProperty.getRandomUUID());
43 | }
44 |
45 | @Test
46 | public void getRandomIntRange() throws Exception {
47 | assertTrue(randomProperty.getRandomIntRange() < 10);
48 | }
49 |
50 | @Test
51 | public void getRandomIntMaxMinRange() throws Exception {
52 | assertTrue(randomProperty.getRandomIntMaxMinRange() > 10);
53 | assertTrue(randomProperty.getRandomIntMaxMinRange() < 100);
54 | }
55 |
56 | }
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/java/com/rhwayfun/springboot/mybatis/annotation/constants/UserSqlProvider.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.annotation.constants;
2 |
3 | import java.util.Map;
4 |
5 | import static org.apache.ibatis.jdbc.SqlBuilder.*;
6 |
7 | /**
8 | * Sql语句生成器
9 | *
10 | * @author happyxiaofan
11 | * @since 0.0.1
12 | */
13 | public class UserSqlProvider {
14 |
15 | private static final String TABLE_NAME = "user";
16 |
17 | public String findOneSql(Map parameters) {
18 | Long userId = (Long) parameters.get("userId");
19 | BEGIN();
20 | SELECT("user_id, user_name, age, birth");
21 | FROM(TABLE_NAME);
22 | if (userId != null) {
23 | WHERE("user_id = #{userId}");
24 | }
25 | return SQL();
26 | }
27 |
28 | public String findAllSql() {
29 | BEGIN();
30 | SELECT("user_id, user_name, age, birth");
31 | FROM(TABLE_NAME);
32 | return SQL();
33 | }
34 |
35 | public String insertSql() {
36 | BEGIN();
37 | INSERT_INTO(TABLE_NAME);
38 | VALUES("user_id", "#{userId}");
39 | VALUES("user_name", "#{userName}");
40 | VALUES("age", "#{age}");
41 | VALUES("birth", "#{birth}");
42 | return SQL();
43 | }
44 |
45 | public String updateSql() {
46 | BEGIN();
47 | UPDATE(TABLE_NAME);
48 | SET("user_name = #{userName}");
49 | SET("age = #{age}");
50 | SET("birth = #{birth}");
51 | WHERE("user_id = #{userId}");
52 | return SQL();
53 | }
54 |
55 | public String deleteSql() {
56 | BEGIN();
57 | DELETE_FROM(TABLE_NAME);
58 | WHERE("user_id = #{userId}");
59 | return SQL();
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.service;
2 |
3 | import com.rhwayfun.springboot.mybatis.shardingjdbc.entity.UserEntity;
4 | import com.rhwayfun.springboot.mybatis.shardingjdbc.mapper.UserMapper;
5 | import org.springframework.stereotype.Service;
6 | import org.springframework.transaction.annotation.Transactional;
7 |
8 | import javax.annotation.Resource;
9 | import java.util.Date;
10 |
11 | /**
12 | * @author happyxiaofan
13 | * @since 0.0.1
14 | */
15 | @Service
16 | public class UserService {
17 |
18 | @Resource
19 | private UserMapper userMapper;
20 |
21 | private Long userId;
22 |
23 | @Transactional("mybatisTransactionManager")
24 | public void updateWithFail() {
25 | UserEntity user = new UserEntity();
26 | user.setCityId(1);
27 | user.setUserName("insertTest");
28 | user.setAge(10);
29 | user.setBirth(new Date());
30 |
31 | userMapper.insertSlave(user);
32 |
33 | userId = user.getUserId();
34 |
35 | user.setUserName("insertTest2");
36 | userMapper.update(user);
37 | throw new IllegalArgumentException("failed");
38 | }
39 |
40 | @Transactional("mybatisTransactionManager")
41 | public void updateWithoutInsertFail() {
42 | UserEntity one = userMapper.getLimitOne();
43 | UserEntity user = new UserEntity();
44 | user.setUserName("insertTest2");
45 | user.setUserId(one.getUserId());
46 | userId = one.getUserId();
47 | userMapper.update(user);
48 | throw new IllegalArgumentException("failed");
49 | }
50 |
51 | public Long getUserId() {
52 | return userId;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 | import com.rhwayfun.springboot.quickstart.mockito.UserDAO;
5 | import com.rhwayfun.springboot.quickstart.mockito.UserService;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.mockito.ArgumentCaptor;
9 | import org.mockito.InjectMocks;
10 | import org.mockito.Mock;
11 | import org.mockito.junit.MockitoJUnitRunner;
12 |
13 | import static org.junit.Assert.assertEquals;
14 | import static org.mockito.ArgumentMatchers.anyInt;
15 | import static org.mockito.Mockito.verify;
16 | import static org.mockito.Mockito.when;
17 |
18 | /**
19 | * Created by chubin on 2017/3/26.
20 | */
21 | @RunWith(MockitoJUnitRunner.class)
22 | public class UserServiceTest {
23 |
24 | @InjectMocks
25 | private UserService userService;
26 | @Mock
27 | private UserDAO userDAO;
28 |
29 | @Test
30 | public void testFindUserById() {
31 | ArgumentCaptor captor = ArgumentCaptor.forClass(User.class);
32 | User user = new User("Tom", 1, 13);
33 | userDAO.modifyUser(user);
34 | verify(userDAO).modifyUser(captor.capture());
35 |
36 | // 获取捕获的参数
37 | assertEquals(captor.getValue().getId(), 1);
38 | assertEquals(captor.getValue().getAge(), 13);
39 | assertEquals(captor.getValue().getName(), "Tom");
40 |
41 | // 添加条件返回值
42 | when(userDAO.findById(anyInt())).thenReturn(user);
43 | assertEquals(userDAO.findById(1).getId(), 1);
44 |
45 | // 测试是否相等
46 | assertEquals(userService.findById(1).getId(), 1);
47 | assertEquals(userService.findById(1).getAge(), 13);
48 | assertEquals(userService.findById(1).getName(), "Tom");
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/java/com/rhwayfun/springboot/mybatis/annotation/entity/UserEntity.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.annotation.entity;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | /**
7 | * 用户实体类,纯POJO
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | public class UserEntity implements Serializable {
13 |
14 | private Integer id;
15 |
16 | private Long userId;
17 |
18 | private String userName;
19 |
20 | private Integer age;
21 |
22 | private Date birth;
23 |
24 | private static final long serialVersionUID = 1L;
25 |
26 | public Integer getId() {
27 | return id;
28 | }
29 |
30 | public void setId(Integer id) {
31 | this.id = id;
32 | }
33 |
34 | public Long getUserId() {
35 | return userId;
36 | }
37 |
38 | public void setUserId(Long userId) {
39 | this.userId = userId;
40 | }
41 |
42 | public String getUserName() {
43 | return userName;
44 | }
45 |
46 | public void setUserName(String userName) {
47 | this.userName = userName;
48 | }
49 |
50 | public Integer getAge() {
51 | return age;
52 | }
53 |
54 | public void setAge(Integer age) {
55 | this.age = age;
56 | }
57 |
58 | public Date getBirth() {
59 | return birth;
60 | }
61 |
62 | public void setBirth(Date birth) {
63 | this.birth = birth;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | return "UserEntity{" +
69 | "id=" + id +
70 | ", userId=" + userId +
71 | ", userName='" + userName + '\'' +
72 | ", age=" + age +
73 | ", birth=" + birth +
74 | '}';
75 | }
76 | }
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/disconf/JedisConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.disconf;
2 |
3 | import com.baidu.disconf.client.common.annotations.DisconfFile;
4 | import com.baidu.disconf.client.common.annotations.DisconfFileItem;
5 | import com.baidu.disconf.client.common.annotations.DisconfUpdateService;
6 | import com.baidu.disconf.client.common.update.IDisconfUpdate;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.context.annotation.Scope;
10 | import org.springframework.stereotype.Service;
11 |
12 | /**
13 | * Created by chubin on 2017/6/11.
14 | */
15 | @Service
16 | @Scope("singleton")
17 | @DisconfFile(filename = "redis.properties")
18 | @DisconfUpdateService(classes = {JedisConfig.class})
19 | public class JedisConfig implements IDisconfUpdate {
20 |
21 | /** Logger */
22 | private static Logger log = LoggerFactory.getLogger(JedisConfig.class);
23 |
24 | // 代表连接地址
25 | private String host;
26 |
27 | // 代表连接port
28 | private int port;
29 |
30 | /**
31 | * 地址, 分布式文件配置
32 | *
33 | * @return
34 | */
35 | @DisconfFileItem(name = "redis.host", associateField = "host")
36 | public String getHost() {
37 | return host;
38 | }
39 |
40 | public void setHost(String host) {
41 | this.host = host;
42 | }
43 |
44 | /**
45 | * 端口, 分布式文件配置
46 | *
47 | * @return
48 | */
49 | @DisconfFileItem(name = "redis.port", associateField = "port")
50 | public int getPort() {
51 | return port;
52 | }
53 |
54 | public void setPort(int port) {
55 | this.port = port;
56 | }
57 |
58 | @Override
59 | public void reload() throws Exception {
60 | log.info(">>>>>>>>>host: " + host);
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-multidatasource/src/main/java/com/rhwayfun/springboot/mybatis/multidatasource/entity/UserEntity.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.multidatasource.entity;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | /**
7 | * 用户实体类,纯POJO
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | public class UserEntity implements Serializable {
13 |
14 | private static final long serialVersionUID = 1L;
15 |
16 | private Integer id;
17 |
18 | private Long userId;
19 |
20 | private String userName;
21 |
22 | private Integer age;
23 |
24 | private Date birth;
25 |
26 | public Integer getId() {
27 | return id;
28 | }
29 |
30 | public void setId(Integer id) {
31 | this.id = id;
32 | }
33 |
34 | public Long getUserId() {
35 | return userId;
36 | }
37 |
38 | public void setUserId(Long userId) {
39 | this.userId = userId;
40 | }
41 |
42 | public String getUserName() {
43 | return userName;
44 | }
45 |
46 | public void setUserName(String userName) {
47 | this.userName = userName;
48 | }
49 |
50 | public Integer getAge() {
51 | return age;
52 | }
53 |
54 | public void setAge(Integer age) {
55 | this.age = age;
56 | }
57 |
58 | public Date getBirth() {
59 | return birth;
60 | }
61 |
62 | public void setBirth(Date birth) {
63 | this.birth = birth;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | return "UserEntity{" +
69 | "id=" + id +
70 | ", userId=" + userId +
71 | ", userName='" + userName + '\'' +
72 | ", age=" + age +
73 | ", birth=" + birth +
74 | '}';
75 | }
76 |
77 | }
--------------------------------------------------------------------------------
/spring-boot-configuration/src/test/java/com/rhwayfun/springboot/configuration/ProfilePropertyTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.configuration;
2 |
3 | import com.rhwayfun.springboot.configuration.property.SimpleProperty;
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.context.SpringBootTest;
8 | import org.springframework.test.context.ActiveProfiles;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 |
11 | import static org.junit.Assert.assertEquals;
12 |
13 | /**
14 | * TEST
15 | *
16 | * @author happyxiaofan
17 | * @since 0.0.1
18 | */
19 | @RunWith(SpringRunner.class)
20 | @SpringBootTest
21 | @ActiveProfiles("dev")
22 | public class ProfilePropertyTest {
23 |
24 | @Autowired
25 | private SimpleProperty profileProperty;
26 |
27 | @Test
28 | public void getApp() throws Exception {
29 | assertEquals("spring-boot-configuration", profileProperty.getApp());
30 | }
31 |
32 | @Test
33 | public void getUser() throws Exception {
34 | assertEquals("springboot", profileProperty.getUser());
35 | }
36 |
37 | @Test
38 | public void getAge() throws Exception {
39 | assertEquals(1, profileProperty.getAge());
40 | }
41 |
42 | @Test
43 | public void getEmail() throws Exception {
44 | assertEquals("springboot@gmail.com", profileProperty.getEmail());
45 | }
46 |
47 | @Test
48 | public void getBlog() throws Exception {
49 | assertEquals("http://blog.csdn.net/springboot", profileProperty.getBlog());
50 | }
51 |
52 | @Test
53 | public void getGithub() throws Exception {
54 | assertEquals("https://github.com/springboot/spring-boot-samples", profileProperty.getGithub());
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/security/dao/impl/UserRepositoryImpl.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.security.dao.impl;
2 |
3 | import com.rhwayfun.springboot.quickstart.security.datasource.mapper.UserMapper;
4 | import com.rhwayfun.springboot.quickstart.security.datasource.model.User;
5 | import com.rhwayfun.springboot.quickstart.security.datasource.model.UserAuthority;
6 | import com.rhwayfun.springboot.quickstart.security.dao.UserRepository;
7 | import com.rhwayfun.springboot.quickstart.security.datasource.mapper.UserAuthorityMapper;
8 | import com.rhwayfun.springboot.quickstart.security.datasource.model.UserAuthorityExample;
9 | import com.rhwayfun.springboot.quickstart.security.datasource.model.UserExample;
10 | import org.springframework.stereotype.Repository;
11 | import org.springframework.util.CollectionUtils;
12 |
13 | import javax.annotation.Resource;
14 | import java.util.List;
15 |
16 | /**
17 | * Created by chubin on 2017/8/13.
18 | */
19 | @Repository
20 | public class UserRepositoryImpl implements UserRepository{
21 |
22 | @Resource
23 | private UserMapper userMapper;
24 |
25 | @Resource
26 | private UserAuthorityMapper userAuthorityMapper;
27 |
28 | @Override
29 | public User findByUserName(String username) {
30 | UserExample example = new UserExample();
31 | example.createCriteria().andUserNameEqualTo(username);
32 | List users = userMapper.selectByExample(example);
33 | return !CollectionUtils.isEmpty(users) ? users.get(0) : null;
34 | }
35 |
36 | @Override
37 | public List findRoles(int userId) {
38 | UserAuthorityExample example = new UserAuthorityExample();
39 | example.createCriteria().andUserIdEqualTo(userId);
40 | return userAuthorityMapper.selectByExample(example);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/spring-boot-dubbo-annotation/dubbo-provider/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | com.rhwayfun
9 | spring-boot-dubbo-annotation
10 | 0.0.1-SNAPSHOT
11 |
12 |
13 | dubbo-provider
14 | 0.0.1-SNAPSHOT
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter
20 |
21 |
22 |
23 | com.rhwayfun
24 | dubbo-api
25 | 0.0.1-SNAPSHOT
26 |
27 |
28 |
29 | com.alibaba
30 | dubbo
31 |
32 |
33 |
34 | com.alibaba.boot
35 | dubbo-spring-boot-starter
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 | org.jacoco
47 | jacoco-maven-plugin
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/spring-boot-quickstart/src/test/java/com/rhwayfun/springboot/quickstart/web/DemoControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.web;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
7 | import org.springframework.mock.web.MockHttpServletRequest;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 | import org.springframework.test.web.servlet.MockMvc;
10 | import org.springframework.test.web.servlet.RequestBuilder;
11 | import org.springframework.test.web.servlet.ResultActions;
12 | import org.springframework.web.bind.annotation.RequestMethod;
13 |
14 | import javax.servlet.ServletContext;
15 |
16 | import static org.junit.Assert.assertEquals;
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 | * Created by chubin on 2017/9/10.
22 | */
23 | @RunWith(SpringRunner.class)
24 | @WebMvcTest(DemoController.class)
25 | public class DemoControllerTest {
26 |
27 | @Autowired
28 | private MockMvc mvc;
29 |
30 | @Test
31 | public void now() throws Exception {
32 | ResultActions resultActions = this.mvc.perform(new RequestBuilder() {
33 | @Override
34 | public MockHttpServletRequest buildRequest(ServletContext servletContext) {
35 | return new MockHttpServletRequest(RequestMethod.GET.name(), "/now");
36 | }
37 | }).andExpect(status().isOk()).andExpect(content().string("hello"));
38 | String contentAsString = resultActions.andReturn().getResponse().getContentAsString();
39 | assertEquals(contentAsString, "hello");
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/spring-boot-logging-log4j2-config/src/main/java/com/rhwayfun/springboot/logging/log4j2/config/SpecificLog4j2Configuration.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.logging.log4j2.config;
2 |
3 | import org.apache.logging.log4j.Level;
4 | import org.apache.logging.log4j.core.config.Configuration;
5 | import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
6 | import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
7 | import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder;
8 | import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
9 |
10 | /**
11 | * @author rhwayfun
12 | * @since 0.0.1
13 | */
14 | public class SpecificLog4j2Configuration extends Log4j2Configuration {
15 |
16 | @Override
17 | public Configuration createCustomConfiguration(final String name, ConfigurationBuilder builder) {
18 | super.createCustomConfiguration(name, builder);
19 |
20 | /* Properties */
21 | builder.addProperty("logging.file.action.name", "${sys:logging.file.path}/../bigdata/${sys:project.name}-action.log");
22 |
23 | /* Appender */
24 | AppenderComponentBuilder componentBuilder = Log4j2Utils.newRollingRandomAccessFileAppender(builder,
25 | "RollingAction", "${logging.file.action.name}", "${logging.file.action.name}-%d{yyyy-MM-dd-HH}");
26 | builder.add(componentBuilder);
27 |
28 | /* Logger */
29 | LoggerComponentBuilder loggerWithRef = Log4j2Utils.newLoggerWithRef(builder, "com.rhwayfun.springboot.logging.log4j2.config.BigdataUtilImpl", "RollingAction");
30 | builder.add(loggerWithRef);
31 | LoggerComponentBuilder logger = Log4j2Utils.newLogger(builder, "com.alibaba.dubbo.monitor", Level.WARN);
32 | builder.add(logger);
33 | return builder.build();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/spring-boot-starter-rest/src/test/java/com/rhwayfun/springboot/starter/rest/DemoControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.starter.rest;
2 |
3 | import com.rhwayfun.springboot.starter.DemoService;
4 | import com.rhwayfun.springboot.starter.rest.web.controller.DemoController;
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.autoconfigure.web.servlet.WebMvcTest;
9 | import org.springframework.boot.test.mock.mockito.MockBean;
10 | import org.springframework.http.MediaType;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 | import org.springframework.test.web.servlet.MockMvc;
13 |
14 | import static org.mockito.BDDMockito.given;
15 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
18 |
19 | /**
20 | * @author happyxiaofan
21 | * @since 0.0.1
22 | */
23 | @RunWith(SpringRunner.class)
24 | @WebMvcTest(DemoController.class)
25 | public class DemoControllerTest {
26 |
27 | @Autowired
28 | private MockMvc mvc;
29 |
30 | @MockBean
31 | private DemoService demoService;
32 |
33 | private static final String USER_GET = "/user-info/1";
34 |
35 | private static final String USER = "User[id=1, name=happyxiaofan, age=12, email=rhwayfun@gmail.com]";
36 |
37 | @Test
38 | public void userInfo() throws Exception {
39 | given(this.demoService.userInfo()).willReturn(USER);
40 | this.mvc.perform(get(USER_GET)
41 | .accept(MediaType.TEXT_PLAIN))
42 | .andExpect(status().isOk())
43 | .andExpect(content().string(USER));
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/spring-boot-log4j2-integration/src/main/java/io/github/rhwayfun/springboot/log4j2/integration/util/AppenderUtil.java:
--------------------------------------------------------------------------------
1 | package io.github.rhwayfun.springboot.log4j2.integration.util;
2 |
3 | import io.github.rhwayfun.springboot.log4j2.integration.appender.AppenderFactory;
4 | import io.github.rhwayfun.springboot.log4j2.integration.en.AppenderTypeEn;
5 | import org.apache.logging.log4j.LogManager;
6 | import org.apache.logging.log4j.core.LoggerContext;
7 | import org.apache.logging.log4j.core.config.Configuration;
8 | import org.apache.logging.log4j.core.lookup.StrLookup;
9 | import org.apache.logging.log4j.core.lookup.StrSubstitutor;
10 |
11 | import java.util.ServiceLoader;
12 |
13 | /**
14 | * @author rhwayfun
15 | * @since 0.0.1
16 | */
17 | public class AppenderUtil {
18 |
19 | public static org.apache.logging.log4j.core.Appender createAppender(LoggerContext ctx, AppenderTypeEn type) {
20 | ClassLoader classLoader = AppenderUtil.class.getClassLoader();
21 | ServiceLoader serviceLoader = ServiceLoader.load(AppenderFactory.class, classLoader);
22 | for (AppenderFactory appenderFactory : serviceLoader) {
23 | org.apache.logging.log4j.core.Appender appender = appenderFactory.createAppender(ctx, type);
24 | if (appender != null) {
25 | return appender;
26 | }
27 | }
28 | return null;
29 | }
30 |
31 | public static String getLoggerProperty(String propertyName) {
32 | final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(true);
33 | final Configuration config = loggerContext.getConfiguration();
34 | final StrSubstitutor strSubstitutor = config.getStrSubstitutor();
35 | final StrLookup variableResolver = strSubstitutor.getVariableResolver();
36 | return variableResolver.lookup(propertyName);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-multidatasource/src/main/java/com/rhwayfun/springboot/mybatis/multidatasource/entity/CityEntity.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.multidatasource.entity;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | /**
7 | * 城市实体类,纯POJO
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | public class CityEntity implements Serializable {
13 |
14 | private static final long serialVersionUID = 1L;
15 |
16 | private int id;
17 |
18 | private String name;
19 |
20 | private boolean isActive;
21 |
22 | private Date createTime;
23 |
24 | private Date modifyTime;
25 |
26 | public int getId() {
27 | return id;
28 | }
29 |
30 | public void setId(int id) {
31 | this.id = id;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public void setName(String name) {
39 | this.name = name;
40 | }
41 |
42 | public boolean isActive() {
43 | return isActive;
44 | }
45 |
46 | public void setActive(boolean active) {
47 | isActive = active;
48 | }
49 |
50 | public Date getCreateTime() {
51 | return createTime;
52 | }
53 |
54 | public void setCreateTime(Date createTime) {
55 | this.createTime = createTime;
56 | }
57 |
58 | public Date getModifyTime() {
59 | return modifyTime;
60 | }
61 |
62 | public void setModifyTime(Date modifyTime) {
63 | this.modifyTime = modifyTime;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | return "CityEntity{" +
69 | "id=" + id +
70 | ", name='" + name + '\'' +
71 | ", isActive=" + isActive +
72 | ", createTime=" + createTime +
73 | ", modifyTime=" + modifyTime +
74 | '}';
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/spring-boot-starter-rest/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-learning-examples
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-starter-rest
13 |
14 |
15 |
16 | com.rhwayfun
17 | spring-boot-starter
18 | 0.0.1-SNAPSHOT
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-web
24 |
25 |
26 |
27 | org.springframework.boot
28 | spring-boot-starter-test
29 | test
30 |
31 |
32 |
33 | org.mockito
34 | mockito-all
35 | test
36 |
37 |
38 |
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-maven-plugin
44 |
45 |
46 | org.jacoco
47 | jacoco-maven-plugin
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/spring-boot-mybatis/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | spring-boot-learning-examples
8 | com.rhwayfun
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 | spring-boot-mybatis
13 | 0.0.1-SNAPSHOT
14 | jar
15 |
16 |
17 |
18 | org.springframework.boot
19 | spring-boot-starter
20 |
21 |
22 |
23 | org.mybatis.spring.boot
24 | mybatis-spring-boot-starter
25 |
26 |
27 |
28 | mysql
29 | mysql-connector-java
30 |
31 |
32 |
33 | com.alibaba
34 | druid
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-configuration-processor
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-starter-test
45 | test
46 |
47 |
48 |
49 |
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-maven-plugin
54 |
55 |
56 | org.jacoco
57 | jacoco-maven-plugin
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-annotation/src/main/java/com/rhwayfun/springboot/mybatis/annotation/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.annotation.mapper;
2 |
3 | import com.rhwayfun.springboot.mybatis.annotation.constants.SqlConstants;
4 | import com.rhwayfun.springboot.mybatis.annotation.entity.UserEntity;
5 | import org.apache.ibatis.annotations.*;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * 用户DAO
11 | *
12 | * @author happyxiaofan
13 | * @since 0.0.1
14 | */
15 | public interface UserMapper {
16 |
17 | /**
18 | * 查询所有用户
19 | *
20 | * 注解:1、@Select定义一个SELECT映射语句
21 | * 2、@Results注解与JavaBean属性映射起来
22 | * 3、@Insert定义一个INSERT映射语句
23 | * 4、@Update定义一个UPDATE映射语句
24 | * @return 所有的用户
25 | */
26 | @Select(SqlConstants.GET_ALL_SQL)
27 | @Results(id = "userResultMap", value = {
28 | @Result(property = "userId", column = "user_id"),
29 | @Result(property = "userName", column = "user_name"),
30 | @Result(property = "age", column = "age"),
31 | @Result(property = "birth", column = "birth")
32 | })
33 | List getAll();
34 |
35 | /**
36 | * 查询单个用户
37 | *
38 | * 这里两个语句的@Results配置完全相同,但还是得重复
39 | * 解决方法是在@Results注解添加id属性,然后@ResultMap指定这个id就可以了。
40 | * 也就是这里的@ResultMap(value = "userResultMap")可以替换为getAll()方法的@Results注解的内容
41 | * @param userId 用户id
42 | * @return 单个用户
43 | */
44 | @Select(SqlConstants.GET_ONE_SQL)
45 | @ResultMap(value = "userResultMap")
46 | UserEntity getOne(Long userId);
47 |
48 | @Insert(SqlConstants.INSERT_SQL)
49 | int insert(UserEntity user);
50 |
51 | @Update(SqlConstants.UPDATE_SQL)
52 | int update(UserEntity user);
53 |
54 | @Delete(SqlConstants.DELETE_SQL)
55 | int delete(Long userId);
56 |
57 | @Delete(SqlConstants.DELETE_ALL_SQL)
58 | void deleteAll();
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/source/src/main/resources/spring/disconf.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
19 |
20 |
21 | classpath:config/application.properties
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/CarDAOTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.rhwayfun.springboot.quickstart.Application;
5 | import com.rhwayfun.springboot.quickstart.datasource.dao.CarDAO;
6 | import com.rhwayfun.springboot.quickstart.datasource.mapper.CarMapper;
7 | import com.rhwayfun.springboot.quickstart.datasource.model.Car;
8 | import com.rhwayfun.springboot.quickstart.doamin.CarBO;
9 | import com.rhwayfun.springboot.quickstart.security.datasource.mapper.UserMapper;
10 | import com.rhwayfun.springboot.quickstart.security.datasource.model.User;
11 | import org.junit.Test;
12 | import org.junit.runner.RunWith;
13 | import org.springframework.boot.test.context.SpringBootTest;
14 | import org.springframework.test.context.ActiveProfiles;
15 | import org.springframework.test.context.junit4.SpringRunner;
16 |
17 | import javax.annotation.Resource;
18 |
19 | /**
20 | * Created by chubin on 2017/7/29.
21 | */
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest(classes = Application.class)
24 | @ActiveProfiles("default")
25 | public class CarDAOTest {
26 |
27 | @Resource
28 | private CarDAO carDAO;
29 |
30 | @Resource
31 | private CarMapper carMapper;
32 |
33 | @Resource
34 | private UserMapper userMapper;
35 |
36 | @Test
37 | public void save() throws Exception {
38 | CarBO car = new CarBO( null, "DD-AB-123", 4 );
39 | carDAO.saveOrUpdate(car);
40 | }
41 |
42 | @Test
43 | public void save2() throws Exception {
44 | Car record = new Car();
45 | record.setLicensePlate("test");
46 | record.setManuFacturer("test");
47 | record.setSeatCount(2);
48 | carMapper.insert(record);
49 | }
50 |
51 | @Test
52 | public void findUser() throws Exception {
53 | User user = userMapper.selectByPrimaryKey(1);
54 | System.out.println(JSON.toJSON(user));
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/springboot/quickstart/mockito/UserServiceSpyTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.mockito;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 | import org.junit.Assert;
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.mockito.junit.MockitoJUnitRunner;
9 |
10 | import java.util.List;
11 |
12 | import static org.mockito.Mockito.spy;
13 |
14 | /**
15 | * Created by chubin on 2017/3/26.
16 | */
17 | @RunWith(MockitoJUnitRunner.class)
18 | public class UserServiceSpyTest {
19 |
20 |
21 | private UserService userService;
22 | private UserDAO userDAO;
23 |
24 | @Before
25 | public void setUp(){
26 | userService = new UserService();
27 | UserDAOImpl userDAOImpl = new UserDAOImpl();
28 | userDAO = spy(userDAOImpl);
29 | userService.setUserDAO(userDAO);
30 | }
31 |
32 | @Test
33 | public void testSpy(){
34 | // 使用真实对象执行
35 | Assert.assertEquals(userService.findById(2).getName(), "Tim");
36 | }
37 |
38 | private static class UserDAOImpl implements UserDAO{
39 |
40 | @Override
41 | public User findById(int id) {
42 | return new User("Tim", 2, 10);
43 | }
44 |
45 | @Override
46 | public void deleteById(int id) {
47 |
48 | }
49 |
50 | @Override
51 | public List findLists(int... ids) {
52 | return null;
53 | }
54 |
55 | @Override
56 | public boolean modifyUser(User user) {
57 | return false;
58 | }
59 |
60 | @Override
61 | public boolean modifyUser(Integer id, String name, List hobbies) {
62 | return false;
63 | }
64 |
65 | @Override
66 | public User findByName(String name) {
67 | return null;
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/kafka/simple/SimpleKafkaConsumerGroup.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.kafka.simple;
2 |
3 | import org.apache.kafka.clients.consumer.ConsumerRecord;
4 | import org.apache.kafka.clients.consumer.ConsumerRecords;
5 | import org.apache.kafka.clients.consumer.KafkaConsumer;
6 |
7 | import java.util.Collections;
8 | import java.util.Properties;
9 | import java.util.Random;
10 |
11 | /**
12 | * Created by chubin on 2017/7/30.
13 | */
14 | public class SimpleKafkaConsumerGroup {
15 |
16 | public static void main(String[] args) throws Exception {
17 |
18 | String topic = "hello-kafka";
19 | String group = String.valueOf(new Random().nextInt(100));
20 | // String group = String.valueOf(2);
21 | Properties props = new Properties();
22 | props.put("bootstrap.servers", "localhost:9092");
23 | props.put("group.id", group);
24 | props.put("enable.auto.commit", "true");
25 | props.put("auto.commit.interval.ms", "1000");
26 | props.put("session.timeout.ms", "30000");
27 | props.put("key.deserializer",
28 | "org.apache.kafka.common.serialization.StringDeserializer");
29 | props.put("value.deserializer",
30 | "org.apache.kafka.common.serialization.StringDeserializer");
31 | KafkaConsumer consumer = new KafkaConsumer<>(props);
32 |
33 | consumer.subscribe(Collections.singletonList(topic));
34 | System.out.println("Subscribed to topic " + topic);
35 | int i = 0;
36 |
37 | while (true) {
38 | ConsumerRecords records = consumer.poll(100);
39 | for (ConsumerRecord record : records)
40 | System.out.printf("offset = %d, key = %s, value = %s\n",
41 | record.offset(), record.key(), record.value());
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/spring-boot-dubbo/consumer/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-dubbo
7 | com.rhwayfun
8 | 0.0.1-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | consumer
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter
18 |
19 |
20 |
21 | com.rhwayfun
22 | api
23 | ${dubbo-api.version}
24 |
25 |
26 |
27 | com.rhwayfun
28 | provider
29 | 0.0.1-SNAPSHOT
30 |
31 |
32 |
33 | com.alibaba
34 | dubbo
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-test
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 | org.jacoco
51 | jacoco-maven-plugin
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/source/src/main/java/com/rhwayfun/springboot/quickstart/kafka/simple/SimpleKafkaConsumer.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.quickstart.kafka.simple;
2 |
3 | import org.apache.kafka.clients.consumer.ConsumerRecord;
4 | import org.apache.kafka.clients.consumer.ConsumerRecords;
5 | import org.apache.kafka.clients.consumer.KafkaConsumer;
6 |
7 | import java.util.Collections;
8 | import java.util.Properties;
9 |
10 | /**
11 | * Created by chubin on 2017/7/30.
12 | */
13 | public class SimpleKafkaConsumer {
14 |
15 | public static void main(String[] args) {
16 |
17 | Properties props = new Properties();
18 |
19 | props.put("bootstrap.servers", "localhost:9092");
20 | //每个消费者分配独立的组号
21 | props.put("group.id", "test");
22 |
23 | //如果value合法,则自动提交偏移量
24 | props.put("enable.auto.commit", "true");
25 |
26 | //设置多久一次更新被消费消息的偏移量
27 | props.put("auto.commit.interval.ms", "1000");
28 |
29 | //设置会话响应的时间,超过这个时间kafka可以选择放弃消费或者消费下一条消息
30 | props.put("session.timeout.ms", "30000");
31 |
32 | props.put("key.deserializer",
33 | "org.apache.kafka.common.serialization.StringDeserializer");
34 | props.put("value.deserializer",
35 | "org.apache.kafka.common.serialization.StringDeserializer");
36 |
37 | KafkaConsumer consumer = new KafkaConsumer<>(props);
38 |
39 | consumer.subscribe(Collections.singletonList("test"));
40 |
41 | System.out.println("Subscribed to topic " + "test");
42 | int i = 0;
43 |
44 | while (true) {
45 | ConsumerRecords records = consumer.poll(100);
46 | for (ConsumerRecord record : records)
47 |
48 | // print the offset,key and value for the consumer records.
49 | System.out.printf("offset = %d, key = %s, value = %s\n",
50 | record.offset(), record.key(), record.value());
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/source/src/test/java/com/rhwayfun/UserServiceSpyTest.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun;
2 |
3 | import com.rhwayfun.springboot.quickstart.doamin.User;
4 | import com.rhwayfun.springboot.quickstart.mockito.UserDAO;
5 | import com.rhwayfun.springboot.quickstart.mockito.UserService;
6 | import org.junit.Assert;
7 | import org.junit.Before;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 | import org.mockito.junit.MockitoJUnitRunner;
11 |
12 | import java.util.List;
13 |
14 | import static org.mockito.Mockito.spy;
15 |
16 | /**
17 | * Created by chubin on 2017/3/26.
18 | */
19 | @RunWith(MockitoJUnitRunner.class)
20 | public class UserServiceSpyTest {
21 |
22 |
23 | private UserService userService;
24 | private UserDAO userDAO;
25 |
26 | @Before
27 | public void setUp(){
28 | userService = new UserService();
29 | UserDAOImpl userDAOImpl = new UserDAOImpl();
30 | userDAO = spy(userDAOImpl);
31 | userService.setUserDAO(userDAO);
32 | }
33 |
34 | @Test
35 | public void testSpy(){
36 | // 使用真实对象执行
37 | Assert.assertEquals(userService.findById(2).getName(), "Tim");
38 | }
39 |
40 | private static class UserDAOImpl implements UserDAO{
41 |
42 | @Override
43 | public User findById(int id) {
44 | return new User("Tim", 2, 10);
45 | }
46 |
47 | @Override
48 | public void deleteById(int id) {
49 |
50 | }
51 |
52 | @Override
53 | public List findLists(int... ids) {
54 | return null;
55 | }
56 |
57 | @Override
58 | public boolean modifyUser(User user) {
59 | return false;
60 | }
61 |
62 | @Override
63 | public boolean modifyUser(Integer id, String name, List hobbies) {
64 | return false;
65 | }
66 |
67 | @Override
68 | public User findByName(String name) {
69 | return null;
70 | }
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/druid/DruidStatsConfig.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.druid;
2 |
3 | import com.alibaba.druid.support.http.StatViewServlet;
4 | import com.alibaba.druid.support.http.WebStatFilter;
5 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
6 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | /**
11 | * 使用配置的方式添加druid数据源监控
12 | *
13 | * @author happyxiaofan
14 | * @since 0.0.1
15 | */
16 | @Configuration
17 | public class DruidStatsConfig {
18 |
19 | /**
20 | * 注册StatViewServlet
21 | * @return
22 | */
23 | @Bean
24 | public ServletRegistrationBean registrationBean() {
25 | ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid-stats/*");
26 | /** 初始化参数配置,initParams**/
27 | //白名单
28 | bean.addInitParameter("allow", "127.0.0.1");
29 | //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
30 | bean.addInitParameter("deny", "192.168.125.120");
31 | //登录查看信息的账号密码.
32 | bean.addInitParameter("loginUsername", "happyxiaofan");
33 | bean.addInitParameter("loginPassword", "springboot");
34 | //是否能够重置数据.
35 | bean.addInitParameter("resetEnable", "false");
36 | return bean;
37 | }
38 |
39 | /**
40 | * 注册WebStatFilter
41 | * @return
42 | */
43 | @Bean
44 | public FilterRegistrationBean druidStatFilter() {
45 | FilterRegistrationBean bean = new FilterRegistrationBean(new WebStatFilter());
46 | //添加过滤规则.
47 | bean.addUrlPatterns("/*");
48 | //添加不需要忽略的格式信息.
49 | bean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid-stats/*");
50 | return bean;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/resources/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | user_id, user_name, age, birth
13 |
14 |
15 |
16 | CREATE TABLE IF NOT EXISTS `t_user` (`id` bigint(20) AUTO_INCREMENT, `user_id` bigint(20) NOT NULL COMMENT '用户id',`city_id` int(11) DEFAULT NULL COMMENT '城市id',`user_name` varchar(15) DEFAULT NULL,`age` int(11) DEFAULT NULL COMMENT '年龄',`birth` date DEFAULT NULL COMMENT '生日',PRIMARY KEY (`id`))
17 |
18 |
19 |
20 | TRUNCATE TABLE t_user;
21 |
22 |
23 |
24 | DROP TABLE IF EXISTS t_user;
25 |
26 |
27 |
28 | INSERT INTO t_user(city_id,user_name,age,birth) VALUES(#{cityId}, #{userName}, #{age}, #{birth})
29 |
30 |
31 |
32 | DELETE FROM t_user WHERE user_id =#{userId}
33 |
34 |
35 |
44 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/entity/UserEntity.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.entity;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | /**
7 | * 用户实体类,纯POJO
8 | *
9 | * @author happyxiaofan
10 | * @since 0.0.1
11 | */
12 | public class UserEntity implements Serializable {
13 |
14 | private Integer id;
15 |
16 | private Long userId;
17 |
18 | private Integer cityId;
19 |
20 | private String userName;
21 |
22 | private Integer age;
23 |
24 | private Date birth;
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | public Integer getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Integer id) {
33 | this.id = id;
34 | }
35 |
36 | public Long getUserId() {
37 | return userId;
38 | }
39 |
40 | public void setUserId(Long userId) {
41 | this.userId = userId;
42 | }
43 |
44 | public Integer getCityId() {
45 | return cityId;
46 | }
47 |
48 | public void setCityId(Integer cityId) {
49 | this.cityId = cityId;
50 | }
51 |
52 | public String getUserName() {
53 | return userName;
54 | }
55 |
56 | public void setUserName(String userName) {
57 | this.userName = userName;
58 | }
59 |
60 | public Integer getAge() {
61 | return age;
62 | }
63 |
64 | public void setAge(Integer age) {
65 | this.age = age;
66 | }
67 |
68 | public Date getBirth() {
69 | return birth;
70 | }
71 |
72 | public void setBirth(Date birth) {
73 | this.birth = birth;
74 | }
75 |
76 | @Override
77 | public String toString() {
78 | return "UserEntity{" +
79 | "id=" + id +
80 | ", userId=" + userId +
81 | ", cityId=" + cityId +
82 | ", userName='" + userName + '\'' +
83 | ", age=" + age +
84 | ", birth=" + birth +
85 | '}';
86 | }
87 | }
--------------------------------------------------------------------------------
/spring-boot-mybatis/src/test/resources/mybatis-generator.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
11 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
39 |
40 |
41 |
42 |
45 |
46 |
--------------------------------------------------------------------------------
/spring-boot-mybatis-sharding-jdbc-masterslave/src/main/java/com/rhwayfun/springboot/mybatis/shardingjdbc/masterslave/entity/UserEntity.java:
--------------------------------------------------------------------------------
1 | package com.rhwayfun.springboot.mybatis.shardingjdbc.masterslave.entity;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | /**
7 | * 用户实体类,纯POJO
8 | *
9 | * @author rhwayfun
10 | * @since 0.0.1
11 | */
12 | public class UserEntity implements Serializable {
13 |
14 | private Integer id;
15 |
16 | private Long userId;
17 |
18 | private Integer cityId;
19 |
20 | private String userName;
21 |
22 | private Integer age;
23 |
24 | private Date birth;
25 |
26 | private static final long serialVersionUID = 1L;
27 |
28 | public Integer getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Integer id) {
33 | this.id = id;
34 | }
35 |
36 | public Long getUserId() {
37 | return userId;
38 | }
39 |
40 | public void setUserId(Long userId) {
41 | this.userId = userId;
42 | }
43 |
44 | public Integer getCityId() {
45 | return cityId;
46 | }
47 |
48 | public void setCityId(Integer cityId) {
49 | this.cityId = cityId;
50 | }
51 |
52 | public String getUserName() {
53 | return userName;
54 | }
55 |
56 | public void setUserName(String userName) {
57 | this.userName = userName;
58 | }
59 |
60 | public Integer getAge() {
61 | return age;
62 | }
63 |
64 | public void setAge(Integer age) {
65 | this.age = age;
66 | }
67 |
68 | public Date getBirth() {
69 | return birth;
70 | }
71 |
72 | public void setBirth(Date birth) {
73 | this.birth = birth;
74 | }
75 |
76 | @Override
77 | public String toString() {
78 | return "UserEntity{" +
79 | "id=" + id +
80 | ", userId=" + userId +
81 | ", cityId=" + cityId +
82 | ", userName='" + userName + '\'' +
83 | ", age=" + age +
84 | ", birth=" + birth +
85 | '}';
86 | }
87 | }
--------------------------------------------------------------------------------