Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf2e752

Browse files
committed
更新配置。
1 parent 959b6ea commit cf2e752

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/main/java/com/isea533/mybatis/MappperBeanPostProcessor.java renamed to src/main/java/com/isea533/mybatis/mapperhelper/MapperSpring.java

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
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;
226

3-
import com.isea533.mybatis.mapperhelper.MapperHelper;
427
import org.apache.ibatis.builder.annotation.ProviderSqlSource;
528
import org.apache.ibatis.mapping.MappedStatement;
629
import org.mybatis.spring.SqlSessionTemplate;
@@ -11,14 +34,14 @@
1134
import java.util.Properties;
1235

1336
/**
37+
* 通用Mapper和Spring集成
38+
*
1439
* @author liuzh
1540
*/
16-
public class MappperBeanPostProcessor implements BeanPostProcessor {
41+
public class MapperSpring implements BeanPostProcessor {
1742

1843
private final MapperHelper mapperHelper = new MapperHelper();
1944

20-
private boolean runed = false;
21-
2245
public void setProperties(Properties properties) {
2346
String UUID = properties.getProperty("UUID");
2447
if (UUID != null && UUID.length() > 0) {
@@ -64,7 +87,8 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
6487

6588
@Override
6689
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
67-
if (!runed && bean instanceof SqlSessionTemplate) {
90+
//对所有的SqlSessionTemplate进行处理,多数据源情况下仍然有效
91+
if (bean instanceof SqlSessionTemplate) {
6892
SqlSessionTemplate sqlSessionTemplate = (SqlSessionTemplate)bean;
6993
Collection<MappedStatement> collection = sqlSessionTemplate.getConfiguration().getMappedStatements();
7094
for (Object object : collection) {
@@ -77,7 +101,6 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
77101
}
78102
}
79103
}
80-
runed = true;
81104
}
82105
return bean;
83106
}

src/main/resources/applicationContext.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<property name="dataSource" ref="dataSource"/>
7575
</bean>
7676

77-
<bean id="mapperHelper" class="com.isea533.mybatis.MappperBeanPostProcessor">
77+
<bean class="com.isea533.mybatis.mapperhelper.MapperSpring">
7878
<property name="properties">
7979
<value>
8080
mappers=com.isea533.mybatis.mapperhelper.Mapper

0 commit comments

Comments
 (0)