├── README.md
├── spring-aop
├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── uiDesigner.xml
├── Spring.iml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── aop
│ │ │ ├── Louzai.java
│ │ │ └── LouzaiAspect.java
│ └── resources
│ │ └── applicationContext.xml
│ └── test
│ └── java
│ └── MyTest.java
├── spring-cycle-depend
├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── uiDesigner.xml
├── Spring.iml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── demo
│ │ │ ├── Louzai1.java
│ │ │ └── Louzai2.java
│ └── resources
│ │ └── applicationContext.xml
│ └── test
│ └── java
│ └── MyTest.java
├── spring-life-cycle
├── .idea
│ ├── .gitignore
│ ├── compiler.xml
│ ├── encodings.xml
│ ├── inspectionProfiles
│ │ └── Project_Default.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ └── uiDesigner.xml
├── Spring.iml
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── demo
│ │ │ ├── LouzaiBean.java
│ │ │ └── MyBeanPostProcessor.java
│ └── resources
│ │ └── applicationContext.xml
│ └── test
│ └── java
│ └── MyTest.java
└── spring-transaction
├── .idea
├── .gitignore
├── compiler.xml
├── encodings.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── jarRepositories.xml
├── misc.xml
└── uiDesigner.xml
├── Spring-事务.iml
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── mybatis
│ │ ├── config
│ │ └── datasources
│ │ │ └── mybatis-config.xml
│ │ ├── controller
│ │ └── Louzai.java
│ │ ├── dao
│ │ └── UserDao.java
│ │ ├── entity
│ │ └── MyUser.java
│ │ ├── mapper
│ │ └── UserMapper.xml
│ │ └── test
│ │ └── SpringMyBatisTest.java
└── resources
│ ├── applicationContext.xml
│ └── jdbc.properties
└── test
└── java
└── MyTest.java
/README.md:
--------------------------------------------------------------------------------
1 | > 各种 Demo,包括 Spring 源码、中间件使用姿势、日常的小示例等,主要是方便楼仔的读者使用。
2 |
3 | ## 1. Spring 源码系列
4 | - spring-cycle-depend:Spring 循环依赖
5 | - spring-life-cycle:Spring 生命周期
6 | - spring-aop:Spring AOP
7 | - spring-transaction:Spring 事务
8 |
--------------------------------------------------------------------------------
/spring-aop/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/spring-aop/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-aop/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/spring-aop/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
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 |
--------------------------------------------------------------------------------
/spring-aop/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-aop/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-aop/.idea/uiDesigner.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 | -
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 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/spring-aop/Spring.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/spring-aop/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | java-study2
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | UTF-8
14 | 1.8
15 | 1.8
16 |
17 | 5.2.15.RELEASE
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | org.springframework
27 | spring-core
28 |
29 | ${spring.version}
30 |
31 |
32 | org.springframework
33 | spring-beans
34 | ${spring.version}
35 |
36 |
37 | org.springframework
38 | spring-context
39 | ${spring.version}
40 |
41 |
42 |
43 |
44 | org.springframework
45 | spring-jdbc
46 | ${spring.version}
47 |
48 |
49 | org.springframework
50 | spring-tx
51 | ${spring.version}
52 |
53 |
54 |
55 | org.springframework
56 | spring-web
57 | ${spring.version}
58 |
59 |
60 | org.springframework
61 | spring-webmvc
62 | ${spring.version}
63 |
64 |
65 |
66 | org.springframework
67 | spring-test
68 | ${spring.version}
69 |
70 |
71 |
72 |
73 |
74 | org.mybatis
75 | mybatis
76 | 3.4.6
77 |
78 |
79 | org.mybatis
80 | mybatis-spring
81 | 2.0.0
82 |
83 |
84 | mysql
85 | mysql-connector-java
86 | 6.0.6
87 |
88 |
89 | org.mybatis.spring.boot
90 | mybatis-spring-boot-starter
91 | 2.1.0
92 |
93 |
94 |
95 | junit
96 | junit
97 | 4.11
98 | test
99 |
100 |
101 |
102 | log4j
103 | log4j
104 | 1.2.17
105 |
106 |
107 |
108 |
109 | org.projectlombok
110 | lombok
111 | 1.16.10
112 |
113 |
114 |
115 | com.google.guava
116 | guava
117 | 30.0-jre
118 |
119 |
120 |
121 |
122 | org.aspectj
123 | aspectjweaver
124 | 1.9.4
125 |
126 |
127 |
128 | com.rabbitmq
129 | amqp-client
130 | 5.5.1
131 |
132 |
133 |
134 | org.mapstruct
135 |
136 | mapstruct-jdk8
137 | 1.2.0.Final
138 |
139 |
140 | org.mapstruct
141 | mapstruct-processor
142 | 1.2.0.Final
143 |
144 |
145 |
146 | org.dspace.xmlui.concurrent
147 | concurrent
148 | 1.3.4
149 |
150 |
151 |
152 |
153 | org.apache.commons
154 | commons-lang3
155 | 3.10
156 |
157 |
158 | org.apache.commons
159 | commons-pool2
160 | 2.6.1
161 |
162 |
163 | org.apache.commons
164 | commons-collections4
165 | 4.4
166 |
167 |
168 | commons-collections
169 | commons-collections
170 | 3.2.2
171 |
172 |
173 | org.apache.commons
174 | commons-jexl3
175 | 3.2.1
176 |
177 |
178 | junit
179 | junit
180 | 4.11
181 | compile
182 |
183 |
184 |
185 |
186 |
187 | demo5
188 |
189 |
190 |
191 | org.apache.maven.plugins
192 | maven-war-plugin
193 | 2.2
194 |
195 | WebContent\WEB-INF\web.xml
196 |
197 |
198 |
199 |
200 | org.apache.maven.plugins
201 | maven-source-plugin
202 | 3.0.1
203 |
204 |
205 | attach-sources
206 | package
207 |
208 | jar-no-fork
209 |
210 |
211 |
212 |
213 |
214 | org.apache.maven.plugins
215 | maven-surefire-plugin
216 |
217 |
218 | true
219 |
220 |
221 |
222 |
223 |
224 |
225 | org.apache.maven.plugins
226 | maven-compiler-plugin
227 |
228 | 8
229 | 8
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | src/main/java
239 |
240 | **/*.properties
241 | **/*.xml
242 |
243 | false
244 |
245 |
246 | src/main/resources
247 |
248 | **/*.*
249 |
250 | false
251 |
252 |
253 |
254 |
255 |
256 |
--------------------------------------------------------------------------------
/spring-aop/src/main/java/com/aop/Louzai.java:
--------------------------------------------------------------------------------
1 | package com.aop;
2 |
3 | import lombok.Data;
4 | import org.springframework.stereotype.Service;
5 |
6 | @Data
7 | @Service
8 | public class Louzai {
9 |
10 | public void everyDay() {
11 | System.out.println("睡觉");
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/spring-aop/src/main/java/com/aop/LouzaiAspect.java:
--------------------------------------------------------------------------------
1 | package com.aop;
2 |
3 | import org.aspectj.lang.annotation.AfterReturning;
4 | import org.aspectj.lang.annotation.Aspect;
5 | import org.aspectj.lang.annotation.Before;
6 | import org.aspectj.lang.annotation.Pointcut;
7 | import org.springframework.stereotype.Component;
8 |
9 | @Aspect
10 | @Component
11 | public class LouzaiAspect {
12 |
13 | @Pointcut("execution(* Louzai.everyDay())")
14 | private void myPointCut() {
15 | }
16 |
17 | // 前置通知
18 | @Before("myPointCut()")
19 | public void myBefore() {
20 | System.out.println("吃饭");
21 | }
22 |
23 | // 后置通知
24 | @AfterReturning(value = "myPointCut()")
25 | public void myAfterReturning() {
26 | System.out.println("打豆豆。。。");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-aop/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/spring-aop/src/test/java/MyTest.java:
--------------------------------------------------------------------------------
1 |
2 | import com.aop.Louzai;
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | public class MyTest {
7 | public static void main(String[] args) throws Exception {
8 | ApplicationContext context =new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
9 | Louzai louzai = (Louzai) context.getBean("louzai");
10 | louzai.everyDay();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-cycle-depend/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/spring-cycle-depend/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-cycle-depend/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/spring-cycle-depend/.idea/inspectionProfiles/Project_Default.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 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/spring-cycle-depend/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-cycle-depend/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-cycle-depend/.idea/uiDesigner.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 | -
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 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/spring-cycle-depend/Spring.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/spring-cycle-depend/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | java-study2
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | UTF-8
14 | 1.8
15 | 1.8
16 |
17 | 5.2.15.RELEASE
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | org.springframework
27 | spring-core
28 |
29 | ${spring.version}
30 |
31 |
32 | org.springframework
33 | spring-beans
34 | ${spring.version}
35 |
36 |
37 | org.springframework
38 | spring-context
39 | ${spring.version}
40 |
41 |
42 |
43 |
44 | org.springframework
45 | spring-jdbc
46 | ${spring.version}
47 |
48 |
49 | org.springframework
50 | spring-tx
51 | ${spring.version}
52 |
53 |
54 |
55 | org.springframework
56 | spring-web
57 | ${spring.version}
58 |
59 |
60 | org.springframework
61 | spring-webmvc
62 | ${spring.version}
63 |
64 |
65 |
66 | org.springframework
67 | spring-test
68 | ${spring.version}
69 |
70 |
71 |
72 |
73 |
74 | org.mybatis
75 | mybatis
76 | 3.4.6
77 |
78 |
79 | org.mybatis
80 | mybatis-spring
81 | 2.0.0
82 |
83 |
84 | mysql
85 | mysql-connector-java
86 | 6.0.6
87 |
88 |
89 | org.mybatis.spring.boot
90 | mybatis-spring-boot-starter
91 | 2.1.0
92 |
93 |
94 |
95 | junit
96 | junit
97 | 4.11
98 | test
99 |
100 |
101 |
102 | log4j
103 | log4j
104 | 1.2.17
105 |
106 |
107 |
108 |
109 | org.projectlombok
110 | lombok
111 | 1.16.10
112 |
113 |
114 |
115 | com.google.guava
116 | guava
117 | 30.0-jre
118 |
119 |
120 |
121 |
122 | org.aspectj
123 | aspectjweaver
124 | 1.9.4
125 |
126 |
127 |
128 | com.rabbitmq
129 | amqp-client
130 | 5.5.1
131 |
132 |
133 |
134 | org.mapstruct
135 |
136 | mapstruct-jdk8
137 | 1.2.0.Final
138 |
139 |
140 | org.mapstruct
141 | mapstruct-processor
142 | 1.2.0.Final
143 |
144 |
145 |
146 | org.dspace.xmlui.concurrent
147 | concurrent
148 | 1.3.4
149 |
150 |
151 |
152 |
153 | org.apache.commons
154 | commons-lang3
155 | 3.10
156 |
157 |
158 | org.apache.commons
159 | commons-pool2
160 | 2.6.1
161 |
162 |
163 | org.apache.commons
164 | commons-collections4
165 | 4.4
166 |
167 |
168 | commons-collections
169 | commons-collections
170 | 3.2.2
171 |
172 |
173 | org.apache.commons
174 | commons-jexl3
175 | 3.2.1
176 |
177 |
178 | junit
179 | junit
180 | 4.11
181 | compile
182 |
183 |
184 |
185 |
186 |
187 | demo5
188 |
189 |
190 |
191 | org.apache.maven.plugins
192 | maven-war-plugin
193 | 2.2
194 |
195 | WebContent\WEB-INF\web.xml
196 |
197 |
198 |
199 |
200 | org.apache.maven.plugins
201 | maven-source-plugin
202 | 3.0.1
203 |
204 |
205 | attach-sources
206 | package
207 |
208 | jar-no-fork
209 |
210 |
211 |
212 |
213 |
214 | org.apache.maven.plugins
215 | maven-surefire-plugin
216 |
217 |
218 | true
219 |
220 |
221 |
222 |
223 |
224 |
225 | org.apache.maven.plugins
226 | maven-compiler-plugin
227 |
228 | 8
229 | 8
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | src/main/java
239 |
240 | **/*.properties
241 | **/*.xml
242 |
243 | false
244 |
245 |
246 | src/main/resources
247 |
248 | **/*.*
249 |
250 | false
251 |
252 |
253 |
254 |
255 |
256 |
--------------------------------------------------------------------------------
/spring-cycle-depend/src/main/java/com/demo/Louzai1.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Service;
5 |
6 | @Service
7 | public class Louzai1 {
8 |
9 | @Autowired
10 | private Louzai2 louzai2;
11 |
12 | public void test1() {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/spring-cycle-depend/src/main/java/com/demo/Louzai2.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Service;
5 |
6 | @Service
7 | public class Louzai2 {
8 | @Autowired
9 | private Louzai1 louzai1;
10 |
11 | public void test2() {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-cycle-depend/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/spring-cycle-depend/src/test/java/MyTest.java:
--------------------------------------------------------------------------------
1 |
2 | import com.demo.Louzai1;
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | public class MyTest {
7 | public static void main(String[] args) throws Exception {
8 | ApplicationContext context =new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
9 | ((ClassPathXmlApplicationContext) context).destroy();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/spring-life-cycle/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/spring-life-cycle/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-life-cycle/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/spring-life-cycle/.idea/inspectionProfiles/Project_Default.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 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/spring-life-cycle/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-life-cycle/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-life-cycle/.idea/uiDesigner.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 | -
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 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/spring-life-cycle/Spring.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/spring-life-cycle/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | java-study2
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | UTF-8
14 | 1.8
15 | 1.8
16 |
17 | 5.2.15.RELEASE
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | org.springframework
27 | spring-core
28 |
29 | ${spring.version}
30 |
31 |
32 | org.springframework
33 | spring-beans
34 | ${spring.version}
35 |
36 |
37 | org.springframework
38 | spring-context
39 | ${spring.version}
40 |
41 |
42 |
43 |
44 | org.springframework
45 | spring-jdbc
46 | ${spring.version}
47 |
48 |
49 | org.springframework
50 | spring-tx
51 | ${spring.version}
52 |
53 |
54 |
55 | org.springframework
56 | spring-web
57 | ${spring.version}
58 |
59 |
60 | org.springframework
61 | spring-webmvc
62 | ${spring.version}
63 |
64 |
65 |
66 | org.springframework
67 | spring-test
68 | ${spring.version}
69 |
70 |
71 |
72 |
73 |
74 | org.mybatis
75 | mybatis
76 | 3.4.6
77 |
78 |
79 | org.mybatis
80 | mybatis-spring
81 | 2.0.0
82 |
83 |
84 | mysql
85 | mysql-connector-java
86 | 6.0.6
87 |
88 |
89 | org.mybatis.spring.boot
90 | mybatis-spring-boot-starter
91 | 2.1.0
92 |
93 |
94 |
95 | junit
96 | junit
97 | 4.11
98 | test
99 |
100 |
101 |
102 | log4j
103 | log4j
104 | 1.2.17
105 |
106 |
107 |
108 |
109 | org.projectlombok
110 | lombok
111 | 1.16.10
112 |
113 |
114 |
115 | com.google.guava
116 | guava
117 | 30.0-jre
118 |
119 |
120 |
121 |
122 | org.aspectj
123 | aspectjweaver
124 | 1.9.4
125 |
126 |
127 |
128 | com.rabbitmq
129 | amqp-client
130 | 5.5.1
131 |
132 |
133 |
134 | org.mapstruct
135 |
136 | mapstruct-jdk8
137 | 1.2.0.Final
138 |
139 |
140 | org.mapstruct
141 | mapstruct-processor
142 | 1.2.0.Final
143 |
144 |
145 |
146 | org.dspace.xmlui.concurrent
147 | concurrent
148 | 1.3.4
149 |
150 |
151 |
152 |
153 | org.apache.commons
154 | commons-lang3
155 | 3.10
156 |
157 |
158 | org.apache.commons
159 | commons-pool2
160 | 2.6.1
161 |
162 |
163 | org.apache.commons
164 | commons-collections4
165 | 4.4
166 |
167 |
168 | commons-collections
169 | commons-collections
170 | 3.2.2
171 |
172 |
173 | org.apache.commons
174 | commons-jexl3
175 | 3.2.1
176 |
177 |
178 | junit
179 | junit
180 | 4.11
181 | compile
182 |
183 |
184 |
185 |
186 |
187 | demo5
188 |
189 |
190 |
191 | org.apache.maven.plugins
192 | maven-war-plugin
193 | 2.2
194 |
195 | WebContent\WEB-INF\web.xml
196 |
197 |
198 |
199 |
200 | org.apache.maven.plugins
201 | maven-source-plugin
202 | 3.0.1
203 |
204 |
205 | attach-sources
206 | package
207 |
208 | jar-no-fork
209 |
210 |
211 |
212 |
213 |
214 | org.apache.maven.plugins
215 | maven-surefire-plugin
216 |
217 |
218 | true
219 |
220 |
221 |
222 |
223 |
224 |
225 | org.apache.maven.plugins
226 | maven-compiler-plugin
227 |
228 | 8
229 | 8
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | src/main/java
239 |
240 | **/*.properties
241 | **/*.xml
242 |
243 | false
244 |
245 |
246 | src/main/resources
247 |
248 | **/*.*
249 |
250 | false
251 |
252 |
253 |
254 |
255 |
256 |
--------------------------------------------------------------------------------
/spring-life-cycle/src/main/java/com/demo/LouzaiBean.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import lombok.ToString;
4 | import org.springframework.beans.BeansException;
5 | import org.springframework.beans.factory.*;
6 |
7 | @ToString
8 | public class LouzaiBean implements InitializingBean, BeanFactoryAware, BeanNameAware, DisposableBean {
9 |
10 | /**
11 | * 姓名
12 | */
13 | private String name;
14 |
15 | public LouzaiBean() {
16 | System.out.println("1.调用构造方法:我出生了!");
17 | }
18 |
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | public void setName(String name) {
24 | this.name = name;
25 | System.out.println("2.设置属性:我的名字叫"+name);
26 | }
27 |
28 | @Override
29 | public void setBeanName(String s) {
30 | System.out.println("3.调用BeanNameAware#setBeanName方法:我要上学了,起了个学名");
31 | }
32 |
33 | @Override
34 | public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
35 | System.out.println("4.调用BeanFactoryAware#setBeanFactory方法:选好学校了");
36 | }
37 |
38 | @Override
39 | public void afterPropertiesSet() throws Exception {
40 | System.out.println("6.InitializingBean#afterPropertiesSet方法:入学登记");
41 | }
42 |
43 | public void init() {
44 | System.out.println("7.自定义init方法:努力上学ing");
45 | }
46 |
47 | @Override
48 | public void destroy() throws Exception {
49 | System.out.println("9.DisposableBean#destroy方法:平淡的一生落幕了");
50 | }
51 |
52 | public void destroyMethod() {
53 | System.out.println("10.自定义destroy方法:睡了,别想叫醒我");
54 | }
55 |
56 | public void work(){
57 | System.out.println("Bean使用中:工作,只有对社会没有用的人才放假。。");
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/spring-life-cycle/src/main/java/com/demo/MyBeanPostProcessor.java:
--------------------------------------------------------------------------------
1 | package com.demo;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.beans.factory.config.BeanPostProcessor;
5 |
6 | public class MyBeanPostProcessor implements BeanPostProcessor {
7 |
8 | @Override
9 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
10 | System.out.println("5.BeanPostProcessor.postProcessBeforeInitialization方法:到学校报名啦");
11 | return bean;
12 | }
13 |
14 | @Override
15 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
16 | System.out.println("8.BeanPostProcessor#postProcessAfterInitialization方法:终于毕业,拿到毕业证啦!");
17 | return bean;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-life-cycle/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spring-life-cycle/src/test/java/MyTest.java:
--------------------------------------------------------------------------------
1 |
2 | import com.demo.LouzaiBean;
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | public class MyTest {
7 | public static void main(String[] args) throws Exception {
8 | ApplicationContext context =new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
9 | LouzaiBean louzaiBean = (LouzaiBean) context.getBean("louzaiBean");
10 | louzaiBean.work();
11 | ((ClassPathXmlApplicationContext) context).destroy();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-transaction/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/spring-transaction/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/spring-transaction/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/spring-transaction/.idea/inspectionProfiles/Project_Default.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 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/spring-transaction/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-transaction/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/spring-transaction/.idea/uiDesigner.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 | -
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 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/spring-transaction/Spring-事务.iml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/spring-transaction/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | java-study2
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 | UTF-8
14 | 1.8
15 | 1.8
16 |
17 | 5.2.15.RELEASE
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | org.springframework
27 | spring-core
28 |
29 | ${spring.version}
30 |
31 |
32 | org.springframework
33 | spring-beans
34 | ${spring.version}
35 |
36 |
37 | org.springframework
38 | spring-context
39 | ${spring.version}
40 |
41 |
42 |
43 |
44 | org.springframework
45 | spring-jdbc
46 | ${spring.version}
47 |
48 |
49 | org.springframework
50 | spring-tx
51 | ${spring.version}
52 |
53 |
54 |
55 | org.springframework
56 | spring-web
57 | ${spring.version}
58 |
59 |
60 | org.springframework
61 | spring-webmvc
62 | ${spring.version}
63 |
64 |
65 |
66 | org.springframework
67 | spring-test
68 | ${spring.version}
69 |
70 |
71 |
72 |
73 |
74 | org.mybatis
75 | mybatis
76 | 3.4.6
77 |
78 |
79 | org.mybatis
80 | mybatis-spring
81 | 2.0.0
82 |
83 |
84 | mysql
85 | mysql-connector-java
86 | 6.0.6
87 |
88 |
89 | org.mybatis.spring.boot
90 | mybatis-spring-boot-starter
91 | 2.1.0
92 |
93 |
94 |
95 | junit
96 | junit
97 | 4.11
98 | test
99 |
100 |
101 |
102 | log4j
103 | log4j
104 | 1.2.17
105 |
106 |
107 |
108 |
109 | org.projectlombok
110 | lombok
111 | 1.16.10
112 |
113 |
114 |
115 | com.google.guava
116 | guava
117 | 30.0-jre
118 |
119 |
120 |
121 |
122 | org.aspectj
123 | aspectjweaver
124 | 1.9.4
125 |
126 |
127 |
128 | com.rabbitmq
129 | amqp-client
130 | 5.5.1
131 |
132 |
133 |
134 | org.mapstruct
135 |
136 | mapstruct-jdk8
137 | 1.2.0.Final
138 |
139 |
140 | org.mapstruct
141 | mapstruct-processor
142 | 1.2.0.Final
143 |
144 |
145 |
146 | org.dspace.xmlui.concurrent
147 | concurrent
148 | 1.3.4
149 |
150 |
151 |
152 |
153 | org.apache.commons
154 | commons-lang3
155 | 3.10
156 |
157 |
158 | org.apache.commons
159 | commons-pool2
160 | 2.6.1
161 |
162 |
163 | org.apache.commons
164 | commons-collections4
165 | 4.4
166 |
167 |
168 | commons-collections
169 | commons-collections
170 | 3.2.2
171 |
172 |
173 | org.apache.commons
174 | commons-jexl3
175 | 3.2.1
176 |
177 |
178 | junit
179 | junit
180 | 4.11
181 | compile
182 |
183 |
184 |
185 |
186 |
187 | demo5
188 |
189 |
190 |
191 | org.apache.maven.plugins
192 | maven-war-plugin
193 | 2.2
194 |
195 | WebContent\WEB-INF\web.xml
196 |
197 |
198 |
199 |
200 | org.apache.maven.plugins
201 | maven-source-plugin
202 | 3.0.1
203 |
204 |
205 | attach-sources
206 | package
207 |
208 | jar-no-fork
209 |
210 |
211 |
212 |
213 |
214 | org.apache.maven.plugins
215 | maven-surefire-plugin
216 |
217 |
218 | true
219 |
220 |
221 |
222 |
223 |
224 |
225 | org.apache.maven.plugins
226 | maven-compiler-plugin
227 |
228 | 8
229 | 8
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | src/main/java
239 |
240 | **/*.properties
241 | **/*.xml
242 |
243 | false
244 |
245 |
246 | src/main/resources
247 |
248 | **/*.*
249 |
250 | false
251 |
252 |
253 |
254 |
255 |
256 |
--------------------------------------------------------------------------------
/spring-transaction/src/main/java/com/mybatis/config/datasources/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/spring-transaction/src/main/java/com/mybatis/controller/Louzai.java:
--------------------------------------------------------------------------------
1 | package com.mybatis.controller;
2 |
3 | import com.mybatis.dao.UserDao;
4 | import com.mybatis.entity.MyUser;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 | import org.springframework.transaction.annotation.Transactional;
8 |
9 | @Service
10 | public class Louzai {
11 | @Autowired
12 | private UserDao userDao;
13 |
14 | public void update(Integer id) {
15 | MyUser user = new MyUser();
16 | user.setUid(id);
17 | user.setUname("张三-testing");
18 | user.setUsex("女");
19 | userDao.updateUser(user);
20 | }
21 |
22 | public MyUser query(Integer id) {
23 | MyUser user = userDao.selectUserById(id);
24 | return user;
25 | }
26 |
27 | // 正常情况
28 | @Transactional(rollbackFor = Exception.class)
29 | public void testSuccess() throws Exception {
30 | Integer id = 1;
31 | MyUser user = query(id);
32 | System.out.println("原记录:" + user);
33 | update(id);
34 | throw new Exception("事务生效");
35 | }
36 | }
--------------------------------------------------------------------------------
/spring-transaction/src/main/java/com/mybatis/dao/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.mybatis.dao;
2 |
3 | import com.mybatis.entity.MyUser;
4 | import org.apache.ibatis.annotations.Mapper;
5 | import org.springframework.stereotype.Repository;
6 |
7 | import java.util.List;
8 |
9 | @Repository("userDao")
10 | @Mapper
11 | /*
12 | * 使用Spring自动扫描MyBatis的接口并装配 (Spring将指定包中所有被@Mapper注解标注的接口自动装配为MyBatis的映射接口
13 | */
14 | public interface UserDao {
15 | /**
16 | * 接口方法对应的SQL映射文件中的id
17 | */
18 | public MyUser selectUserById(Integer uid);
19 | public List selectAllUser();
20 | public int addUser(MyUser user);
21 | public int updateUser(MyUser user);
22 | public int deleteUser(Integer uid);
23 | }
24 |
--------------------------------------------------------------------------------
/spring-transaction/src/main/java/com/mybatis/entity/MyUser.java:
--------------------------------------------------------------------------------
1 | package com.mybatis.entity;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * springtest数据库中user表的持久类
7 | */
8 | @Data
9 | public class MyUser {
10 | private Integer uid; // 主键
11 | private String uname;
12 | private String usex;
13 | }
14 |
--------------------------------------------------------------------------------
/spring-transaction/src/main/java/com/mybatis/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
10 |
11 |
12 | update user_test set uname =#{uname},usex = #{usex} where uid = #{uid}
13 |
14 |
--------------------------------------------------------------------------------
/spring-transaction/src/main/java/com/mybatis/test/SpringMyBatisTest.java:
--------------------------------------------------------------------------------
1 | package com.mybatis.test;
2 |
3 | import com.mybatis.controller.Louzai;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.support.ClassPathXmlApplicationContext;
6 |
7 | // 用于测试MyBatis和Spring的集成
8 | public class SpringMyBatisTest {
9 | public static void main(String[] args) throws Exception {
10 | String xmlPath = "applicationContext.xml";
11 | ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
12 | Louzai uc = (Louzai) applicationContext.getBean("louzai");
13 | uc.testSuccess();
14 | }
15 | }
--------------------------------------------------------------------------------
/spring-transaction/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | classpath:jdbc.properties
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 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/spring-transaction/src/main/resources/jdbc.properties:
--------------------------------------------------------------------------------
1 | jdbc.shop.url=jdbc:mysql://127.0.0.1:3306/java_study?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
2 | jdbc.shop.username=root
3 | jdbc.shop.password=
--------------------------------------------------------------------------------
/spring-transaction/src/test/java/MyTest.java:
--------------------------------------------------------------------------------
1 |
2 | import com.mybatis.controller.Louzai;
3 | import org.springframework.context.ApplicationContext;
4 | import org.springframework.context.support.ClassPathXmlApplicationContext;
5 |
6 | public class MyTest {
7 | public static void main(String[] args) throws Exception {
8 | String xmlPath = "applicationContext.xml";
9 | ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
10 | Louzai uc = (Louzai) applicationContext.getBean("userController");
11 | uc.testSuccess();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------