yufeng 6 years ago
parent
commit
3e63ae0601

+ 2 - 0
.gitignore

@@ -53,3 +53,5 @@ local.properties
53 53
 # TeXlipse plugin
54 54
 .texlipse
55 55
 
56
+/target/
57
+LOG_PATH_IS_UNDEFINED/

+ 225 - 0
mvnw

@@ -0,0 +1,225 @@
1
+#!/bin/sh
2
+# ----------------------------------------------------------------------------
3
+# Licensed to the Apache Software Foundation (ASF) under one
4
+# or more contributor license agreements.  See the NOTICE file
5
+# distributed with this work for additional information
6
+# regarding copyright ownership.  The ASF licenses this file
7
+# to you under the Apache License, Version 2.0 (the
8
+# "License"); you may not use this file except in compliance
9
+# with the License.  You may obtain a copy of the License at
10
+#
11
+#    http://www.apache.org/licenses/LICENSE-2.0
12
+#
13
+# Unless required by applicable law or agreed to in writing,
14
+# software distributed under the License is distributed on an
15
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+# KIND, either express or implied.  See the License for the
17
+# specific language governing permissions and limitations
18
+# under the License.
19
+# ----------------------------------------------------------------------------
20
+
21
+# ----------------------------------------------------------------------------
22
+# Maven2 Start Up Batch script
23
+#
24
+# Required ENV vars:
25
+# ------------------
26
+#   JAVA_HOME - location of a JDK home dir
27
+#
28
+# Optional ENV vars
29
+# -----------------
30
+#   M2_HOME - location of maven2's installed home dir
31
+#   MAVEN_OPTS - parameters passed to the Java VM when running Maven
32
+#     e.g. to debug Maven itself, use
33
+#       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34
+#   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35
+# ----------------------------------------------------------------------------
36
+
37
+if [ -z "$MAVEN_SKIP_RC" ] ; then
38
+
39
+  if [ -f /etc/mavenrc ] ; then
40
+    . /etc/mavenrc
41
+  fi
42
+
43
+  if [ -f "$HOME/.mavenrc" ] ; then
44
+    . "$HOME/.mavenrc"
45
+  fi
46
+
47
+fi
48
+
49
+# OS specific support.  $var _must_ be set to either true or false.
50
+cygwin=false;
51
+darwin=false;
52
+mingw=false
53
+case "`uname`" in
54
+  CYGWIN*) cygwin=true ;;
55
+  MINGW*) mingw=true;;
56
+  Darwin*) darwin=true
57
+    # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59
+    if [ -z "$JAVA_HOME" ]; then
60
+      if [ -x "/usr/libexec/java_home" ]; then
61
+        export JAVA_HOME="`/usr/libexec/java_home`"
62
+      else
63
+        export JAVA_HOME="/Library/Java/Home"
64
+      fi
65
+    fi
66
+    ;;
67
+esac
68
+
69
+if [ -z "$JAVA_HOME" ] ; then
70
+  if [ -r /etc/gentoo-release ] ; then
71
+    JAVA_HOME=`java-config --jre-home`
72
+  fi
73
+fi
74
+
75
+if [ -z "$M2_HOME" ] ; then
76
+  ## resolve links - $0 may be a link to maven's home
77
+  PRG="$0"
78
+
79
+  # need this for relative symlinks
80
+  while [ -h "$PRG" ] ; do
81
+    ls=`ls -ld "$PRG"`
82
+    link=`expr "$ls" : '.*-> \(.*\)$'`
83
+    if expr "$link" : '/.*' > /dev/null; then
84
+      PRG="$link"
85
+    else
86
+      PRG="`dirname "$PRG"`/$link"
87
+    fi
88
+  done
89
+
90
+  saveddir=`pwd`
91
+
92
+  M2_HOME=`dirname "$PRG"`/..
93
+
94
+  # make it fully qualified
95
+  M2_HOME=`cd "$M2_HOME" && pwd`
96
+
97
+  cd "$saveddir"
98
+  # echo Using m2 at $M2_HOME
99
+fi
100
+
101
+# For Cygwin, ensure paths are in UNIX format before anything is touched
102
+if $cygwin ; then
103
+  [ -n "$M2_HOME" ] &&
104
+    M2_HOME=`cygpath --unix "$M2_HOME"`
105
+  [ -n "$JAVA_HOME" ] &&
106
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107
+  [ -n "$CLASSPATH" ] &&
108
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109
+fi
110
+
111
+# For Migwn, ensure paths are in UNIX format before anything is touched
112
+if $mingw ; then
113
+  [ -n "$M2_HOME" ] &&
114
+    M2_HOME="`(cd "$M2_HOME"; pwd)`"
115
+  [ -n "$JAVA_HOME" ] &&
116
+    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117
+  # TODO classpath?
118
+fi
119
+
120
+if [ -z "$JAVA_HOME" ]; then
121
+  javaExecutable="`which javac`"
122
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123
+    # readlink(1) is not available as standard on Solaris 10.
124
+    readLink=`which readlink`
125
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126
+      if $darwin ; then
127
+        javaHome="`dirname \"$javaExecutable\"`"
128
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129
+      else
130
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
131
+      fi
132
+      javaHome="`dirname \"$javaExecutable\"`"
133
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134
+      JAVA_HOME="$javaHome"
135
+      export JAVA_HOME
136
+    fi
137
+  fi
138
+fi
139
+
140
+if [ -z "$JAVACMD" ] ; then
141
+  if [ -n "$JAVA_HOME"  ] ; then
142
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143
+      # IBM's JDK on AIX uses strange locations for the executables
144
+      JAVACMD="$JAVA_HOME/jre/sh/java"
145
+    else
146
+      JAVACMD="$JAVA_HOME/bin/java"
147
+    fi
148
+  else
149
+    JAVACMD="`which java`"
150
+  fi
151
+fi
152
+
153
+if [ ! -x "$JAVACMD" ] ; then
154
+  echo "Error: JAVA_HOME is not defined correctly." >&2
155
+  echo "  We cannot execute $JAVACMD" >&2
156
+  exit 1
157
+fi
158
+
159
+if [ -z "$JAVA_HOME" ] ; then
160
+  echo "Warning: JAVA_HOME environment variable is not set."
161
+fi
162
+
163
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164
+
165
+# traverses directory structure from process work directory to filesystem root
166
+# first directory with .mvn subdirectory is considered project base directory
167
+find_maven_basedir() {
168
+
169
+  if [ -z "$1" ]
170
+  then
171
+    echo "Path not specified to find_maven_basedir"
172
+    return 1
173
+  fi
174
+
175
+  basedir="$1"
176
+  wdir="$1"
177
+  while [ "$wdir" != '/' ] ; do
178
+    if [ -d "$wdir"/.mvn ] ; then
179
+      basedir=$wdir
180
+      break
181
+    fi
182
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183
+    if [ -d "${wdir}" ]; then
184
+      wdir=`cd "$wdir/.."; pwd`
185
+    fi
186
+    # end of workaround
187
+  done
188
+  echo "${basedir}"
189
+}
190
+
191
+# concatenates all lines of a file
192
+concat_lines() {
193
+  if [ -f "$1" ]; then
194
+    echo "$(tr -s '\n' ' ' < "$1")"
195
+  fi
196
+}
197
+
198
+BASE_DIR=`find_maven_basedir "$(pwd)"`
199
+if [ -z "$BASE_DIR" ]; then
200
+  exit 1;
201
+fi
202
+
203
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204
+echo $MAVEN_PROJECTBASEDIR
205
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206
+
207
+# For Cygwin, switch paths to Windows format before running java
208
+if $cygwin; then
209
+  [ -n "$M2_HOME" ] &&
210
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
211
+  [ -n "$JAVA_HOME" ] &&
212
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213
+  [ -n "$CLASSPATH" ] &&
214
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217
+fi
218
+
219
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220
+
221
+exec "$JAVACMD" \
222
+  $MAVEN_OPTS \
223
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 143 - 0
mvnw.cmd

