1
- package com .isea533 .mybatis ;
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2014 [email protected]
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 .isea533 .mybatis .mapperhelper ;
2
26
3
- import com .isea533 .mybatis .mapperhelper .MapperHelper ;
4
27
import org .apache .ibatis .builder .annotation .ProviderSqlSource ;
5
28
import org .apache .ibatis .mapping .MappedStatement ;
6
29
import org .mybatis .spring .SqlSessionTemplate ;
11
34
import java .util .Properties ;
12
35
13
36
/**
37
+ * 通用Mapper和Spring集成
38
+ *
14
39
* @author liuzh
15
40
*/
16
- public class MappperBeanPostProcessor implements BeanPostProcessor {
41
+ public class MapperSpring implements BeanPostProcessor {
17
42
18
43
private final MapperHelper mapperHelper = new MapperHelper ();
19
44
20
- private boolean runed = false ;
21
-
22
45
public void setProperties (Properties properties ) {
23
46
String UUID = properties .getProperty ("UUID" );
24
47
if (UUID != null && UUID .length () > 0 ) {
@@ -64,7 +87,8 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
64
87
65
88
@ Override
66
89
public Object postProcessAfterInitialization (Object bean , String beanName ) throws BeansException {
67
- if (!runed && bean instanceof SqlSessionTemplate ) {
90
+ //对所有的SqlSessionTemplate进行处理,多数据源情况下仍然有效
91
+ if (bean instanceof SqlSessionTemplate ) {
68
92
SqlSessionTemplate sqlSessionTemplate = (SqlSessionTemplate )bean ;
69
93
Collection <MappedStatement > collection = sqlSessionTemplate .getConfiguration ().getMappedStatements ();
70
94
for (Object object : collection ) {
@@ -77,7 +101,6 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
77
101
}
78
102
}
79
103
}
80
- runed = true ;
81
104
}
82
105
return bean ;
83
106
}
0 commit comments