values = DynamicDataSource.METHOD_TYPE_MAP.get(type);
41 | for (String key : values) {
42 | if (method.startsWith(key)) {
43 | logger.info(">>{} 方法使用的数据源为:{}<<", method, key);
44 | DatabaseContextHolder.setDatabaseType(type);
45 | DatabaseType types = DatabaseContextHolder.getDatabaseType();
46 | logger.info(">>{}方法使用的数据源为:{}<<", method, types);
47 | }
48 | }
49 | }
50 | } catch (Exception e) {
51 | logger.error(e.getMessage(), e);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Spring-Blog-business/src/main/java/com/charles/business/model/BaseEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014-2016 abel533@gmail.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | package com.charles.business.model;
26 |
27 | import javax.persistence.*;
28 | import java.io.Serializable;
29 |
30 |
31 | public class BaseEntity implements Serializable {
32 | @Id
33 | @Column(name = "Id")
34 | @GeneratedValue(strategy = GenerationType.IDENTITY)
35 | private Integer id;
36 |
37 | @Transient
38 | private Integer page = 1;
39 |
40 | @Transient
41 | private Integer rows = 10;
42 |
43 | public Integer getId() {
44 | return id;
45 | }
46 |
47 | public void setId(Integer id) {
48 | this.id = id;
49 | }
50 |
51 | public Integer getPage() {
52 | return page;
53 | }
54 |
55 | public void setPage(Integer page) {
56 | this.page = page;
57 | }
58 |
59 | public Integer getRows() {
60 | return rows;
61 | }
62 |
63 | public void setRows(Integer rows) {
64 | this.rows = rows;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/resource/charles_blog-01-17.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat MySQL Data Transfer
3 |
4 | Source Server : 本地数据库
5 | Source Server Version : 50621
6 | Source Host : localhost:3306
7 | Source Database : charles_blog
8 |
9 | Target Server Type : MYSQL
10 | Target Server Version : 50621
11 | File Encoding : 65001
12 |
13 | Date: 2018-01-17 14:44:11
14 | */
15 |
16 | SET FOREIGN_KEY_CHECKS=0;
17 |
18 | -- ----------------------------
19 | -- Table structure for user
20 | -- ----------------------------
21 | DROP TABLE IF EXISTS `user`;
22 | CREATE TABLE `user` (
23 | `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键',
24 | `username` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '用户名',
25 | `phone` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '手机',
26 | `idCard` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '身份证',
27 | `password` varchar(100) COLLATE utf8_bin DEFAULT NULL COMMENT '密码',
28 | PRIMARY KEY (`id`)
29 | ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
30 |
31 | -- ----------------------------
32 | -- Records of user
33 | -- ----------------------------
34 | INSERT INTO `user` VALUES ('1', 'Charles', '18814127283', '440182199512042311', 'jaycekon');
35 | INSERT INTO `user` VALUES ('4', '1234', '123', '1234', 'Jaycekon');
36 | INSERT INTO `user` VALUES ('5', '1234', '123', '1234', 'Jaycekon');
37 | INSERT INTO `user` VALUES ('6', '1234', '123', '1234', 'Jaycekon');
38 | INSERT INTO `user` VALUES ('7', '1234', '123', '1234', 'Jaycekon');
39 | INSERT INTO `user` VALUES ('8', '1234', '123', '1234', 'Jaycekon');
40 | INSERT INTO `user` VALUES ('9', '1234', '123', '1234', 'Jaycekon');
41 | INSERT INTO `user` VALUES ('10', '1234', '123', '1234', 'Jaycekon');
42 | INSERT INTO `user` VALUES ('11', 'Charles', '18891202121', '4402912131231231', '952102');
43 | INSERT INTO `user` VALUES ('12', '1234', '123', '1234', 'Jaycekon');
44 | INSERT INTO `user` VALUES ('13', '1234', '123', '1234', 'Jaycekon');
45 | INSERT INTO `user` VALUES ('14', '1234', '123', '1234', 'Jaycekon');
46 | INSERT INTO `user` VALUES ('15', '1234', '123', '1234', 'Jaycekon');
47 | INSERT INTO `user` VALUES ('16', '1234', '123', '1234', 'Jaycekon');
48 | INSERT INTO `user` VALUES ('17', '1234', '123', '1234', 'Jaycekon');
49 | INSERT INTO `user` VALUES ('18', '1234', '123', '1234', 'Jaycekon');
50 | INSERT INTO `user` VALUES ('19', '1234', '123', '1234', 'Jaycekon');
51 |
--------------------------------------------------------------------------------
/Spring-Blog-api/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Spring-Blog-webflux/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/.idea/libraries/Arquillian_JUnit_Release.xml:
--------------------------------------------------------------------------------
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 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/Spring-Blog-api/src/main/java/com/charles/api/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package com.charles.api.controller;
2 |
3 | import com.charles.business.mapper.UserMapper;
4 | import com.charles.business.model.User;
5 | import io.swagger.annotations.Api;
6 | import io.swagger.annotations.ApiImplicitParam;
7 | import io.swagger.annotations.ApiOperation;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.stereotype.Controller;
12 | import org.springframework.ui.Model;
13 | import org.springframework.web.bind.annotation.*;
14 | import org.springframework.web.servlet.ModelAndView;
15 | import springfox.documentation.annotations.ApiIgnore;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * 获取用户基本信息类,用于测试读写分离
21 | *
22 | * 2018/1/17 14:08
23 | */
24 | @RequestMapping("/users")
25 | @Api(tags = "用户数据API")
26 | @Controller
27 | public class UserController {
28 | private Logger logger = LoggerFactory.getLogger(UserController.class);
29 |
30 | @Autowired
31 | private UserMapper userMapper;
32 |
33 |
34 | @ApiOperation(value = "查找用户", notes = "根据 IdCard 获取用户")
35 | @RequestMapping(value = "/lists", method = RequestMethod.GET)
36 | @ResponseBody
37 | public User findByIdCard(String idCard) {
38 | User u = userMapper.selectByIdCard(idCard);
39 | logger.info("获取结果:{}", u);
40 | return u;
41 | }
42 |
43 |
44 | @ApiOperation(value = "保存用户", notes = "保存用户")
45 | @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
46 | @RequestMapping(value = "/save", method = RequestMethod.POST)
47 | public User saveUser(@RequestBody User user) {
48 | userMapper.insert(user);
49 | logger.info("保存结果:{}", user);
50 | return user;
51 | }
52 |
53 |
54 | @ApiIgnore
55 | @RequestMapping(value = "/list", method = RequestMethod.GET)
56 | public String list(Model model) {
57 | List users = userMapper.selectAll();
58 | model.addAttribute("users", users);
59 | model.addAttribute("title", "用户管理");
60 | return "user/list";
61 | }
62 |
63 | @ApiIgnore
64 | @RequestMapping(value = "/{id}", method = RequestMethod.GET)
65 | public String query(@PathVariable String id, Model model) {
66 | User user = userMapper.selectByPrimaryKey(Integer.valueOf(id));
67 | model.addAttribute("user", user);
68 | model.addAttribute("title", "查看用户");
69 | return "user/view";
70 | }
71 |
72 |
73 | @ApiIgnore
74 | @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
75 | public String saveOrUpdate(User user) {
76 | User temp = userMapper.selectByPrimaryKey(user.getId());
77 | if (temp == null) {
78 | userMapper.insert(user);
79 | } else {
80 | user.setId(temp.getId());
81 | userMapper.updateByPrimaryKeySelective(user);
82 | }
83 | return "redirect:list";
84 | }
85 |
86 |
87 | @ApiIgnore
88 | @RequestMapping(value = "delete/{id}", method = RequestMethod.GET)
89 | public ModelAndView delete(@PathVariable Integer id) {
90 | userMapper.deleteByPrimaryKey(id);
91 | return new ModelAndView("redirect:/users/list");
92 | }
93 |
94 |
95 | @ApiIgnore
96 | @RequestMapping(value = "modify/{id}")
97 | public String modify(@PathVariable Integer id, Model model) {
98 | User user = userMapper.selectByPrimaryKey(id);
99 | model.addAttribute("user", user);
100 | model.addAttribute("title", "修改用户");
101 | return "user/form";
102 | }
103 |
104 |
105 | @ApiIgnore
106 | @RequestMapping(value = "form")
107 | public String form(Model model) {
108 | model.addAttribute("user", new User());
109 | model.addAttribute("title", "创建用户");
110 | return "user/form";
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/.idea/modules/Spring-Blog-business/Spring-Blog-business_main.iml:
--------------------------------------------------------------------------------
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 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/.idea/modules/Spring-Blog-business/Spring-Blog-business_test.iml:
--------------------------------------------------------------------------------
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 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/Spring-Blog-api/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Spring-Blog-webflux/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Spring-Blog-api/src/main/java/com/charles/api/config/dataSource/DataSourceConfig.java:
--------------------------------------------------------------------------------
1 | package com.charles.api.config.dataSource;
2 |
3 | import com.alibaba.druid.pool.DruidDataSource;
4 | import org.apache.ibatis.session.SqlSessionFactory;
5 | import org.mybatis.spring.SqlSessionFactoryBean;
6 | import org.mybatis.spring.annotation.MapperScan;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.beans.factory.annotation.Qualifier;
11 | import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
12 | import org.springframework.boot.context.properties.ConfigurationProperties;
13 | import org.springframework.boot.jdbc.DataSourceBuilder;
14 | import org.springframework.context.annotation.Bean;
15 | import org.springframework.context.annotation.Configuration;
16 | import org.springframework.context.annotation.Primary;
17 | import org.springframework.core.env.Environment;
18 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
19 | import org.springframework.jdbc.datasource.DataSourceTransactionManager;
20 | import org.springframework.transaction.annotation.EnableTransactionManagement;
21 |
22 | import javax.sql.DataSource;
23 | import java.sql.SQLException;
24 | import java.util.HashMap;
25 | import java.util.Map;
26 |
27 | /**
28 | * 2018/1/15 18:46
29 | */
30 | @Configuration
31 | @MapperScan("com.charles.business.mapper")
32 | @EnableTransactionManagement
33 | public class DataSourceConfig {
34 |
35 | private static Logger logger = LoggerFactory.getLogger(DataSourceConfig.class);
36 |
37 | @Autowired
38 | private Environment env;
39 |
40 | @Autowired
41 | private DataSourceProperties properties;
42 |
43 | /**
44 | * 通过Spring JDBC 快速创建 DataSource
45 | * 参数格式
46 | * spring.datasource.master.jdbcurl=jdbc:mysql://localhost:3306/charles_blog
47 | * spring.datasource.master.username=root
48 | * spring.datasource.master.password=root
49 | * spring.datasource.master.driver-class-name=com.mysql.jdbc.Driver
50 | *
51 | * @return DataSource
52 | */
53 | @Bean(name = "masterDataSource")
54 | @Qualifier("masterDataSource")
55 | @ConfigurationProperties(prefix = "spring.datasource.master")
56 | public DataSource masterDataSource() {
57 | return DataSourceBuilder.create().build();
58 | }
59 |
60 |
61 | /**
62 | * 手动创建DruidDataSource,通过DataSourceProperties 读取配置
63 | * 参数格式
64 | * spring.datasource.url=jdbc:mysql://localhost:3306/charles_blog
65 | * spring.datasource.username=root
66 | * spring.datasource.password=root
67 | * spring.datasource.driver-class-name=com.mysql.jdbc.Driver
68 | *
69 | * @return DataSource
70 | * @throws SQLException
71 | */
72 | @Bean(name = "slaveDataSource")
73 | @Qualifier("slaveDataSource")
74 | public DataSource slaveDataSource() throws SQLException {
75 | DruidDataSource dataSource = new DruidDataSource();
76 | dataSource.setUrl(properties.getUrl());
77 | dataSource.setDriverClassName(properties.getDriverClassName());
78 | dataSource.setUsername(properties.getUsername());
79 | dataSource.setPassword(properties.getPassword());
80 | dataSource.setInitialSize(5);
81 | dataSource.setMinIdle(5);
82 | dataSource.setMaxActive(100);
83 | dataSource.setMaxWait(60000);
84 | dataSource.setTimeBetweenEvictionRunsMillis(60000);
85 | dataSource.setMinEvictableIdleTimeMillis(300000);
86 | dataSource.setValidationQuery("SELECT 'x'");
87 | dataSource.setTestWhileIdle(true);
88 | dataSource.setTestOnBorrow(false);
89 | dataSource.setTestOnReturn(false);
90 | dataSource.setPoolPreparedStatements(true);
91 | dataSource.setMaxPoolPreparedStatementPerConnectionSize(20);
92 | dataSource.setFilters("stat,wall");
93 | return dataSource;
94 | }
95 |
96 |
97 | /**
98 | * 构造多数据源连接池
99 | * Master 数据源连接池采用 HikariDataSource
100 | * Slave 数据源连接池采用 DruidDataSource
101 | * @param master
102 | * @param slave
103 | * @return
104 | */
105 | @Bean
106 | @Primary
107 | public DynamicDataSource dataSource(@Qualifier("masterDataSource") DataSource master,
108 | @Qualifier("slaveDataSource") DataSource slave) {
109 | Map