@@ -0,0 +1,143 @@
1
+@REM ----------------------------------------------------------------------------
2
+@REM Licensed to the Apache Software Foundation (ASF) under one
3
+@REM or more contributor license agreements.  See the NOTICE file
4
+@REM distributed with this work for additional information
5
+@REM regarding copyright ownership.  The ASF licenses this file
6
+@REM to you under the Apache License, Version 2.0 (the
7
+@REM "License"); you may not use this file except in compliance
8
+@REM with the License.  You may obtain a copy of the License at
9
+@REM
10
+@REM    http://www.apache.org/licenses/LICENSE-2.0
11
+@REM
12
+@REM Unless required by applicable law or agreed to in writing,
13
+@REM software distributed under the License is distributed on an
14
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+@REM KIND, either express or implied.  See the License for the
16
+@REM specific language governing permissions and limitations
17
+@REM under the License.
18
+@REM ----------------------------------------------------------------------------
19
+
20
+@REM ----------------------------------------------------------------------------
21
+@REM Maven2 Start Up Batch script
22
+@REM
23
+@REM Required ENV vars:
24
+@REM JAVA_HOME - location of a JDK home dir
25
+@REM
26
+@REM Optional ENV vars
27
+@REM M2_HOME - location of maven2's installed home dir
28
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31
+@REM     e.g. to debug Maven itself, use
32
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34
+@REM ----------------------------------------------------------------------------
35
+
36
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37
+@echo off
38
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39
+@if "%MAVEN_BATCH_ECHO%" == "on"  echo %MAVEN_BATCH_ECHO%
40
+
41
+@REM set %HOME% to equivalent of $HOME
42
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43
+
44
+@REM Execute a user defined script before this one
45
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
47
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49
+:skipRcPre
50
+
51
+@setlocal
52
+
53
+set ERROR_CODE=0
54
+
55
+@REM To isolate internal variables from possible post scripts, we use another setlocal
56
+@setlocal
57
+
58
+@REM ==== START VALIDATION ====
59
+if not "%JAVA_HOME%" == "" goto OkJHome
60
+
61
+echo.
62
+echo Error: JAVA_HOME not found in your environment. >&2
63
+echo Please set the JAVA_HOME variable in your environment to match the >&2
64
+echo location of your Java installation. >&2
65
+echo.
66
+goto error
67
+
68
+:OkJHome
69
+if exist "%JAVA_HOME%\bin\java.exe" goto init
70
+
71
+echo.
72
+echo Error: JAVA_HOME is set to an invalid directory. >&2
73
+echo JAVA_HOME = "%JAVA_HOME%" >&2
74
+echo Please set the JAVA_HOME variable in your environment to match the >&2
75
+echo location of your Java installation. >&2
76
+echo.
77
+goto error
78
+
79
+@REM ==== END VALIDATION ====
80
+
81
+:init
82
+
83
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84
+@REM Fallback to current working directory if not found.
85
+
86
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88
+
89
+set EXEC_DIR=%CD%
90
+set WDIR=%EXEC_DIR%
91
+:findBaseDir
92
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
93
+cd ..
94
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
95
+set WDIR=%CD%
96
+goto findBaseDir
97
+
98
+:baseDirFound
99
+set MAVEN_PROJECTBASEDIR=%WDIR%
100
+cd "%EXEC_DIR%"
101
+goto endDetectBaseDir
102
+
103
+:baseDirNotFound
104
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105
+cd "%EXEC_DIR%"
106
+
107
+:endDetectBaseDir
108
+
109
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110
+
111
+@setlocal EnableExtensions EnableDelayedExpansion
112
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114
+
115
+:endReadAdditionalConfig
116
+
117
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118
+
119
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121
+
122
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123
+if ERRORLEVEL 1 goto error
124
+goto end
125
+
126
+:error
127
+set ERROR_CODE=1
128
+
129
+:end
130
+@endlocal & set ERROR_CODE=%ERROR_CODE%
131
+
132
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
134
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136
+:skipRcPost
137
+
138
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
140
+
141
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142
+
143
+exit /B %ERROR_CODE%

+ 174 - 0
pom.xml

