├── .gitignore
├── Async
├── .gitignore
├── .project
├── README.MD
├── async.iml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── cml
│ │ └── learn
│ │ └── async
│ │ ├── Application.java
│ │ ├── AsyncService.java
│ │ ├── AsyncThreadPoolConfiguration.java
│ │ └── AsyncThreadPoolConfiguration2.java
│ └── resources
│ ├── application.properties
│ └── logback.xml
├── DynamicDataSource
├── .classpath
├── .factorypath
├── .gitignore
├── .project
├── .settings
│ ├── .jsdtscope
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.apt.core.prefs
│ ├── org.eclipse.jdt.core.prefs
│ ├── org.eclipse.m2e.core.prefs
│ ├── org.eclipse.wst.common.component
│ ├── org.eclipse.wst.common.project.facet.core.xml
│ ├── org.eclipse.wst.jsdt.ui.superType.container
│ ├── org.eclipse.wst.jsdt.ui.superType.name
│ └── org.eclipse.wst.validation.prefs
├── .springBeans
├── LICENSE
├── README.md
├── boot.iml
├── db
│ └── springbot.sql
├── pom.xml
└── src
│ ├── main
│ ├── i18n
│ │ ├── messages.properties
│ │ ├── messages_en_US.properties
│ │ └── messages_zh_CN.properties
│ ├── java
│ │ └── com
│ │ │ └── cml
│ │ │ └── springboot
│ │ │ ├── BootApplication.java
│ │ │ ├── framework
│ │ │ ├── AsyncTaskConfig.java
│ │ │ ├── Configuration.java
│ │ │ ├── WebGlobalConfiguration.java
│ │ │ ├── controller
│ │ │ │ └── BaseController.java
│ │ │ ├── db
│ │ │ │ ├── DynamicDataSourceAutoConfiguration.java
│ │ │ │ ├── DynamicDataSourceHolder.java
│ │ │ │ ├── EnableDynamicDataSource.java
│ │ │ │ └── TransactionAspect.java
│ │ │ ├── deserializer
│ │ │ │ └── DateTimeDeserializer.java
│ │ │ ├── exception
│ │ │ │ └── ExceptionHandler.java
│ │ │ ├── interceptor
│ │ │ │ ├── ParamInterceptor.java
│ │ │ │ └── TokenInterceptor.java
│ │ │ ├── mybatis
│ │ │ │ ├── MybatisConfig.java
│ │ │ │ ├── MybatisScanConfiguration.java
│ │ │ │ ├── SpringBootVFS.java
│ │ │ │ └── typehandler
│ │ │ │ │ ├── JodaDateTimeTypeHandler.java
│ │ │ │ │ └── JodaLocalTimeTypeHandler.java
│ │ │ ├── response
│ │ │ │ ├── BaseResponse.java
│ │ │ │ ├── BaseResponseAdvise.java
│ │ │ │ └── MethodResponseHandler.java
│ │ │ ├── transaction
│ │ │ │ └── TransactionService.java
│ │ │ └── util
│ │ │ │ ├── DateFormatter.java
│ │ │ │ ├── DateUtil.java
│ │ │ │ ├── LogUtil.java
│ │ │ │ ├── MD5.java
│ │ │ │ └── UUIDUtil.java
│ │ │ └── sample
│ │ │ ├── bean
│ │ │ ├── LogBean.java
│ │ │ ├── User.java
│ │ │ └── UserResponse.java
│ │ │ ├── controller
│ │ │ ├── ModelAttributeController.java
│ │ │ ├── SampleController.java
│ │ │ └── UserController.java
│ │ │ ├── db
│ │ │ ├── LogMapper.java
│ │ │ ├── UserMapper.java
│ │ │ └── resource
│ │ │ │ ├── log.sql.xml
│ │ │ │ └── user.sql.xml
│ │ │ └── service
│ │ │ ├── LogService.java
│ │ │ ├── UserService.java
│ │ │ └── impl
│ │ │ ├── LogServiceImpl.java
│ │ │ └── UserServiceImpl.java
│ ├── resources
│ │ ├── ValidationMessages.properties
│ │ ├── banner.txt
│ │ ├── config
│ │ │ ├── application-jdbc.properties
│ │ │ └── application.properties
│ │ ├── log4j.properties
│ │ └── public
│ │ │ └── error
│ │ │ └── 404.html
│ └── webapp
│ │ ├── WEB-INF
│ │ └── jsp
│ │ │ ├── test.jsp
│ │ │ └── welcome.jsp
│ │ ├── demo.html
│ │ ├── demo.jsp
│ │ ├── error.jsp
│ │ ├── static
│ │ └── demo.html
│ │ ├── test.jsp
│ │ └── upload.html
│ └── test
│ └── java
│ └── com
│ └── cml
│ └── springboot
│ └── controller
│ └── test
│ ├── DynamicDataSourceTest.java
│ ├── HelloControllerIT.java
│ └── HelloControllerTest.java
├── Kafka
├── .classpath
├── .gitignore
├── .project
├── Kafka.iml
├── README.md
├── pom.xml
└── src
│ └── main
│ ├── i18n
│ ├── messages.properties
│ ├── messages_en_US.properties
│ └── messages_zh_CN.properties
│ ├── java
│ └── com
│ │ └── cml
│ │ └── springboot
│ │ ├── KafkaConfiguration.java
│ │ ├── consumer
│ │ ├── BootApplication.java
│ │ └── Consumer.java
│ │ ├── message
│ │ └── TestMessage.java
│ │ └── producer
│ │ ├── Producer.java
│ │ └── ProducerBootApplication.java
│ ├── resources
│ ├── banner.txt
│ ├── config
│ │ ├── application-consumer.properties
│ │ └── application-producer.properties
│ ├── log4j.properties
│ └── public
│ │ └── error
│ │ └── 404.html
│ └── test
│ └── com
│ └── cml
│ └── springboot
│ └── test
│ ├── SpringKafkaTest.java
│ └── TestConfiguration.java
├── LearnCache
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── cml
│ └── learn
│ └── CacheApplication.java
├── LearnTest
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── cml
│ │ └── learn
│ │ └── test
│ │ ├── AService.java
│ │ ├── BService.java
│ │ ├── CService.java
│ │ ├── DService.java
│ │ └── Main.java
│ └── test
│ ├── java
│ └── com
│ │ └── cml
│ │ └── learn
│ │ └── test
│ │ ├── AServiceMockTest.java
│ │ ├── AServiceTest.java
│ │ ├── BServiceTest.java
│ │ ├── DServicePropertiesFileTest.java
│ │ ├── DServicePropertiesTest.java
│ │ ├── DServiceTest.java
│ │ ├── MainTest.java
│ │ └── MockSelectorTest.java
│ └── resources
│ └── application.properties
├── README.md
├── RabbitmqSpringBoot
├── .gitignore
├── .project
├── README.MD
├── classpath
├── pom.xml
├── screenshots
│ ├── rabbit-admin.png
│ └── receiver.png
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── cml
│ │ └── learning
│ │ └── rabbitmq
│ │ └── spring
│ │ ├── Application.java
│ │ ├── RabbitConfiguration.java
│ │ ├── constant
│ │ └── PlaceHolderConst.java
│ │ ├── model
│ │ └── EmailModel.java
│ │ ├── receiver
│ │ └── MessageReceiver.java
│ │ └── service
│ │ ├── MailService.java
│ │ └── MailServiceImpl.java
│ └── resources
│ ├── application.properties
│ ├── config
│ └── rabbitmq
│ │ └── rabbitmq.properties
│ └── logback-spring.xml
├── Redis
├── .gitignore
├── .project
├── README.MD
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── cml
│ │ │ └── learn
│ │ │ └── redis
│ │ │ ├── Application.java
│ │ │ ├── CacheConfiguration.java
│ │ │ └── CacheService.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── cml
│ └── learn
│ └── redis
│ └── test
│ ├── BasicCacheTest.java
│ └── ConcurrentCacheTest.java
├── RestMvc
├── .classpath
├── .factorypath
├── .gitignore
├── .project
├── .springBeans
├── LICENSE
├── README.md
├── boot.iml
├── db
│ └── springbot.sql
├── pom.xml
├── screenshots
│ └── structure.png
└── src
│ ├── main
│ ├── i18n
│ │ ├── messages.properties
│ │ ├── messages_en_US.properties
│ │ └── messages_zh_CN.properties
│ ├── java
│ │ └── com
│ │ │ └── cml
│ │ │ └── springboot
│ │ │ ├── BootApplication.java
│ │ │ ├── framework
│ │ │ ├── AsyncTaskConfig.java
│ │ │ ├── Configuration.java
│ │ │ ├── WebGlobalConfiguration.java
│ │ │ ├── argument
│ │ │ │ ├── CacheableModelMethodProcessor.java
│ │ │ │ └── CustomModelArgumentResolverConfiguration.java
│ │ │ ├── controller
│ │ │ │ └── BaseController.java
│ │ │ ├── deserializer
│ │ │ │ └── DateTimeDeserializer.java
│ │ │ ├── exception
│ │ │ │ └── ExceptionHandler.java
│ │ │ ├── interceptor
│ │ │ │ ├── ParamInterceptor.java
│ │ │ │ └── TokenInterceptor.java
│ │ │ ├── mybatis
│ │ │ │ ├── MybatisConfig.java
│ │ │ │ ├── MybatisScanConfiguration.java
│ │ │ │ ├── SpringBootVFS.java
│ │ │ │ └── typehandler
│ │ │ │ │ ├── JodaDateTimeTypeHandler.java
│ │ │ │ │ └── JodaLocalTimeTypeHandler.java
│ │ │ ├── response
│ │ │ │ ├── BaseResponse.java
│ │ │ │ ├── BaseResponseAdvise.java
│ │ │ │ └── MethodResponseHandler.java
│ │ │ ├── rest
│ │ │ │ ├── RestMvcAutoConfiguration.java
│ │ │ │ ├── RestMvcTesst.java
│ │ │ │ └── TestMvc.java
│ │ │ ├── transaction
│ │ │ │ └── TransactionService.java
│ │ │ └── util
│ │ │ │ ├── DateFormatter.java
│ │ │ │ ├── DateUtil.java
│ │ │ │ ├── LogUtil.java
│ │ │ │ ├── MD5.java
│ │ │ │ └── UUIDUtil.java
│ │ │ └── sample
│ │ │ ├── bean
│ │ │ ├── LogBean.java
│ │ │ ├── User.java
│ │ │ └── UserResponse.java
│ │ │ ├── controller
│ │ │ ├── ModelAttributeController.java
│ │ │ ├── SampleController.java
│ │ │ └── UserController.java
│ │ │ ├── db
│ │ │ ├── LogMapper.java
│ │ │ ├── UserMapper.java
│ │ │ └── resource
│ │ │ │ ├── log.sql.xml
│ │ │ │ └── user.sql.xml
│ │ │ └── service
│ │ │ ├── LogService.java
│ │ │ ├── UserService.java
│ │ │ └── impl
│ │ │ ├── LogServiceImpl.java
│ │ │ └── UserServiceImpl.java
│ ├── resources
│ │ ├── ValidationMessages.properties
│ │ ├── banner.txt
│ │ ├── config
│ │ │ ├── application-jdbc.properties
│ │ │ └── application.properties
│ │ ├── log4j.properties
│ │ └── public
│ │ │ └── error
│ │ │ └── 404.html
│ └── webapp
│ │ ├── WEB-INF
│ │ └── jsp
│ │ │ ├── test.jsp
│ │ │ └── welcome.jsp
│ │ ├── demo.html
│ │ ├── demo.jsp
│ │ ├── error.jsp
│ │ ├── static
│ │ └── demo.html
│ │ ├── test.jsp
│ │ └── upload.html
│ └── test
│ └── java
│ └── com
│ └── cml
│ └── springboot
│ └── controller
│ └── test
│ ├── HelloControllerIT.java
│ └── HelloControllerTest.java
├── SpringBootWebFlux
├── README.MD
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── cml
│ │ │ │ └── learn
│ │ │ │ └── webflux
│ │ │ │ ├── Application.java
│ │ │ │ ├── controller
│ │ │ │ └── WebFluxController.java
│ │ │ │ ├── error
│ │ │ │ ├── CustomExceptionHandler.java
│ │ │ │ └── ErrorHandler.java
│ │ │ │ └── filter
│ │ │ │ ├── AccessLogFilter.java
│ │ │ │ ├── LogUtils.java
│ │ │ │ ├── PartnerServerHttpRequestDecorator.java
│ │ │ │ ├── PartnerServerHttpResponseDecorator.java
│ │ │ │ └── PayloadServerWebExchangeDecorator.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── logback.xml
│ └── test
│ │ └── java
│ │ └── com
│ │ └── cml
│ │ └── webflux
│ │ └── webclient
│ │ ├── JsonContentTests.java
│ │ ├── Person.java
│ │ └── WebClientTest.java
└── web-flux.iml
├── SpringJpa
├── .gitignore
├── .project
├── README.MD
├── db
│ └── db.sql
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── cml
│ │ │ └── learn
│ │ │ └── jpa
│ │ │ ├── Application.java
│ │ │ ├── controller
│ │ │ └── HelloWorldController.java
│ │ │ ├── db
│ │ │ ├── bean
│ │ │ │ ├── Order.java
│ │ │ │ └── User.java
│ │ │ ├── read
│ │ │ │ ├── OrderReadRepository.java
│ │ │ │ └── UserReadRepository.java
│ │ │ └── write
│ │ │ │ ├── OrderRepository.java
│ │ │ │ └── UserRepository.java
│ │ │ ├── dto
│ │ │ ├── OrderQueryDTO.java
│ │ │ ├── OrderQueryDTO2.java
│ │ │ ├── OrderQueryDTO3.java
│ │ │ ├── UserEmailDTO.java
│ │ │ ├── UserNickNameDTO.java
│ │ │ └── UserProjection.java
│ │ │ ├── framework
│ │ │ ├── db
│ │ │ │ ├── ReadDbConfig.java
│ │ │ │ ├── WriteDbConfig.java
│ │ │ │ └── converter
│ │ │ │ │ └── DateToDateTimeConverter.java
│ │ │ └── util
│ │ │ │ └── MD5.java
│ │ │ └── service
│ │ │ └── UserService.java
│ └── resources
│ │ ├── application.properties
│ │ └── logback.xml
│ └── test
│ └── java
│ └── com
│ └── cml
│ └── learn
│ └── jpa
│ └── test
│ ├── TransactionTest.java
│ ├── UserCreateTest.java
│ ├── UserProjectionQueryTest.java
│ ├── UserQueryTest.java
│ └── order
│ ├── OrderCreateTest.java
│ └── OrderQueryTest.java
├── SpringStarter
├── .classpath
└── .settings
│ ├── org.eclipse.core.resources.prefs
│ └── org.eclipse.jdt.core.prefs
├── embedded-container
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── cml
│ └── learn
│ └── embedd
│ └── container
│ ├── Application.java
│ ├── redis
│ ├── RedisConfiguration.java
│ └── RedisTest.java
│ └── zookeeper
│ ├── EmbeddedZooKeeper.java
│ ├── EmbeddedZookeeperConfiguration.java
│ └── EmbeddedZookeeperTest.java
├── flyway
├── flyway.iml
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── cml
│ │ └── learn
│ │ └── flyway
│ │ ├── FlywayApplication.java
│ │ └── repository
│ │ ├── City.java
│ │ └── CityRepository.java
│ └── resources
│ └── application.yaml
├── rabbitmq
├── .classpath
├── .gitignore
├── .project
├── .settings
│ ├── org.eclipse.core.resources.prefs
│ ├── org.eclipse.jdt.core.prefs
│ └── org.eclipse.m2e.core.prefs
├── README.MD
├── pom.xml
├── screenshots
│ ├── rabbit-admin.png
│ └── receiver.png
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── cml
│ │ │ └── learning
│ │ │ └── rabbitmq
│ │ │ └── spring
│ │ │ ├── model
│ │ │ └── EmailModel.java
│ │ │ ├── receiver
│ │ │ ├── AbstractEmailReceiver.java
│ │ │ ├── AbstractReceiver.java
│ │ │ ├── DirectMessageReceiver.java
│ │ │ ├── FanoutMessageReceiver.java
│ │ │ ├── QueneMessageReceiver.java
│ │ │ ├── TopicManualACKMessageReceiver.java
│ │ │ └── TopicMessageReceiver.java
│ │ │ └── service
│ │ │ ├── MailService.java
│ │ │ └── MailServiceImpl.java
│ └── resources
│ │ ├── config
│ │ └── rabbitmq
│ │ │ └── rabbitmq.properties
│ │ ├── log4j.properties
│ │ └── spring
│ │ ├── application-rabbitmq-client.xml
│ │ └── application-rabbitmq-listener.xml
│ └── test
│ └── java
│ └── com
│ └── cml
│ └── learning
│ └── rabbitmq
│ └── spring
│ ├── SpringIntegrationReceiverTest.java
│ └── SpringIntegrationSendTest.java
└── web
├── .factorypath
├── .gitignore
├── LICENSE
├── README.md
├── db
└── springbot.sql
├── pom.xml
├── screenshots
└── structure.png
└── src
├── main
├── i18n
│ ├── messages.properties
│ ├── messages_en_US.properties
│ └── messages_zh_CN.properties
├── java
│ └── com
│ │ └── cml
│ │ └── springboot
│ │ ├── BootApplication.java
│ │ ├── framework
│ │ ├── AsyncTaskConfig.java
│ │ ├── Configuration.java
│ │ ├── WebGlobalConfiguration.java
│ │ ├── controller
│ │ │ └── BaseController.java
│ │ ├── deserializer
│ │ │ └── DateTimeDeserializer.java
│ │ ├── exception
│ │ │ └── ExceptionHandler.java
│ │ ├── interceptor
│ │ │ ├── ParamInterceptor.java
│ │ │ └── TokenInterceptor.java
│ │ ├── mybatis
│ │ │ ├── MybatisConfig.java
│ │ │ ├── MybatisScanConfiguration.java
│ │ │ ├── SpringBootVFS.java
│ │ │ └── typehandler
│ │ │ │ ├── JodaDateTimeTypeHandler.java
│ │ │ │ └── JodaLocalTimeTypeHandler.java
│ │ ├── response
│ │ │ ├── BaseResponse.java
│ │ │ ├── BaseResponseAdvise.java
│ │ │ └── MethodResponseHandler.java
│ │ ├── transaction
│ │ │ └── TransactionService.java
│ │ └── util
│ │ │ ├── DateFormatter.java
│ │ │ ├── DateUtil.java
│ │ │ ├── LogUtil.java
│ │ │ ├── MD5.java
│ │ │ └── UUIDUtil.java
│ │ └── sample
│ │ ├── bean
│ │ ├── LogBean.java
│ │ ├── User.java
│ │ └── UserResponse.java
│ │ ├── controller
│ │ ├── ModelAttributeController.java
│ │ ├── SampleController.java
│ │ └── UserController.java
│ │ ├── db
│ │ ├── LogMapper.java
│ │ ├── UserMapper.java
│ │ └── resource
│ │ │ ├── log.sql.xml
│ │ │ └── user.sql.xml
│ │ └── service
│ │ ├── LogService.java
│ │ ├── UserService.java
│ │ └── impl
│ │ ├── LogServiceImpl.java
│ │ └── UserServiceImpl.java
├── resources
│ ├── ValidationMessages.properties
│ ├── banner.txt
│ ├── config
│ │ ├── application-jdbc.properties
│ │ └── application.properties
│ ├── log4j.properties
│ └── public
│ │ └── error
│ │ └── 404.html
└── webapp
│ ├── WEB-INF
│ └── jsp
│ │ ├── test.jsp
│ │ └── welcome.jsp
│ ├── demo.html
│ ├── demo.jsp
│ ├── error.jsp
│ ├── static
│ └── demo.html
│ ├── test.jsp
│ └── upload.html
└── test
└── java
└── com
└── cml
└── springboot
└── controller
└── test
├── HelloControllerIT.java
└── HelloControllerTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | **/bin/
3 | **/target/
4 | **/logs/
5 | **/transaction-logs/
6 | **/.idea/
--------------------------------------------------------------------------------
/Async/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | /target/
3 | /logs
4 | /transaction-logs
5 | /.settings/
6 | .classpath
--------------------------------------------------------------------------------
/Async/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Async
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.m2e.core.maven2Builder
25 |
26 |
27 |
28 |
29 |
30 | org.springframework.ide.eclipse.core.springnature
31 | org.eclipse.jdt.core.javanature
32 | org.eclipse.m2e.core.maven2Nature
33 | org.eclipse.wst.common.project.facet.core.nature
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Async/README.MD:
--------------------------------------------------------------------------------
1 | # Async项目说明 #
2 | Async线程池测试
3 |
4 |
5 | # 测试说明#
6 | 可以通过配置文件中的async.threadpool.enable进行配置开关线程池
7 |
--------------------------------------------------------------------------------
/Async/src/main/java/com/cml/learn/async/AsyncThreadPoolConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.cml.learn.async;
2 |
3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
7 |
8 | @ConditionalOnProperty(name = "async.threadpool.enable", matchIfMissing = false)
9 | @Configuration
10 | public class AsyncThreadPoolConfiguration {
11 |
12 | @Bean
13 | public ThreadPoolTaskExecutor taskExecutor() {
14 | ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
15 | taskExecutor.setCorePoolSize(100);
16 | taskExecutor.setMaxPoolSize(500);
17 | taskExecutor.setThreadNamePrefix("async-thread-pool-");
18 | return taskExecutor;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Async/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | async.threadpool.enable=false
--------------------------------------------------------------------------------
/DynamicDataSource/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | /target/
3 | /logs
4 | /transaction-logs
5 | /.apt_generated/
6 |
--------------------------------------------------------------------------------
/DynamicDataSource/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | DynamicDataSource
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.jdt.core.javabuilder
15 |
16 |
17 |
18 |
19 | org.springframework.ide.eclipse.core.springbuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.wst.validation.validationbuilder
25 |
26 |
27 |
28 |
29 | org.eclipse.m2e.core.maven2Builder
30 |
31 |
32 |
33 |
34 |
35 | org.eclipse.jem.workbench.JavaEMFNature
36 | org.eclipse.wst.common.modulecore.ModuleCoreNature
37 | org.springframework.ide.eclipse.core.springnature
38 | org.eclipse.jdt.core.javanature
39 | org.eclipse.m2e.core.maven2Nature
40 | org.eclipse.wst.common.project.facet.core.nature
41 | org.eclipse.wst.jsdt.core.jsNature
42 |
43 |
44 |
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/.jsdtscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/i18n=UTF-8
3 | encoding//src/main/java=UTF-8
4 | encoding//src/main/resources=UTF-8
5 | encoding//src/test/java=UTF-8
6 | encoding//src/test/resources=UTF-8
7 | encoding/=UTF-8
8 |
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.jdt.apt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.apt.aptEnabled=true
3 |
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.wst.common.component:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.wst.jsdt.ui.superType.container:
--------------------------------------------------------------------------------
1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.wst.jsdt.ui.superType.name:
--------------------------------------------------------------------------------
1 | Window
--------------------------------------------------------------------------------
/DynamicDataSource/.settings/org.eclipse.wst.validation.prefs:
--------------------------------------------------------------------------------
1 | disabled=06target
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/DynamicDataSource/.springBeans:
--------------------------------------------------------------------------------
1 |
2 |
3 | 1
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | java:com.cml.springboot.main.BootApplication
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/DynamicDataSource/README.md:
--------------------------------------------------------------------------------
1 | # SpringBoot Learning #
2 |
3 | 读写分离自动配置
4 | 详情介绍请看博客:http://blog.csdn.net/cml_blog/article/details/78224798
5 |
6 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/i18n/messages.properties:
--------------------------------------------------------------------------------
1 | welcome=welcome to default
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/i18n/messages_en_US.properties:
--------------------------------------------------------------------------------
1 | welcome=welcome to english
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/i18n/messages_zh_CN.properties:
--------------------------------------------------------------------------------
1 | welcome=\u6b22\u8fce\u6765\u5230\u4e2d\u56fd
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/BootApplication.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6 | import org.springframework.context.annotation.ComponentScan;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.context.annotation.PropertySource;
9 | import org.springframework.context.annotation.PropertySources;
10 | import org.springframework.scheduling.annotation.EnableAsync;
11 |
12 | import com.cml.springboot.framework.db.EnableDynamicDataSource;
13 |
14 | @Configuration
15 | @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
16 | @ComponentScan()
17 | @EnableAsync
18 | @PropertySources({ @PropertySource("classpath:config/application-jdbc.properties") })
19 | @EnableDynamicDataSource
20 | public class BootApplication {
21 |
22 | // @Bean
23 | // public PropertyPlaceholderConfigurer placeHolder() {
24 | //
25 | // PropertyPlaceholderConfigurer configure = new
26 | // PropertyPlaceholderConfigurer();
27 | // configure.setLocations(null);
28 | //
29 | // return configure;
30 | // }
31 |
32 | public static void main(String[] args) throws Exception {
33 | SpringApplication.run(BootApplication.class, args);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/AsyncTaskConfig.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework;
2 |
3 | import java.util.concurrent.Executor;
4 |
5 | import org.apache.commons.logging.Log;
6 | import org.apache.commons.logging.LogFactory;
7 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
8 | import org.springframework.beans.factory.annotation.Value;
9 | import org.springframework.context.annotation.Configuration;
10 | import org.springframework.scheduling.annotation.AsyncConfigurer;
11 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
12 |
13 | @Configuration
14 | public class AsyncTaskConfig implements AsyncConfigurer {
15 |
16 | protected static Log log = LogFactory.getLog(AsyncTaskConfig.class);
17 |
18 | @Value("${async.task.config.corePoolSize}")
19 | private Integer corePoolSize;
20 | @Value("${async.task.config.maxPoolSize}")
21 | private Integer maxPoolSize;
22 |
23 | @Override
24 | public Executor getAsyncExecutor() {
25 |
26 | log.info("<<>>====>corePoolSize:" + corePoolSize + ",maxPoolSize:" + maxPoolSize);
27 |
28 | ThreadPoolTaskExecutor ex = new ThreadPoolTaskExecutor();
29 | ex.setCorePoolSize(corePoolSize);
30 | ex.setMaxPoolSize(maxPoolSize);
31 | ex.initialize();
32 | return ex;
33 | }
34 |
35 | @Override
36 | public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
37 | return null;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/Configuration.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework;
2 |
3 | public interface Configuration {
4 | interface Status {
5 | int STATUS_OK = 1;
6 | int STATUS_FAIL = 2;
7 | int STATUS_INVALID_TOKEN = 3;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/controller/BaseController.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.controller;
2 |
3 | import org.springframework.validation.Errors;
4 | import org.springframework.validation.ObjectError;
5 |
6 | import com.cml.springboot.framework.Configuration;
7 |
8 | public class BaseController {
9 |
10 | public static final int SUCCESS = Configuration.Status.STATUS_OK;
11 | public static final int FAIL = Configuration.Status.STATUS_FAIL;
12 |
13 | public static String getAllErrors(Errors errors) {
14 | StringBuilder builder = new StringBuilder();
15 | for (ObjectError error : errors.getAllErrors()) {
16 | builder.append(error.getDefaultMessage()).append("\n");
17 | }
18 | return builder.toString();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/db/DynamicDataSourceHolder.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.db;
2 |
3 | /**
4 | * 动态数据源处理
5 | *
6 | * @author cml
7 | *
8 | */
9 | public class DynamicDataSourceHolder {
10 | private static ThreadLocal holderDataSource = new ThreadLocal<>();
11 |
12 | public static void setDataSource(String dataSource) {
13 | holderDataSource.set(dataSource);
14 | }
15 |
16 | public static String getDataSource() {
17 | return holderDataSource.get();
18 | }
19 |
20 | public static void clear() {
21 | holderDataSource.remove();
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/db/EnableDynamicDataSource.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.db;
2 |
3 | import java.lang.annotation.Documented;
4 | import java.lang.annotation.ElementType;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | import org.springframework.context.annotation.Import;
10 |
11 | @Target(ElementType.TYPE)
12 | @Retention(RetentionPolicy.RUNTIME)
13 | @Documented
14 | @Import(DynamicDataSourceAutoConfiguration.class)
15 | public @interface EnableDynamicDataSource {
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/deserializer/DateTimeDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.deserializer;
2 |
3 | import java.io.IOException;
4 |
5 | import org.joda.time.DateTime;
6 | import org.joda.time.format.DateTimeFormat;
7 | import org.joda.time.format.DateTimeFormatter;
8 | import org.springframework.format.datetime.joda.DateTimeFormatterFactory;
9 |
10 | import com.fasterxml.jackson.core.JsonGenerator;
11 | import com.fasterxml.jackson.core.JsonProcessingException;
12 | import com.fasterxml.jackson.databind.JsonSerializer;
13 | import com.fasterxml.jackson.databind.SerializerProvider;
14 |
15 | public class DateTimeDeserializer extends JsonSerializer {
16 |
17 | private String format = "yyyyMMddHHmmss";
18 |
19 | public DateTimeDeserializer() {
20 | System.out.println("===================================================dddddddddddddddddddddddddddddddddddd");
21 | }
22 |
23 | public DateTimeDeserializer(String format) {
24 | super();
25 | this.format = format;
26 | }
27 |
28 | @Override
29 | public void serialize(DateTime value, JsonGenerator gen, SerializerProvider serializers)
30 | throws IOException, JsonProcessingException {
31 | if (null != value) {
32 | gen.writeString(value.toString(format));
33 | }
34 | System.out.println("==============================");
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/mybatis/MybatisScanConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.mybatis;
2 |
3 | import org.apache.commons.logging.Log;
4 | import org.apache.commons.logging.LogFactory;
5 | import org.mybatis.spring.annotation.MapperScan;
6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | @Configuration
10 | @AutoConfigureAfter(MybatisConfig.class)
11 | @MapperScan(basePackages = { "com.cml.springboot.sample.db" }, sqlSessionFactoryRef = "sqlSessionFactory")
12 | public class MybatisScanConfiguration {
13 | protected static Log log = LogFactory.getLog(MybatisScanConfiguration.class);
14 |
15 | public MybatisScanConfiguration() {
16 | log.info("*************************MybatisScanConfiguration***********************");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/mybatis/SpringBootVFS.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.mybatis;
2 |
3 | import java.io.IOException;
4 | import java.net.URI;
5 | import java.net.URL;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import org.apache.ibatis.io.VFS;
10 | import org.springframework.core.io.Resource;
11 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
12 | import org.springframework.core.io.support.ResourcePatternResolver;
13 |
14 | public class SpringBootVFS extends VFS {
15 |
16 | private final ResourcePatternResolver resourceResolver;
17 |
18 | public SpringBootVFS() {
19 | this.resourceResolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
20 | }
21 |
22 | @Override
23 | public boolean isValid() {
24 | return true;
25 | }
26 |
27 | @Override
28 | protected List list(URL url, String path) throws IOException {
29 | Resource[] resources = resourceResolver.getResources("classpath*:" + path + "/**/*.class");
30 | List resourcePaths = new ArrayList();
31 | for (Resource resource : resources) {
32 | resourcePaths.add(preserveSubpackageName(resource.getURI(), path));
33 | }
34 | return resourcePaths;
35 | }
36 |
37 | private static String preserveSubpackageName(final URI uri, final String rootPath) {
38 | final String uriStr = uri.toString();
39 | final int start = uriStr.indexOf(rootPath);
40 | return uriStr.substring(start);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/response/BaseResponse.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.response;
2 |
3 | public class BaseResponse {
4 | private Integer code;
5 | private String message;
6 |
7 | public BaseResponse() {
8 | }
9 |
10 | public BaseResponse(Integer code, String message) {
11 | super();
12 | this.code = code;
13 | this.message = message;
14 | }
15 |
16 | public Integer getCode() {
17 | return code;
18 | }
19 |
20 | public void setCode(Integer code) {
21 | this.code = code;
22 | }
23 |
24 | public String getMessage() {
25 | return message;
26 | }
27 |
28 | public void setMessage(String message) {
29 | this.message = message;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/response/BaseResponseAdvise.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.response;
2 |
3 | import org.apache.commons.logging.Log;
4 | import org.apache.commons.logging.LogFactory;
5 | import org.springframework.core.MethodParameter;
6 | import org.springframework.http.MediaType;
7 | import org.springframework.http.converter.HttpMessageConverter;
8 | import org.springframework.http.server.ServerHttpRequest;
9 | import org.springframework.http.server.ServerHttpResponse;
10 | import org.springframework.web.bind.annotation.ControllerAdvice;
11 | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
12 |
13 | //@ControllerAdvice()
14 | public class BaseResponseAdvise implements ResponseBodyAdvice {
15 |
16 | private static Log log = LogFactory.getLog(BaseResponseAdvise.class);
17 |
18 | @Override
19 | public boolean supports(MethodParameter returnType, Class extends HttpMessageConverter>> converterType) {
20 | log.info("===>" + (returnType.getGenericParameterType() instanceof BaseResponse));
21 | return returnType.getGenericParameterType() == BaseResponse.class;
22 | }
23 |
24 | @Override
25 | public BaseResponse beforeBodyWrite(BaseResponse body, MethodParameter returnType, MediaType selectedContentType,
26 | Class extends HttpMessageConverter>> selectedConverterType, ServerHttpRequest request,
27 | ServerHttpResponse response) {
28 | // body.setMessage("被我修改了");
29 | return body;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/response/MethodResponseHandler.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.response;
2 |
3 | import org.springframework.core.MethodParameter;
4 | import org.springframework.stereotype.Component;
5 | import org.springframework.web.context.request.NativeWebRequest;
6 | import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
7 | import org.springframework.web.method.support.ModelAndViewContainer;
8 |
9 | @Component
10 | public class MethodResponseHandler implements HandlerMethodReturnValueHandler {
11 |
12 | @Override
13 | public boolean supportsReturnType(MethodParameter returnType) {
14 | System.out.println("=====================? supportsReturnType");
15 | return true;
16 | }
17 |
18 | @Override
19 | public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
20 | NativeWebRequest webRequest) throws Exception {
21 | System.out.println("====================> handleReturnValue");
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/transaction/TransactionService.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.transaction;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.autoconfigure.AutoConfigureAfter;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.core.Ordered;
8 | import org.springframework.core.annotation.Order;
9 | import org.springframework.jdbc.datasource.DataSourceTransactionManager;
10 | import org.springframework.transaction.PlatformTransactionManager;
11 | import org.springframework.transaction.annotation.EnableTransactionManagement;
12 |
13 | import com.cml.springboot.framework.db.DynamicDataSourceAutoConfiguration.DynamicDataSource;
14 | import com.cml.springboot.framework.db.TransactionAspect;
15 |
16 | @AutoConfigureAfter(TransactionAspect.class)
17 | @Configuration
18 | @EnableTransactionManagement()
19 | public class TransactionService {
20 |
21 | @Autowired
22 | private DynamicDataSource dataSource;
23 |
24 |
25 | @Order(Ordered.LOWEST_PRECEDENCE)
26 | @Bean(name = "txManager")
27 | public PlatformTransactionManager txManager() {
28 | return new DataSourceTransactionManager(dataSource);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/util/LogUtil.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.util;
2 |
3 | public class LogUtil {
4 |
5 | private static final String FORMAT_CONTROLLER = "《《《《%s》》》》====>%s";
6 |
7 | public static String formatControllerLog(Object controller, String log) {
8 | return String.format(FORMAT_CONTROLLER, controller.getClass().getSimpleName(), log);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/util/MD5.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.util;
2 |
3 | import java.security.MessageDigest;
4 |
5 | public class MD5 {
6 | public static String getMD5(String source) {
7 | String s = null;
8 | char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
9 | 'a', 'b', 'c', 'd', 'e', 'f' };
10 | try {
11 | MessageDigest md5 = MessageDigest.getInstance("MD5");
12 | md5.update(source.getBytes());
13 | byte tmp[] = md5.digest();
14 | char str[] = new char[16 * 2];
15 | int k = 0;
16 | for (int i = 0; i < 16; i++) {
17 | byte byte0 = tmp[i];
18 | str[k++] = hexDigits[byte0 >>> 4 & 0xf];
19 | str[k++] = hexDigits[byte0 & 0xf];
20 | }
21 | s = new String(str);
22 |
23 | } catch (Exception ex) {
24 | ex.printStackTrace();
25 | }
26 | return s;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/framework/util/UUIDUtil.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.framework.util;
2 |
3 | import java.util.UUID;
4 |
5 | public class UUIDUtil {
6 |
7 | public static final String generateUUID() {
8 | return UUID.randomUUID().toString().toUpperCase().replaceAll("-", "");
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/bean/UserResponse.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.sample.bean;
2 |
3 | import com.cml.springboot.framework.response.BaseResponse;
4 |
5 | public class UserResponse extends BaseResponse {
6 | private User user;
7 |
8 | public UserResponse(Integer code, String message, User user) {
9 | super(code, message);
10 | this.user = user;
11 | }
12 |
13 | public UserResponse(Integer code, User user) {
14 | super(code, null);
15 | this.user = user;
16 | }
17 |
18 | public User getUser() {
19 | return user;
20 | }
21 |
22 | public void setUser(User user) {
23 | this.user = user;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/controller/ModelAttributeController.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.sample.controller;
2 |
3 | import java.sql.SQLException;
4 |
5 | import javax.annotation.Resource;
6 | import javax.validation.Valid;
7 |
8 | import org.apache.commons.lang.StringUtils;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.web.bind.annotation.ModelAttribute;
11 | import org.springframework.web.bind.annotation.RequestMapping;
12 | import org.springframework.web.bind.annotation.RequestParam;
13 | import org.springframework.web.bind.annotation.ResponseBody;
14 |
15 | import com.cml.springboot.sample.bean.User;
16 | import com.cml.springboot.sample.service.UserService;
17 |
18 | /**
19 | * ModelAttribute demo
20 | *
21 | * @author team-lab
22 | *
23 | */
24 | @Controller
25 | @RequestMapping("/model")
26 | public class ModelAttributeController {
27 |
28 | @Resource(name = "userServiceImpl")
29 | private UserService userService;
30 |
31 | @ModelAttribute("user")
32 | public User user(@RequestParam String token) throws SQLException {
33 | System.out.println("==================================================token:"+token);
34 | if (StringUtils.isBlank(token)) {
35 | return null;
36 | }
37 | return userService.findUserByToken(token);
38 | }
39 |
40 | @RequestMapping("/testA")
41 | @ResponseBody
42 | public String testA(@ModelAttribute() User user) {
43 | if (user == null) {
44 | return "user is null!!!!";
45 | }
46 | return "user:" + user.getUsername() + "," + user.getNickName();
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/db/LogMapper.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.sample.db;
2 |
3 | import com.cml.springboot.sample.bean.LogBean;
4 |
5 | public interface LogMapper {
6 | void insertLog(LogBean logbean);
7 | }
8 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/db/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.sample.db;
2 |
3 | import java.sql.SQLException;
4 |
5 | import com.cml.springboot.sample.bean.User;
6 |
7 | public interface UserMapper {
8 | User getUserByToken(String token) throws SQLException;
9 |
10 | User getUser(User user);
11 |
12 | Integer updateToken(User loginUser);
13 | }
14 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/db/resource/log.sql.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | INSERT INTO t_api_log (
7 | call_day,
8 | parameters,
9 | return_status_code,
10 | returns,
11 | api_url,
12 | create_date,
13 | update_date
14 |
15 | )
16 | VALUES (
17 | #{callDayStr},
18 | #{parameters},
19 | #{returnStatusCode},
20 | #{returns},
21 | #{apiUrl},
22 | #{createDate},
23 | NOW()
24 | )
25 |
26 |
27 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/db/resource/user.sql.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
35 |
36 |
37 | UPDATE
38 | t_user
39 | SET
40 | token = #{newToken},
41 | update_date = NOW()
42 | WHERE
43 | token = #{token}
44 |
45 |
46 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/service/LogService.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.sample.service;
2 |
3 | import com.cml.springboot.sample.bean.LogBean;
4 |
5 | public interface LogService {
6 | void insertLog(LogBean logbean);
7 |
8 | void insertLogReadOnly(LogBean logbean);
9 | }
10 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/java/com/cml/springboot/sample/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.sample.service;
2 |
3 | import java.sql.SQLException;
4 |
5 | import com.cml.springboot.sample.bean.User;
6 |
7 | public interface UserService {
8 | User findUserByToken(String token) throws SQLException;
9 |
10 | User login(User user) throws Exception;
11 | }
12 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/resources/ValidationMessages.properties:
--------------------------------------------------------------------------------
1 | user.empty.username=\u7528\u6237\u540d\u4e0d\u80fd\u4e3a\u7a7axxxxx
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | I am a banner!!!
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/resources/config/application.properties:
--------------------------------------------------------------------------------
1 | endpoints.beans.id=springbeans
2 | endpoints.beans.sensitive=false
3 | endpoints.shutdown.enabled=true
4 |
5 | spring.datasource.initialize=false
6 |
7 | # \u81ea\u5b9a\u4e49\u7aef\u53e3
8 | server.port=8080
9 |
10 | #\u5173\u95edbanner\u8bbe\u7f6e
11 | spring.main.banner-mode=off
12 |
13 | #spring.resources.staticLocations=*\.html,/*.html
14 | #spring.devtools.restart.exclude=static/**,public/**,src/main/webapp/**
15 |
16 | spring.mvc.view.prefix=/
17 | spring.mvc.view.suffix=.jsp
18 | application.message=Hello Phil
19 |
20 |
21 | #\u5f02\u6b65\u5904\u7406\u914d\u7f6e
22 | async.task.config.corePoolSize=5
23 | async.task.config.maxPoolSize=500
24 |
25 | #\u5f02\u5e38\u8fd4\u56de\u5904\u7406\u914d\u7f6e true\u8868\u793a\u4e0d\u5bf9\u5916\u66b4\u9732\u5f02\u5e38\u4fe1\u606f\uff0c\u53ea\u8fd4\u56de\u56fa\u5b9a\u7684${exception.response.messasge}
26 | exception.response.filter=true
27 | #exception.response.contentType=application/json
28 | exception.response.messasge=exception
29 |
30 | #log\u914d\u7f6e TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF.
31 | #logging.file=logs/api.log
32 | #logging.path=logs %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
33 | #logging.level.root=INFO
34 | #logging.level.org.springframework.web=DEBUG
35 | #logging.level.org.hibernate=ERROR
36 |
37 |
38 | #logging.config=classpath:log4j2.xml
39 |
40 |
41 | #\u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e
42 | dynamicDatasource.strategy.read=get,find,select
43 | dynamicDatasource.strategy.write=insert,update,delete,login
44 | dynamicDatasource.defaultDataSource=write
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | # LOG4J\u914d\u7f6e
2 | log4j.rootCategory=INFO,stdout,file
3 | log4j.logger.com.cml.springboot.framework.interceptor=INFO,logfile
4 | log4j.logger.org.mybatis.spring.SqlSessionFactoryBean=ALL,stdout,logfile
5 |
6 | ###\u663e\u793aSQL\u8bed\u53e5\u90e8\u5206
7 | log4j.logger.org.mybatis=ALL
8 | log4j.logger.org.apache=ALL
9 | log4j.logger.org.apache.ibatis.logging.jdbc=ALL
10 | log4j.logger.java.sql=ALL
11 | log4j.logger.com.cml.springboot=ALL
12 |
13 | # \u63a7\u5236\u53f0\u8f93\u51fa
14 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
15 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
16 | log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
17 |
18 | # \u65e5\u5fd7\u8f93\u51fa\u5230\u6587\u4ef6
19 | log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
20 | log4j.appender.file.file=logs/springboot.log
21 | log4j.appender.file.DatePattern='.'yyyy-MM-dd
22 | log4j.appender.file.layout=org.apache.log4j.PatternLayout
23 | log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
24 |
25 | # \u65e5\u5fd7\u8f93\u51fa\u5230\u6587\u4ef6
26 | log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
27 | log4j.appender.logfile.file=logs/api.log
28 | log4j.appender.logfile.DatePattern='.'yyyy-MM-dd
29 | log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
30 | log4j.appender.logfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/resources/public/error/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 | 404
8 |
9 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/WEB-INF/jsp/test.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 |
7 | Insert title here
8 |
9 |
10 | 234567890=-"src/main/webapp/test.jsp"
11 |
12 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/WEB-INF/jsp/welcome.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 |
10 |
11 | Spring URL: ${springUrl} at ${time}
12 |
13 | JSTL URL: ${url}
14 |
15 | Message: ${message}
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 |
8 | master api demo
9 |
10 |
16 | 注:为了测试方便,将请求url设置为可接受get方式
17 |
18 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/demo.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
4 |
5 |
6 |
7 |
8 | Insert title here
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/error.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 |
7 | Insert title here
8 |
9 |
10 | errors
11 |
12 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/static/demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 |
8 |
9 | 登录测试
10 | 登录测试
11 | 登录测试
12 |
13 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/test.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 |
7 | Insert title here
8 |
9 |
10 | 23456789 test
11 |
12 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/main/webapp/upload.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Insert title here
6 |
7 | upload
8 |
9 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/DynamicDataSource/src/test/java/com/cml/springboot/controller/test/DynamicDataSourceTest.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.controller.test;
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.context.SpringBootTest;
7 | import org.springframework.test.context.junit4.SpringRunner;
8 |
9 | import com.cml.springboot.BootApplication;
10 | import com.cml.springboot.sample.bean.User;
11 | import com.cml.springboot.sample.service.UserService;
12 |
13 | @RunWith(SpringRunner.class)
14 | @SpringBootTest(classes = BootApplication.class)
15 | public class DynamicDataSourceTest {
16 |
17 | @Autowired
18 | private UserService userService;
19 |
20 | @Test
21 | public void testLogin() throws Exception {
22 | User user = new User();
23 | user.setUsername("11111111111");
24 | user.setPassword("123456");
25 | User loginUser = userService.login(user);
26 | System.out.println("登录结果:" + loginUser);
27 | }
28 |
29 | @Test
30 | public void testFindUser() throws Exception {
31 | User loginUser = userService.findUserByToken("xxx");
32 | System.out.println("查询用户结果:" + loginUser);
33 | }
34 | }
--------------------------------------------------------------------------------
/DynamicDataSource/src/test/java/com/cml/springboot/controller/test/HelloControllerIT.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.controller.test;
2 |
3 | import java.net.URL;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.context.embedded.LocalServerPort;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.boot.test.web.client.TestRestTemplate;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | //@RunWith(SpringRunner.class)
16 | //@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
17 | public class HelloControllerIT {
18 |
19 | @LocalServerPort
20 | private int port;
21 |
22 | private URL base;
23 |
24 | @Autowired
25 | private TestRestTemplate template;
26 |
27 | @Before
28 | public void setUp() throws Exception {
29 | this.base = new URL("http://localhost:" + port + "/");
30 | }
31 |
32 | @Test
33 | public void getHello() throws Exception {
34 | ResponseEntity response = template.getForEntity(base.toString(), String.class);
35 | // assertThat(response.getBody(), equalTo("Hello World!"));
36 | }
37 | }
--------------------------------------------------------------------------------
/DynamicDataSource/src/test/java/com/cml/springboot/controller/test/HelloControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.controller.test;
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.AutoConfigureMockMvc;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.test.context.junit4.SpringRunner;
9 | import org.springframework.test.web.servlet.MockMvc;
10 |
11 | //@RunWith(SpringRunner.class)
12 | //@SpringBootTest
13 | //@AutoConfigureMockMvc
14 | public class HelloControllerTest {
15 |
16 | @Autowired
17 | private MockMvc mvc;
18 |
19 | @Test
20 | public void getHello() throws Exception {
21 | // mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
22 | // .andExpect(content().string(equalTo("Greetings from Spring Boot!")));
23 | }
24 | }
--------------------------------------------------------------------------------
/Kafka/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Kafka/.gitignore:
--------------------------------------------------------------------------------
1 | /.apt_generated/
2 |
--------------------------------------------------------------------------------
/Kafka/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Kafka
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Kafka/README.md:
--------------------------------------------------------------------------------
1 | # SpringBoot Learning #
2 |
3 | 此项目主要作为SpringBoot学习,和根据实际项目对SpringBoot进行配置改造
4 | 主要使用框架:SpringBoot(Spring,SpringMVC),Mybatis,ehcache,javamail
5 |
6 | # 项目结构 #
7 | - **程序入口**
8 | > com.cml.springboot.consumer.BootApplication
9 |
10 | - **核心配置**
11 | > com.cml.springboot.framework 是核心包,取代原有的xml配置,将xml配置等价转换为注解配置!
12 |
13 | - **demo代码**
14 | > com.cml.springboot.sample为测试使用的代码,主要结构为Controller,bean,db,service几个常用的包层级。
15 |
16 | - **db**
17 | > db文件夹下为demo工程的数据库ddl
18 |
19 | # 执行程序 #
20 | 详见:wiki Home page
21 | # 分支说明 #
22 |
23 | 1. master
24 |
25 | > 主要分支,模拟常用api功能。
26 |
27 | 2. branch_learn
28 |
29 | > 初始化分支,混杂各种spring boot学习代码,未做具体区分
30 |
31 | 3. branch_shiro
32 |
33 | > 整合shiro框架,实现授权,认证与自定义拦截器授权处理
34 |
35 | 4. deploy_jar_bugfind
36 |
37 | > 查找与解决打包jar后Mybatis扫描问题
38 |
39 | 5. branch_i18n
40 |
41 | > 国际化支持
42 |
43 | 6. branch_mail
44 |
45 | > 邮件发送功能整合,注意需要在config/application.properties配置邮箱服务密码
46 |
47 | 7. branch-mybatis-scanner
48 |
49 | > 添加Mybatis MapperScan动态扫描(占位符)功能 ,详情见博客:http://blog.csdn.net/cml_blog/article/details/65658654
50 |
51 | 8. branch-mybatis-generate
52 |
53 | > mybatis beans生成工具,默认日期类型为DateTime类型,入口类:com.cml.springboot.sample.mbg.MybatisGenerateEntrance
54 |
55 |
56 | #问题与解决
57 | 1、Mybatis打包jar后无法扫描到bean与mapper问题,解决对应地址http://blog.csdn.net/cml_blog/article/details/53138851
58 | 2、163发送邮件功能问题,解决对应地址http://blog.csdn.net/cml_blog/article/details/54235510
59 |
60 | # 当前分支(master)测试说明 #
61 | > 详见demo.html
62 | > 端口号为2222,可在config/application.properties 中server.port进行配置
63 |
64 | # 更多信息请查看wiki #
65 |
66 |
67 |
--------------------------------------------------------------------------------
/Kafka/src/main/i18n/messages.properties:
--------------------------------------------------------------------------------
1 | welcome=welcome to default
--------------------------------------------------------------------------------
/Kafka/src/main/i18n/messages_en_US.properties:
--------------------------------------------------------------------------------
1 | welcome=welcome to english
--------------------------------------------------------------------------------
/Kafka/src/main/i18n/messages_zh_CN.properties:
--------------------------------------------------------------------------------
1 | welcome=\u6b22\u8fce\u6765\u5230\u4e2d\u56fd
--------------------------------------------------------------------------------
/Kafka/src/main/java/com/cml/springboot/consumer/BootApplication.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.consumer;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.WebApplicationType;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.annotation.Profile;
7 | import org.springframework.kafka.annotation.EnableKafka;
8 | import org.springframework.scheduling.annotation.EnableAsync;
9 | import org.springframework.scheduling.annotation.EnableScheduling;
10 |
11 | @SpringBootApplication
12 | @EnableScheduling
13 | @EnableKafka
14 | public class BootApplication {
15 |
16 | public static void main(String[] args) throws Exception {
17 | SpringApplication app = new SpringApplication(BootApplication.class);
18 | app.setWebApplicationType(WebApplicationType.NONE);
19 | // app.setWebEnvironment(false);
20 | app.run(args);
21 | // SpringApplication.run(BootApplication.class, args);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/Kafka/src/main/java/com/cml/springboot/consumer/Consumer.java:
--------------------------------------------------------------------------------
1 | package com.cml.springboot.consumer;
2 |
3 | import com.cml.springboot.message.TestMessage;
4 | import org.apache.kafka.clients.consumer.ConsumerRecord;
5 | import org.springframework.kafka.annotation.KafkaListener;
6 | import org.springframework.scheduling.annotation.Async;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Component
10 | class Consumer {
11 |
12 | // @KafkaListener(topics = "test2")
13 | // public void processMessage(String message) throws Exception {
14 | // System.out.println("processMessage receivced sample message [" + message + "] threadId:" + Thread.currentThread().getId());
15 | //
16 | // }
17 |
18 | @KafkaListener(topics = "test2")
19 | public void processMessage2(TestMessage testMessage) throws Exception {
20 | System.out.println("processMessage2 receivced sample message [" + testMessage.toString() + "] threadId:" + Thread.currentThread().getId());
21 | // Thread.sleep(100);
22 | // if (Math.random() < 0.5)
23 | // throw new Exception("出错了:" + testMessage.toString());
24 |
25 | }
26 | // @KafkaListener(topics = "test2")
27 | // public void processMessage(ConsumerRecord