@@ -0,0 +1,174 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+
6
+	<groupId>yike.example</groupId>
7
+	<artifactId>demo</artifactId>
8
+	<version>0.0.1-SNAPSHOT</version>
9
+	<packaging>jar</packaging>
10
+
11
+	<name>demo</name>
12
+	<description>Demo project for Spring Boot</description>
13
+
14
+	<parent>
15
+		<groupId>org.springframework.boot</groupId>
16
+		<artifactId>spring-boot-starter-parent</artifactId>
17
+		<version>1.5.9.RELEASE</version>
18
+		<relativePath/> <!-- lookup parent from repository -->
19
+	</parent>
20
+
21
+	<properties>
22
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
+		<java.version>1.8</java.version>
25
+	</properties>
26
+
27
+	<dependencies>
28
+		<dependency>
29
+			<groupId>org.springframework.boot</groupId>
30
+			<artifactId>spring-boot-starter</artifactId>
31
+		</dependency>
32
+
33
+		<dependency>
34
+			<groupId>org.springframework.boot</groupId>
35
+			<artifactId>spring-boot-starter-test</artifactId>
36
+			<scope>test</scope>
37
+		</dependency>
38
+
39
+		<dependency>
40
+			<groupId>org.springframework.boot</groupId>
41
+			<artifactId>spring-boot-starter-web</artifactId>
42
+		</dependency>
43
+
44
+		<!-- redis -->
45
+		<dependency>
46
+			<groupId>org.springframework.boot</groupId>
47
+			<artifactId>spring-boot-starter-data-redis</artifactId>
48
+		</dependency>
49
+
50
+		<!-- 数据层 -->
51
+		<dependency>
52
+			<groupId>org.springframework.boot</groupId>
53
+			<artifactId>spring-boot-starter-jdbc</artifactId>
54
+		</dependency>
55
+		
56
+		<dependency>
57
+			<groupId>org.mybatis.spring.boot</groupId>
58
+			<artifactId>mybatis-spring-boot-starter</artifactId>
59
+			<version>1.0.0</version>
60
+		</dependency>
61
+		<dependency>
62
+			<groupId>org.mybatis</groupId>
63
+			<artifactId>mybatis</artifactId>
64
+			<version>3.2.8</version>
65
+		</dependency>
66
+		<dependency>
67
+			<groupId>org.mybatis</groupId>
68
+			<artifactId>mybatis-spring</artifactId>
69
+			<version>1.2.2</version>
70
+		</dependency>
71
+		<dependency>
72
+			<groupId>com.alibaba</groupId>
73
+			<artifactId>druid</artifactId>
74
+			<version>1.0.18</version>
75
+		</dependency>
76
+		<dependency>
77
+			<groupId>com.alibaba</groupId>
78
+			<artifactId>druid-spring-boot-starter</artifactId>
79
+			<version>1.1.0</version>
80
+		</dependency>
81
+		<dependency>
82
+			<groupId>mysql</groupId>
83
+			<artifactId>mysql-connector-java</artifactId>
84
+		</dependency>
85
+		<!-- Swagger -->
86
+		<dependency>
87
+			<groupId>io.springfox</groupId>
88
+			<artifactId>springfox-swagger-ui</artifactId>
89
+			<version>2.6.0</version>
90
+		</dependency>
91
+
92
+		<dependency>
93
+			<groupId>io.springfox</groupId>
94
+			<artifactId>springfox-swagger2</artifactId>
95
+			<version>2.6.0</version>
96
+		</dependency>
97
+		
98
+		<!-- amqp -->
99
+		<dependency>
100
+			<groupId>org.springframework.boot</groupId>
101
+			<artifactId>spring-boot-starter-amqp</artifactId>
102
+		</dependency>
103
+ 
104
+		<!-- util -->
105
+		<dependency>
106
+			<groupId>com.google.guava</groupId>
107
+			<artifactId>guava</artifactId>
108
+			<version>18.0</version>
109
+		</dependency>
110
+		
111
+		<dependency>
112
+		    <groupId>com.alibaba</groupId>
113
+		    <artifactId>fastjson</artifactId>
114
+		    <version>1.2.45</version>
115
+		</dependency>
116
+		<!-- 二方包 -->
117
+		
118
+	</dependencies>
119
+
120
+	<build>
121
+		<plugins>
122
+			<plugin>
123
+				<groupId>org.springframework.boot</groupId>
124
+				<artifactId>spring-boot-maven-plugin</artifactId>
125
+			</plugin>
126
+
127
+			<plugin>
128
+				<groupId>org.codehaus.mojo</groupId>
129
+				<artifactId>build-helper-maven-plugin</artifactId>
130
+				<executions>
131
+					<execution>
132
+						<id>add-resource</id>
133
+						<phase>generate-resources</phase>
134
+						<goals>
135
+							<goal>add-resource</goal>
136
+						</goals>
137
+						<configuration>
138
+							<resources>
139
+								<resource>
140
+									<directory>src/main/java</directory>
141
+									<includes>
142
+										<include>yike/**/*.xml</include>
143
+									</includes>
144
+								</resource>
145
+							</resources>
146
+						</configuration>
147
+					</execution>
148
+				</executions>
149
+			</plugin>
150
+			
151
+		</plugins>
152
+	</build>
153
+	
154
+	<repositories>
155
+		<repository>
156
+			<id>maven-releases</id>
157
+			<name>maven-releases</name>
158
+			<url>http://nexus.huojutech.com/repository/maven-releases/</url>
159
+		</repository>
160
+		<repository>
161
+			<id>maven-snapshots</id>
162
+			<name>maven-snapshots</name>
163
+			<url>http://nexus.huojutech.com/repository/maven-public/</url>
164
+			<snapshots>
165
+				<enabled>true</enabled>
166
+				<updatePolicy>always</updatePolicy>
167
+				<checksumPolicy>warn</checksumPolicy>
168
+			</snapshots>
169
+		</repository>
170
+
171
+	</repositories>
172
+
173
+
174
+</project>

+ 48 - 0
src/main/java/yike/DemoApplication.java

@@ -0,0 +1,48 @@
1
+package yike;
2
+
3
+import org.mybatis.spring.annotation.MapperScan;
4
+import org.springframework.boot.SpringApplication;
5
+import org.springframework.boot.autoconfigure.SpringBootApplication;
6
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
7
+import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
8
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
9
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
10
+
11
+/**
12
+ * 基本目录结构
13
+ * SpringBootApplication启动项目,会解析base package下的所有类
14
+ * @author Administrator
15
+ *
16
+ */
17
+@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
18
+@MapperScan("yike.**.dao")
19
+public class DemoApplication extends WebMvcConfigurationSupport {
20
+	
21
+	public ThreadPoolTaskExecutor getAsyncExecutor() {
22
+		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
23
+		executor.setCorePoolSize(1);
24
+		executor.setMaxPoolSize(30);
25
+		executor.setQueueCapacity(100);
26
+		executor.setThreadNamePrefix("qiakr-task-");
27
+		executor.initialize();
28
+		return executor;
29
+	}
30
+
31
+	@Override
32
+	public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
33
+		configurer.setTaskExecutor(getAsyncExecutor());
34
+		super.configureAsyncSupport(configurer);
35
+	}
36
+	
37
+	@Override
38
+	public void addResourceHandlers(ResourceHandlerRegistry registry) {
39
+		//为swagger配置
40
+		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
41
+		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
42
+	}
43
+
44
+	public static void main(String[] args) {
45
+		SpringApplication.run(DemoApplication.class, args);
46
+	}
47
+
48
+}

+ 54 - 0
src/main/java/yike/RedisConfig.java

@@ -0,0 +1,54 @@
1
+package yike;
2
+
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
6
+import org.springframework.cache.CacheManager;
7
+import org.springframework.cache.annotation.EnableCaching;
8
+import org.springframework.context.annotation.Bean;
9
+import org.springframework.context.annotation.Configuration;
10
+import org.springframework.data.redis.cache.RedisCacheManager;
11
+import org.springframework.data.redis.connection.RedisConnectionFactory;
12
+import org.springframework.data.redis.core.RedisTemplate;
13
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
14
+import org.springframework.data.redis.serializer.StringRedisSerializer;
15
+
16
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
17
+import com.fasterxml.jackson.annotation.PropertyAccessor;
18
+import com.fasterxml.jackson.databind.ObjectMapper;
19
+
20
+@Configuration
21
+@EnableCaching
22
+public class RedisConfig {
23
+
24
+	@Bean
25
+	public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
26
+		RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
27
+		redisTemplate.setConnectionFactory(factory);
28
+		redisTemplate.afterPropertiesSet();
29
+		setSerializer(redisTemplate);
30
+		return redisTemplate;
31
+	}
32
+
33
+	@SuppressWarnings({ "rawtypes", "unchecked" })
34
+	private void setSerializer(RedisTemplate<String, String> template) {
35
+		Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
36
+		ObjectMapper om = new ObjectMapper();
37
+		om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
38
+		om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
39
+		jackson2JsonRedisSerializer.setObjectMapper(om);
40
+		template.setKeySerializer(new StringRedisSerializer());
41
+		template.setValueSerializer(jackson2JsonRedisSerializer);
42
+	}
43
+
44
+	@Bean
45
+	public CacheManager cacheManager(RedisTemplate<String, String> redisTemplate) {
46
+		RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
47
+		// 设置缓存过期时间,秒
48
+		rcm.setDefaultExpiration(60);
49
+		Map<String, Long> expires = new HashMap<>();
50
+		expires.put("account", 30L);
51
+		rcm.setExpires(expires);
52
+		return rcm;
53
+	}
54
+}

+ 40 - 0
src/main/java/yike/Swagger2Configuration.java

@@ -0,0 +1,40 @@
1
+package yike;
2
+
3
+import static springfox.documentation.builders.PathSelectors.regex;
4
+
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.context.annotation.Configuration;
7
+
8
+import com.google.common.collect.Sets;
9
+
10
+import springfox.documentation.builders.ApiInfoBuilder;
11
+import springfox.documentation.service.ApiInfo;
12
+import springfox.documentation.service.Contact;
13
+import springfox.documentation.spi.DocumentationType;
14
+import springfox.documentation.spring.web.plugins.Docket;
15
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
16
+
17
+@Configuration
18
+@EnableSwagger2
19
+public class Swagger2Configuration {
20
+	
21
+	@Bean
22
+	public Docket configSpringfoxDocketForAgent() {
23
+		return new Docket(DocumentationType.SWAGGER_2)
24
+				.groupName("代理商接口")
25
+				.protocols(Sets.newHashSet("http"))
26
+//				.enable(Constants.SWAGGER_ENABLE)
27
+				.forCodeGeneration(true).select().paths(regex("/account/.*"))
28
+				.build().apiInfo(apiInfo());
29
+	}
30
+
31
+	private ApiInfo apiInfo() {
32
+		return new ApiInfoBuilder()//
33
+				.title("洽客学院")// 标题
34
+				.description("spring boot 全集")// 描述
35
+				.termsOfServiceUrl("http://www.qiakr.com")//
36
+				.contact(new Contact("lyy", "http://www.qiakr.com", "yufeng@qiakr.com"))// 联系
37
+				.version("1.0")// 版本
38
+				.build();
39
+	}
40
+}

+ 71 - 0
src/main/java/yike/dto/AccountUpdateDTO.java

@@ -0,0 +1,71 @@
1
+package yike.dto;
2
+
3
+import io.swagger.annotations.ApiModelProperty;
4
+
5
+public class AccountUpdateDTO {
6
+	
7
+	private Long id;
8
+
9
+	@ApiModelProperty("用户名")
10
+	private String username;
11
+	
12
+	@ApiModelProperty("手机号")
13
+	private String mobile;
14
+	
15
+	@ApiModelProperty("邮箱")
16
+	private String email;
17
+	
18
+	private String inviteCode;
19
+	
20
+	private String apnsToken;
21
+
22
+	public String getUsername() {
23
+		return username;
24
+	}
25
+
26
+	public void setUsername(String username) {
27
+		this.username = username;
28
+	}
29
+
30
+	public String getMobile() {
31
+		return mobile;
32
+	}
33
+
34
+	public void setMobile(String mobile) {
35
+		this.mobile = mobile;
36
+	}
37
+
38
+	public String getEmail() {
39
+		return email;
40
+	}
41
+
42
+	public void setEmail(String email) {
43
+		this.email = email;
44
+	}
45
+
46
+	public String getInviteCode() {
47
+		return inviteCode;
48
+	}
49
+
50
+	public void setInviteCode(String inviteCode) {
51
+		this.inviteCode = inviteCode;
52
+	}
53
+
54
+	public String getApnsToken() {
55
+		return apnsToken;
56
+	}
57
+
58
+	public void setApnsToken(String apnsToken) {
59
+		this.apnsToken = apnsToken;
60
+	}
61
+
62
+	public Long getId() {
63
+		return id;
64
+	}
65
+
66
+	public void setId(Long id) {
67
+		this.id = id;
68
+	}
69
+	
70
+	
71
+}

+ 37 - 0
src/main/java/yike/dto/BaseResponseDTO.java

@@ -0,0 +1,37 @@
1
+package yike.dto;
2
+
3
+import java.util.Map;
4
+
5
+public class BaseResponseDTO {
6
+
7
+	private int status;
8
+
9
+	private String errmsg;
10
+
11
+	private Map<String, Object> result;
12
+
13
+	public int getStatus() {
14
+		return status;
15
+	}
16
+
17
+	public void setStatus(int status) {
18
+		this.status = status;
19
+	}
20
+
21
+	public String getErrmsg() {
22
+		return errmsg;
23
+	}
24
+
25
+	public void setErrmsg(String errmsg) {
26
+		this.errmsg = errmsg;
27
+	}
28
+
29
+	public Map<String, Object> getResult() {
30
+		return result;
31
+	}
32
+
33
+	public void setResult(Map<String, Object> result) {
34
+		this.result = result;
35
+	}
36
+
37
+}

+ 162 - 0
src/main/java/yike/example/AccountController.java

@@ -0,0 +1,162 @@
1
+package yike.example;
2
+
3
+import java.util.ArrayList;
4
+import java.util.HashMap;
5
+import java.util.Map;
6
+import java.util.concurrent.Callable;
7
+
8
+import javax.annotation.Resource;
9
+
10
+import org.springframework.web.bind.annotation.RequestMapping;
11
+import org.springframework.web.bind.annotation.RequestMethod;
12
+import org.springframework.web.bind.annotation.RequestParam;
13
+import org.springframework.web.bind.annotation.RestController;
14
+
15
+import io.swagger.annotations.Api;
16
+import io.swagger.annotations.ApiOperation;
17
+import io.swagger.annotations.ApiParam;
18
+import yike.dto.AccountUpdateDTO;
19
+import yike.dto.BaseResponseDTO;
20
+import yike.example.mq.AccountCreateListener;
21
+import yike.example.mq.AccountUpdateListener;
22
+import yike.example.obj.Account;
23
+import yike.example.service.AccountService;
24
+
25
+@Api(description="账户管理")
26
+@RestController
27
+public class AccountController {
28
+
29
+	@Resource
30
+	private AccountService accountService;
31
+	
32
+	@Resource
33
+	private AccountCreateListener accountCreateListener;
34
+	
35
+	@Resource
36
+	private AccountUpdateListener accountUpdateListener;
37
+	
38
+	@ApiOperation(value = "查找", notes = "根据用户ID查找用户", response=Account.class)
39
+	@RequestMapping(value="/account/account.json", method=RequestMethod.GET)
40
+	public Object account(@ApiParam(value="用户id") @RequestParam Long id) {
41
+		BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
42
+		baseResponseDTO.setStatus(0);
43
+		Map<String, Object> result = new HashMap<>();
44
+		result.put("account", accountService.getById(id));
45
+		baseResponseDTO.setResult(result);
46
+		return baseResponseDTO;
47
+	}
48
+	
49
+	@RequestMapping(value="/account/accounts.json", method=RequestMethod.GET)
50
+	public Object accounts(String ids) {
51
+		BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
52
+		baseResponseDTO.setStatus(0);
53
+		
54
+//		List<Long> idList = StringUtil.split2LongList(ids);
55
+//		List<List<Long>> pages = Lists.partition(idList, 1);
56
+//		//Java8语法
57
+//		List<CompletableFuture<Account>> futures = 
58
+//				pages.stream().map(page -> page.get(0))
59
+//							  .map(id -> CompletableFuture.supplyAsync(() -> {
60
+//				return accountService.getById(id);
61
+//			})).collect(Collectors.toList());
62
+//		CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
63
+		
64
+//		List<Account> accounts = futures.stream().map(future -> future.join()).collect(Collectors.toList());
65
+		
66
+		Map<String, Object> result = new HashMap<>();
67
+		result.put("accounts", new ArrayList<>());
68
+		
69
+		baseResponseDTO.setResult(result);
70
+		return baseResponseDTO;
71
+	}
72
+	
73
+	@RequestMapping(value="/account/asyncAccount", method=RequestMethod.GET)
74
+	public Callable<BaseResponseDTO> asyncAccount(Long id) {
75
+		Callable<BaseResponseDTO> asyncTask = new Callable<BaseResponseDTO>() {
76
+
77
+			@Override
78
+			public BaseResponseDTO call() throws Exception {
79
+				BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
80
+				baseResponseDTO.setStatus(0);
81
+				Map<String, Object> result = new HashMap<>();
82
+				result.put("account", accountService.getById(id));
83
+				
84
+				Thread.sleep(1000);
85
+				
86
+				baseResponseDTO.setResult(result);
87
+				return baseResponseDTO;
88
+			}
89
+		};
90
+
91
+		return asyncTask;
92
+	}
93
+	
94
+	@RequestMapping(value="/account/asyncAccountException", method=RequestMethod.GET)
95
+	public Callable<BaseResponseDTO> asyncAccountException(Long id) {
96
+		Callable<BaseResponseDTO> asyncTask = new Callable<BaseResponseDTO>() {
97
+
98
+			@Override
99
+			public BaseResponseDTO call() throws Exception {
100
+				BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
101
+				baseResponseDTO.setStatus(0);
102
+				Map<String, Object> result = new HashMap<>();
103
+				result.put("account", accountService.getById(id));
104
+				int x= 1/0;
105
+				baseResponseDTO.setResult(result);
106
+				return baseResponseDTO;
107
+			}
108
+		};
109
+
110
+		return asyncTask;
111
+	}
112
+	
113
+	@ApiOperation(value = "创建")
114
+	@RequestMapping(value="/account/account.json", method=RequestMethod.POST)
115
+	public Object addAccount(@ApiParam(value="用户Name") @RequestParam String accountName) {
116
+		BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
117
+		baseResponseDTO.setStatus(0);
118
+		
119
+		accountCreateListener.send(accountName);
120
+		return baseResponseDTO;
121
+	}
122
+	
123
+	@ApiOperation(value = "创建2")
124
+	@RequestMapping(value="/account/account2.json", method=RequestMethod.POST)
125
+	public Object addAccount2(@ApiParam(value="用户Name") @RequestParam String accountName,
126
+			@ApiParam(value="用户id") @RequestParam Long accountId) {
127
+		BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
128
+		baseResponseDTO.setStatus(0);
129
+		
130
+		accountCreateListener.send(accountId, accountName);
131
+		return baseResponseDTO;
132
+	}
133
+	
134
+	@ApiOperation(value = "更新")
135
+	@RequestMapping(value="/account/account.json", method=RequestMethod.PUT)
136
+	public Object updateAccount(@ApiParam(value="用户Name") @RequestParam String accountName,
137
+			@ApiParam(value="用户id") @RequestParam Long accountId) {
138
+		BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
139
+		baseResponseDTO.setStatus(0);
140
+		
141
+		accountUpdateListener.send(accountId, accountName);
142
+		return baseResponseDTO;
143
+	}
144
+	
145
+	@ApiOperation(value = "更新2")
146
+	@RequestMapping(value="/account/account2.json", method=RequestMethod.PUT)
147
+	public Object updateAccount2(AccountUpdateDTO accountDTO) {
148
+		BaseResponseDTO baseResponseDTO = new BaseResponseDTO();
149
+		baseResponseDTO.setStatus(0);
150
+		
151
+		Account account = new Account();
152
+		account.setApnsToken(accountDTO.getApnsToken());
153
+		account.setEmail(accountDTO.getEmail());
154
+		account.setInviteCode(accountDTO.getInviteCode());
155
+		account.setMobile(accountDTO.getMobile());
156
+		account.setUsername(accountDTO.getUsername());
157
+		account.setId(accountDTO.getId());
158
+		accountService.updateAccountInfo(account);
159
+		
160
+		return baseResponseDTO;
161
+	}
162
+}

+ 22 - 0
src/main/java/yike/example/BaseErrorController.java

@@ -0,0 +1,22 @@
1
+package yike.example;
2
+
3
+import javax.servlet.http.HttpServletRequest;
4
+
5
+import org.slf4j.Logger;
6
+import org.slf4j.LoggerFactory;
7
+import org.springframework.web.bind.annotation.ControllerAdvice;
8
+import org.springframework.web.bind.annotation.ExceptionHandler;
9
+import org.springframework.web.bind.annotation.ResponseBody;
10
+
11
+@ControllerAdvice
12
+public class BaseErrorController {
13
+	
14
+	private static Logger logger = LoggerFactory.getLogger(BaseErrorController.class);
15
+
16
+	@ExceptionHandler(value = Exception.class)
17
+	@ResponseBody
18
+	public String defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
19
+		logger.error(e.getMessage(), e);
20
+		return "error happens";
21
+	}
22
+}

+ 20 - 0
src/main/java/yike/example/SampleController.java

@@ -0,0 +1,20 @@
1
+package yike.example;
2
+
3
+import org.springframework.web.bind.annotation.RequestMapping;
4
+import org.springframework.web.bind.annotation.RestController;
5
+
6
+@RestController
7
+public class SampleController {
8
+
9
+	@RequestMapping("/helloworld")
10
+	String home() {
11
+		return "Hello World!";
12
+	}
13
+	
14
+	@RequestMapping("/exception")
15
+	String exception() {
16
+		int x= 1/0;
17
+		return "Hello World!";
18
+	}
19
+
20
+}

+ 10 - 0
src/main/java/yike/example/dao/AccountDao.java

@@ -0,0 +1,10 @@
1
+package yike.example.dao;
2
+
3
+import yike.example.obj.Account;
4
+
5
+public interface AccountDao {
6
+
7
+	Account selectByPrimaryKey(Long id);
8
+	
9
+	void updateAccountInfo(Account account);
10
+}

+ 27 - 0
src/main/java/yike/example/dao/AccountDao.xml

@@ -0,0 +1,27 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="yike.example.dao.AccountDao">
4
+    <resultMap id="BaseResultMap" type="yike.example.obj.Account">
5
+        <id column="id" jdbcType="BIGINT" property="id"/>
6
+    </resultMap>
7
+    
8
+    <select id="selectByPrimaryKey" parameterType="java.lang.Long"
9
+            resultMap="BaseResultMap">
10
+        select *
11
+        from account
12
+        where id = #{id,jdbcType=BIGINT}
13
+    </select>
14
+    
15
+    <update id="updateAccountInfo" parameterType="yike.example.obj.Account">
16
+		UPDATE account 
17
+		SET
18
+			username= #{username},
19
+			mobile = #{mobile},
20
+			email = #{email},
21
+			invite_code = #{inviteCode},
22
+			apns_token = #{apnsToken}
23
+		WHERE
24
+			id = #{id}
25
+	</update>
26
+
27
+</mapper>

+ 46 - 0
src/main/java/yike/example/mq/AccountCreateListener.java

@@ -0,0 +1,46 @@
1
+package yike.example.mq;
2
+
3
+import org.springframework.amqp.core.AmqpTemplate;
4
+import org.springframework.amqp.rabbit.annotation.Exchange;
5
+import org.springframework.amqp.rabbit.annotation.Queue;
6
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
7
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.stereotype.Component;
10
+
11
+import com.alibaba.fastjson.JSONObject;
12
+
13
+
14
+@Component
15
+public class AccountCreateListener extends BaseListener{
16
+
17
+	@Autowired
18
+	private AmqpTemplate amqpTemplate;
19
+	
20
+	private final String routingKey = "account.create";
21
+	
22
+	private final String exchange = "account";
23
+	
24
+	private final String queueName = routingKey + QUEUE_NAME;
25
+
26
+	public void send(String msg) {
27
+		this.amqpTemplate.convertAndSend(exchange, routingKey, super.addExchangeAndRoutingKey(msg, exchange, routingKey));
28
+	}
29
+	
30
+	public void send(Long id, String name) {
31
+		JSONObject jsonObject = new JSONObject();
32
+		jsonObject.put("id", id);
33
+		jsonObject.put("name", name);
34
+		this.amqpTemplate.convertAndSend(exchange, routingKey, super.addExchangeAndRoutingKey(jsonObject, exchange, routingKey));
35
+	}
36
+
37
+//	@RabbitListener(bindings = @QueueBinding(
38
+//			value = @Queue(value = queueName, durable = "true"), 
39
+//			exchange = @Exchange(value = exchange, ignoreDeclarationExceptions = "true"), 
40
+//			key = routingKey ))
41
+	public void receiveQueue(String text) {
42
+		System.out.println("接受到:" + text);
43
+		JSONObject jsonObject = JSONObject.parseObject(text);
44
+		jsonObject.clear();
45
+	}
46
+}

+ 46 - 0
src/main/java/yike/example/mq/AccountUpdateListener.java

@@ -0,0 +1,46 @@
1
+package yike.example.mq;
2
+
3
+import org.springframework.amqp.core.AmqpTemplate;
4
+import org.springframework.amqp.rabbit.annotation.Exchange;
5
+import org.springframework.amqp.rabbit.annotation.Queue;
6
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
7
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.stereotype.Component;
10
+
11
+import com.alibaba.fastjson.JSONObject;
12
+
13
+
14
+@Component
15
+public class AccountUpdateListener extends BaseListener{
16
+
17
+	@Autowired
18
+	private AmqpTemplate amqpTemplate;
19
+	
20
+	private final String routingKey = "account.update";
21
+	
22
+	private final String exchange = "account";
23
+	
24
+	private final String queueName = routingKey + QUEUE_NAME;
25
+
26
+	public void send(String msg) {
27
+		this.amqpTemplate.convertAndSend(exchange, routingKey, super.addExchangeAndRoutingKey(msg, exchange, routingKey));
28
+	}
29
+	
30
+	public void send(Long id, String name) {
31
+		JSONObject jsonObject = new JSONObject();
32
+		jsonObject.put("id", id);
33
+		jsonObject.put("name", name);
34
+		this.amqpTemplate.convertAndSend(exchange, routingKey, super.addExchangeAndRoutingKey(jsonObject, exchange, routingKey));
35
+	}
36
+
37
+//	@RabbitListener(bindings = @QueueBinding(
38
+//			value = @Queue(value = queueName, durable = "true"), 
39
+//			exchange = @Exchange(value = exchange, ignoreDeclarationExceptions = "true"), 
40
+//			key = routingKey ))
41
+	public void receiveQueue(String text) {
42
+		System.out.println("接受到:" + text);
43
+		JSONObject jsonObject = JSONObject.parseObject(text);
44
+		jsonObject.clear();
45
+	}
46
+}

+ 17 - 0
src/main/java/yike/example/mq/BaseListener.java

@@ -0,0 +1,17 @@
1
+package yike.example.mq;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+
5
+public class BaseListener {
6
+	
7
+	protected final String QUEUE_NAME = ".QUEUE";
8
+
9
+	protected String addExchangeAndRoutingKey(Object content, String exchange, String routingKey) {
10
+		JSONObject jsonObject = new JSONObject();
11
+		jsonObject.put("routingKey", routingKey);
12
+		jsonObject.put("content", content);
13
+		jsonObject.put("exchange", exchange);
14
+		return jsonObject.toJSONString();
15
+	}
16
+	
17
+}

+ 113 - 0
src/main/java/yike/example/obj/Account.java

@@ -0,0 +1,113 @@
1
+package yike.example.obj;
2
+
3
+import java.io.Serializable;
4
+import java.util.Date;
5
+
6
+import io.swagger.annotations.ApiModelProperty;
7
+
8
+/**
9
+ * 账号
10
+ * 
11
+ * @author kevin
12
+ *
13
+ */
14
+public class Account implements Serializable{
15
+
16
+	/**
17
+	 * 
18
+	 */
19
+	private static final long serialVersionUID = 5164200417829209017L;
20
+	private Long id;
21
+	
22
+	@ApiModelProperty("用户名")
23
+	private String username;
24
+	private String password;
25
+	private String mobile;
26
+	private String email;
27
+	private String inviteCode;
28
+	private String weixinOpenId;
29
+	private String apnsToken;
30
+	private Date gmtCreate;
31
+	private Date gmtUpdate;
32
+
33
+	public Long getId() {
34
+		return id;
35
+	}
36
+
37
+	public void setId(Long id) {
38
+		this.id = id;
39
+	}
40
+
41
+	public String getUsername() {
42
+		return username;
43
+	}
44
+
45
+	public void setUsername(String username) {
46
+		this.username = username;
47
+	}
48
+
49
+	public String getPassword() {
50
+		return password;
51
+	}
52
+
53
+	public void setPassword(String password) {
54
+		this.password = password;
55
+	}
56
+
57
+	public String getMobile() {
58
+		return mobile;
59
+	}
60
+
61
+	public void setMobile(String mobile) {
62
+		this.mobile = mobile;
63
+	}
64
+
65
+	public String getEmail() {
66
+		return email;
67
+	}
68
+
69
+	public void setEmail(String email) {
70
+		this.email = email;
71
+	}
72
+
73
+	public String getInviteCode() {
74
+		return inviteCode;
75
+	}
76
+
77
+	public void setInviteCode(String inviteCode) {
78
+		this.inviteCode = inviteCode;
79
+	}
80
+
81
+	public String getWeixinOpenId() {
82
+		return weixinOpenId;
83
+	}
84
+
85
+	public void setWeixinOpenId(String weixinOpenId) {
86
+		this.weixinOpenId = weixinOpenId;
87
+	}
88
+
89
+	public Date getGmtCreate() {
90
+		return gmtCreate;
91
+	}
92
+
93
+	public void setGmtCreate(Date gmtCreate) {
94
+		this.gmtCreate = gmtCreate;
95
+	}
96
+
97
+	public Date getGmtUpdate() {
98
+		return gmtUpdate;
99
+	}
100
+
101
+	public void setGmtUpdate(Date gmtUpdate) {
102
+		this.gmtUpdate = gmtUpdate;
103
+	}
104
+
105
+	public String getApnsToken() {
106
+		return apnsToken;
107
+	}
108
+
109
+	public void setApnsToken(String apnsToken) {
110
+		this.apnsToken = apnsToken;
111
+	}
112
+
113
+}

+ 26 - 0
src/main/java/yike/example/service/AccountService.java

@@ -0,0 +1,26 @@
1
+package yike.example.service;
2
+
3
+import javax.annotation.Resource;
4
+
5
+import org.springframework.cache.annotation.Cacheable;
6
+import org.springframework.stereotype.Service;
7
+
8
+import yike.example.dao.AccountDao;
9
+import yike.example.obj.Account;
10
+
11
+@Service
12
+public class AccountService {
13
+
14
+	@Resource
15
+	private AccountDao accountDao;
16
+	
17
+	@Cacheable(value="account", key="'aco_' + #id", condition = "#id != null")
18
+	public Account getById(Long id) {
19
+		return accountDao.selectByPrimaryKey(id);
20
+	}
21
+	
22
+	public void updateAccountInfo(Account account) {
23
+		//
24
+		accountDao.updateAccountInfo(account);
25
+	}
26
+}

+ 36 - 0
src/main/resources/application-dev.properties

@@ -0,0 +1,36 @@
1
+
2
+spring.datasource.name= test
3
+spring.datasource.url= jdbc:mysql://10.4.30.207:3306/xmall
4
+spring.datasource.username= root
5
+spring.datasource.password= yiguokeji01db
6
+# 使用druid数据源
7
+spring.datasource.type= com.alibaba.druid.pool.DruidDataSource
8
+spring.datasource.driver-class-name= com.mysql.jdbc.Driver
9
+spring.datasource.filters= stat
10
+spring.datasource.maxActive= 200
11
+spring.datasource.initialSize= 1
12
+spring.datasource.maxWait= 60000
13
+spring.datasource.minIdle= 1
14
+spring.datasource.timeBetweenEvictionRunsMillis= 60000
15
+spring.datasource.minEvictableIdleTimeMillis= 300000
16
+spring.datasource.validationQuery= select 'x'
17
+spring.datasource.testWhileIdle= true
18
+spring.datasource.testOnBorrow= false
19
+spring.datasource.testOnReturn= false
20
+spring.datasource.poolPreparedStatements= true
21
+spring.datasource.maxOpenPreparedStatements= 20
22
+spring.redis.host= 10.4.30.207
23
+spring.redis.port= 6379
24
+spring.rabbitmq.host= 10.4.30.207
25
+spring.rabbitmq.port= 5672
26
+spring.rabbitmq.username= guest
27
+spring.rabbitmq.password= guest
28
+#mybatis
29
+mybatis.mapper-locations= classpath:yike.**.dao
30
+mybatis.type-aliases-package= yike.example.obj
31
+  
32
+server.port= 8093
33
+
34
+#log
35
+logging.config=classpath:logback.xml
36
+logging.path=/data/spring_logs

+ 36 - 0
src/main/resources/application-loc.properties

@@ -0,0 +1,36 @@
1
+
2
+spring.datasource.name= test
3
+spring.datasource.url= jdbc:mysql://127.0.0.1:3306/test
4
+spring.datasource.username= root
5
+spring.datasource.password= 123456
6
+# 使用druid数据源
7
+spring.datasource.type= com.alibaba.druid.pool.DruidDataSource
8
+spring.datasource.driver-class-name= com.mysql.jdbc.Driver
9
+spring.datasource.filters= stat
10
+spring.datasource.maxActive= 200
11
+spring.datasource.initialSize= 1
12
+spring.datasource.maxWait= 60000
13
+spring.datasource.minIdle= 1
14
+spring.datasource.timeBetweenEvictionRunsMillis= 60000
15
+spring.datasource.minEvictableIdleTimeMillis= 300000
16
+spring.datasource.validationQuery= select 'x'
17
+spring.datasource.testWhileIdle= true
18
+spring.datasource.testOnBorrow= false
19
+spring.datasource.testOnReturn= false
20
+spring.datasource.poolPreparedStatements= true
21
+spring.datasource.maxOpenPreparedStatements= 20
22
+spring.redis.host= 127.0.0.1
23
+spring.redis.port= 6379
24
+#spring.rabbitmq.host= localhost
25
+#spring.rabbitmq.port= 5672
26
+#spring.rabbitmq.username= guest
27
+#spring.rabbitmq.password= guest
28
+#mybatis
29
+mybatis.mapper-locations= classpath:yike.**.dao
30
+mybatis.type-aliases-package= yike.example.obj
31
+  
32
+server.port= 8080
33
+
34
+#log
35
+logging.config=classpath:logback.xml
36
+logging.path=/data/spring_logs

+ 55 - 0
src/main/resources/logback.xml

@@ -0,0 +1,55 @@
1
+<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
2
+<configuration scan="true" scanPeriod="10 seconds">
3
+    <include resource="org/springframework/boot/logging/logback/base.xml" />
4
+
5
+    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
6
+        <File>${LOG_PATH}/info.log</File>
7
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
8
+            <fileNamePattern>${LOG_PATH}/info-%d{yyyyMMdd}.log.%i</fileNamePattern>
9
+            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
10
+                <maxFileSize>500MB</maxFileSize>
11
+            </timeBasedFileNamingAndTriggeringPolicy>
12
+            <maxHistory>2</maxHistory>
13
+        </rollingPolicy>
14
+        <layout class="ch.qos.logback.classic.PatternLayout">
15
+            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
16
+            </Pattern>
17
+        </layout>
18
+    </appender>
19
+
20
+    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
21
+        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
22
+            <level>ERROR</level>
23
+        </filter>
24
+        <File>${LOG_PATH}/error.log</File>
25
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
26
+            <fileNamePattern>${LOG_PATH}/error-%d{yyyyMMdd}.log.%i
27
+            </fileNamePattern>
28
+            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
29
+                <maxFileSize>500MB</maxFileSize>
30
+            </timeBasedFileNamingAndTriggeringPolicy>
31
+            <maxHistory>2</maxHistory>
32
+        </rollingPolicy>
33
+        <layout class="ch.qos.logback.classic.PatternLayout">
34
+            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
35
+
36
+            </Pattern>
37
+        </layout>
38
+    </appender>
39
+    
40
+<!--     <logger name="org.springframework.web" level="DEBUG" /> -->
41
+    <!-- hibernate日志输入 -->
42
+    <!-- <logger name="org.hibernate.type.descriptor.sql.BasicBinder"
43
+        level="TRACE" />
44
+    <logger name="org.hibernate.type.descriptor.sql.BasicExtractor"
45
+        level="TRACE" />
46
+    <logger name="org.hibernate.SQL" level="INFO" />
47
+    <logger name="org.hibernate.engine.QueryParameters" level="INFO" />
48
+    <logger name="org.hibernate.engine.query.HQLQueryPlan" level="INFO" /> -->
49
+
50
+    <root level="INFO">
51
+        <appender-ref ref="INFO_FILE" />
52
+        <appender-ref ref="ERROR_FILE" />
53
+    </root>
54
+    
55
+</configuration>

+ 16 - 0
src/test/java/yike/example/demo/DemoApplicationTests.java

@@ -0,0 +1,16 @@
1
+package yike.example.demo;
2
+
3
+import org.junit.Test;
4
+import org.junit.runner.RunWith;
5
+import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.junit4.SpringRunner;
7
+
8
+@RunWith(SpringRunner.class)
9
+@SpringBootTest
10
+public class DemoApplicationTests {
11
+
12
+	@Test
13
+	public void contextLoads() {
14
+	}
15
+
16
+}